diff --git a/classes/config.py b/classes/config.py index a4eaf83..7c441c7 100644 --- a/classes/config.py +++ b/classes/config.py @@ -15,10 +15,10 @@ class Config: @property def directories(self): - for section in self._parser.sections: + for section in self._parser.sections(): if section.startswith("Directory "): - yield Directory.from_config(section) + yield Directory.from_config(self._parser[section]) @property def server(self): - return Server(self._parser["Server"]) + return Server.from_config(self._parser["Server"]) diff --git a/daemon.py b/daemon.py index 035b570..b1e14ad 100644 --- a/daemon.py +++ b/daemon.py @@ -35,13 +35,14 @@ if __name__ == "__main__": try: with config.server.get_sftp_client() as sftp: 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 - encrypted: bytes = sftp.open(response).read() - decrypted = GPG().decrypt(encrypted) + encrypted: bytes = sftp.open(rpath).read() + decrypted = GPG().decrypt(encrypted).data.decode() - dirname = Path(outpath).name.split("_")[0] + dirname = response.split("_")[0] founddir = None @@ -53,16 +54,21 @@ if __name__ == "__main__": if not founddir: 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: - (Path(founddir.destinationbackup) / outfile.name).write_text(decrypted) + (Path(founddir.destinationbackup) / outfile).write_text(decrypted) - sftp.remove(response) + sftp.remove(rpath) - except: - print(f"Something went wrong downloading files from the server.") \ No newline at end of file + except Exception as e: + print(f"Something went wrong downloading files from the server: {e}") \ No newline at end of file