Implement moving to completed directory
This commit is contained in:
parent
82737215fe
commit
f1094bdbda
4 changed files with 35 additions and 0 deletions
|
@ -180,6 +180,12 @@ class Database:
|
|||
|
||||
return [f[0] for f in cur.fetchall()]
|
||||
|
||||
def getCompletionByFileUUID(self, fileuuid: str) -> List[Optional[str]]:
|
||||
cur = self.getCursor()
|
||||
cur.execute("SELECT vessel FROM contentmonster_file_log WHERE file = ?", (fileuuid))
|
||||
|
||||
return [v[0] for v in cur.fetchall()]
|
||||
|
||||
def migrate(self) -> None:
|
||||
"""Apply database migrations
|
||||
"""
|
||||
|
|
|
@ -46,10 +46,23 @@ class Directory:
|
|||
|
||||
if os.path.isdir(location):
|
||||
self.location = pathlib.Path(location)
|
||||
self.assertCompletedDirectory()
|
||||
else:
|
||||
location = str(location)
|
||||
raise ValueError(
|
||||
f"Location {location} for Directory {name} does not exist or is not a directory.")
|
||||
|
||||
@property
|
||||
def completeddir(self):
|
||||
return self.location / "completed"
|
||||
|
||||
def assertCompletedDirectory(self):
|
||||
if not os.path.isdir(self.completeddir):
|
||||
if os.path.isfile(self.completeddir):
|
||||
raise FileExistsError("Cannot create directory %s - path exists but is not a directory!" % str(self.completeddir))
|
||||
|
||||
os.path.mkdir(self.completeddir)
|
||||
|
||||
def getFiles(self) -> list[File]:
|
||||
"""Get all Files in Directory
|
||||
|
||||
|
|
|
@ -40,6 +40,9 @@ class File:
|
|||
"""
|
||||
return os.path.isfile(self.directory.location / self.name)
|
||||
|
||||
def moveCompleted(self) -> None:
|
||||
self.getFullPath.rename(self.directory.completeddir / self.name)
|
||||
|
||||
def getUUID(self) -> str:
|
||||
"""Return unique identifier for this File object
|
||||
|
||||
|
|
|
@ -117,6 +117,8 @@ class VesselThread(Process):
|
|||
self.vessel._uploaded.append(fileobj.uuid)
|
||||
self._logger.debug(
|
||||
f"Moved {fileobj.name} to its final destination on {self.vessel.name} - done!")
|
||||
|
||||
self.checkFileCompletion(fileobj)
|
||||
return
|
||||
|
||||
nextchunk = 0 if status == STATUS_START else status + 1
|
||||
|
@ -139,6 +141,17 @@ class VesselThread(Process):
|
|||
f"No more data to upload to vessel {self.vessel.name} for file {fileobj.name} - compiling")
|
||||
self.vessel.compileComplete(remotefile)
|
||||
|
||||
def checkFileCompletion(self, fileobj: File) -> None:
|
||||
db = Database()
|
||||
complete = db.getCompletionByFileUUID()
|
||||
del(db)
|
||||
|
||||
for vessel in [v.name for v in self._state["config"].vessels]:
|
||||
if vessel not in complete:
|
||||
return
|
||||
|
||||
fileobj.moveCompleted()
|
||||
|
||||
def processQueue(self) -> Optional[str]:
|
||||
"""Return a file from the processing queue
|
||||
"""
|
||||
|
|
Loading…
Reference in a new issue