-
Notifications
You must be signed in to change notification settings - Fork 11
/
watcher.py
45 lines (36 loc) · 1.09 KB
/
watcher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python3
import glob, os, shutil, time
print('File watcher started')
while True:
i = 0
while True:
i = i + 1
shareEnable = os.getenv('PROXY{}_ENABLE'.format(i))
if shareEnable == None:
break
elif not shareEnable == "1":
continue
shareDirectory = '/share{}'.format(i)
remoteMount = '/remote{}'.format(i)
files = glob.glob(shareDirectory + '/*.pdf')
for file in files:
currentTime = time.time()
modifiedTime = os.path.getmtime(file)
fileAge = currentTime - modifiedTime
if fileAge < 15:
continue
_, filename = os.path.split(file)
name, ext = os.path.splitext(filename)
i = 0
while True:
i = i + 1
remotePath = remoteMount + "/" + name + '{:04d}'.format(i) + ext
if not os.path.exists(remotePath):
break
try:
print("Move Scan: '" + file + "' -> '" + remotePath + "'")
shutil.copyfile(file, remotePath)
os.remove(file)
except (FileNotFoundError, OSError) as err:
print("↳ " + str(err))
time.sleep(5)