-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathLocalThread.py
More file actions
64 lines (57 loc) · 2.13 KB
/
LocalThread.py
File metadata and controls
64 lines (57 loc) · 2.13 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from os import listdir,mkdir,remove,path
from shutil import move
from threading import Thread
from json import load
from time import sleep
from glob import glob
class LocalThread(Thread):
def __init__(self, subdir, fileExt, signal, basePath):
Thread.__init__(self)
self.subdir=subdir
self.fileExt=fileExt
self.Loop=True
self.message=signal
self.fileIndex=0
self.fullpath="{}/{}".format(basePath, subdir)
print("fullpath={}".format(self.fullpath))
try:
mkdir(self.fullpath)
except:
pass
def forceStartPoint(self, start):
self.fileIndex=start
def getStartPoint(self):
if self.fileExt[0] == '.':
search="{}/*{}".format(self.fullpath, self.fileExt)
else:
search="{}/*.{}".format(self.fullpath, self.fileExt)
files=glob(search)
if len(files) == 0:
print("No previous file found, starting with index at 0")
self.fileIndex=0
return 0
files.sort()
lastFile=files[len(files)-1]
print("last file={}".format(lastFile))
base=path.basename(lastFile)
self.message.emit("last file in {}={}".format(self.subdir,lastFile))
self.fileIndex=1+int(base.split(".")[0],10)
self.message.emit("File index now at: {}".format(self.fileIndex))
return self.fileIndex
def run(self):
self.Loop=True
try:
mkdir("/dev/shm/complete")
except Exception as e:
msg=str(e)
if msg != "[Errno 17] File exists: '/dev/shm/complete'":
self.message.emit(str(e))
while self.Loop:
sleep(1)
for item in listdir("/dev/shm/complete/"):
if path.isfile("/dev/shm/complete/{}".format(item)):
destination="{}/{}".format(self.fullpath, item)
self.message.emit(f"xfer,{destination}")
move("/dev/shm/complete/{}".format(item),destination)
def stopLoop(self):
self.Loop=False