Get it to actually work
This commit is contained in:
parent
5a1f8533b0
commit
ef1537fcf2
2 changed files with 20 additions and 14 deletions
|
@ -15,10 +15,10 @@ class Config:
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def directories(self):
|
def directories(self):
|
||||||
for section in self._parser.sections:
|
for section in self._parser.sections():
|
||||||
if section.startswith("Directory "):
|
if section.startswith("Directory "):
|
||||||
yield Directory.from_config(section)
|
yield Directory.from_config(self._parser[section])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def server(self):
|
def server(self):
|
||||||
return Server(self._parser["Server"])
|
return Server.from_config(self._parser["Server"])
|
||||||
|
|
28
daemon.py
28
daemon.py
|
@ -35,13 +35,14 @@ if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
with config.server.get_sftp_client() as sftp:
|
with config.server.get_sftp_client() as sftp:
|
||||||
for response in sftp.listdir(config.server.outpath):
|
for response in sftp.listdir(config.server.outpath):
|
||||||
if (time.time() - sftp.stat(response).st_mtime < 60):
|
rpath = str(Path(config.server.outpath) / response)
|
||||||
|
if (time.time() - sftp.stat(rpath).st_mtime < 60):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
encrypted: bytes = sftp.open(response).read()
|
encrypted: bytes = sftp.open(rpath).read()
|
||||||
decrypted = GPG().decrypt(encrypted)
|
decrypted = GPG().decrypt(encrypted).data.decode()
|
||||||
|
|
||||||
dirname = Path(outpath).name.split("_")[0]
|
dirname = response.split("_")[0]
|
||||||
|
|
||||||
founddir = None
|
founddir = None
|
||||||
|
|
||||||
|
@ -53,16 +54,21 @@ if __name__ == "__main__":
|
||||||
if not founddir:
|
if not founddir:
|
||||||
founddir = directory
|
founddir = directory
|
||||||
|
|
||||||
outfile = Path("_".join(Path(outpath).name.split("_")[1:]))
|
if founddir.name == dirname:
|
||||||
|
outfile = response.split("_")[1:]
|
||||||
|
else:
|
||||||
|
outfile = response
|
||||||
|
|
||||||
assert not outfile.exists()
|
outpath = Path(directory.destination) / outfile
|
||||||
|
|
||||||
outfile.write_text(decrypted)
|
assert not outpath.exists()
|
||||||
|
|
||||||
|
outpath.write_text(decrypted)
|
||||||
|
|
||||||
if founddir.destinationbackup:
|
if founddir.destinationbackup:
|
||||||
(Path(founddir.destinationbackup) / outfile.name).write_text(decrypted)
|
(Path(founddir.destinationbackup) / outfile).write_text(decrypted)
|
||||||
|
|
||||||
sftp.remove(response)
|
sftp.remove(rpath)
|
||||||
|
|
||||||
except:
|
except Exception as e:
|
||||||
print(f"Something went wrong downloading files from the server.")
|
print(f"Something went wrong downloading files from the server: {e}")
|
Loading…
Reference in a new issue