Reformatted DataPuller.py

This commit is contained in:
R Dittberner 2026-03-04 12:13:17 +01:00
parent 5fc7602ea7
commit 348f71ba69

View file

@ -7,14 +7,15 @@ import filecmp
# Argument Parsing # Argument Parsing
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
prog='DataPuller', prog="DataPuller",
description='Check differences between folders and update files if needed') description="Check differences between folders and update files if needed",
)
parser.add_argument('-i', '--input') parser.add_argument("-i", "--input")
parser.add_argument('-o', '--output') parser.add_argument("-o", "--output")
parser.add_argument('-q', '--quiet', action='store_true') parser.add_argument("-q", "--quiet", action="store_true")
parser.add_argument('-y', '--confirm', action="store_true") parser.add_argument("-y", "--confirm", action="store_true")
parser.add_argument('-d', '--delete', action="store_true") parser.add_argument("-d", "--delete", action="store_true")
parser.add_argument("--dryrun", action="store_true") parser.add_argument("--dryrun", action="store_true")
args = parser.parse_args() args = parser.parse_args()
@ -29,6 +30,7 @@ if not args.output:
else: else:
outpath = args.output outpath = args.output
def get_files(path): def get_files(path):
file_info = {} file_info = {}
if not os.path.exists(path): if not os.path.exists(path):
@ -48,10 +50,13 @@ def get_files(path):
pass pass
return file_info return file_info
def main(): def main():
startstring = " FOLDER-SYNC 1.0 " startstring = " FOLDER-SYNC 1.0 "
if not args.quiet: if not args.quiet:
print(len(startstring)*"=" + "\n" + startstring + "\n" + len(startstring)*"=") print(
len(startstring) * "=" + "\n" + startstring + "\n" + len(startstring) * "="
)
# Test Folder availability # Test Folder availability
if not os.path.exists((inpath)): if not os.path.exists((inpath)):
@ -116,7 +121,9 @@ def main():
if args.confirm: if args.confirm:
copy_confirm = "y" copy_confirm = "y"
else: else:
copy_confirm = input("Write new and changed files? (y/N): ").strip().lower() copy_confirm = (
input("Write new and changed files? (y/N): ").strip().lower()
)
if copy_confirm in ["ja", "j", "yes", "y"]: if copy_confirm in ["ja", "j", "yes", "y"]:
if not args.quiet: if not args.quiet:
print("\nCopying files...") print("\nCopying files...")
@ -135,7 +142,12 @@ def main():
except Exception as error: except Exception as error:
print(f"Failed to copy {path} with error {error}") print(f"Failed to copy {path} with error {error}")
if not args.confirm: if not args.confirm:
if not input("Continue? (y/N): ") in ["ja", "j", "yes", "y"]: if not input("Continue? (y/N): ") in [
"ja",
"j",
"yes",
"y",
]:
exit(1) exit(1)
elif not args.quiet: elif not args.quiet:
print("\nSkipping changes...") print("\nSkipping changes...")
@ -149,7 +161,9 @@ def main():
if args.delete: if args.delete:
delete_confirm = "y" delete_confirm = "y"
else: else:
delete_confirm = input("Delete files on the target? (y/N): ").strip().lower() delete_confirm = (
input("Delete files on the target? (y/N): ").strip().lower()
)
if delete_confirm in ["ja", "j", "yes", "y"]: if delete_confirm in ["ja", "j", "yes", "y"]:
if not args.quiet: if not args.quiet:
print("\nDeleting files...") print("\nDeleting files...")
@ -162,7 +176,12 @@ def main():
except Exception as error: except Exception as error:
print(f"Failed to delete {path} with error {error}") print(f"Failed to delete {path} with error {error}")
if not args.confirm: if not args.confirm:
if not input("Continue? (y/N): ") in ["ja", "j", "yes", "y"]: if not input("Continue? (y/N): ") in [
"ja",
"j",
"yes",
"y",
]:
exit(1) exit(1)
elif not args.quiet: elif not args.quiet:
print("\nSkipping deletion...") print("\nSkipping deletion...")
@ -172,6 +191,5 @@ def main():
input("\nPress ENTER to exit...") input("\nPress ENTER to exit...")
if __name__ == "__main__": if __name__ == "__main__":
main() main()