1
0

Copy-to for to-photoblog

This commit is contained in:
Noah 2023-09-17 12:47:53 -07:00
parent bd6651c8bd
commit 1b84701f48
2 changed files with 25 additions and 1 deletions

View File

@ -212,3 +212,4 @@ fi
###
. ~/.common.sh
. "$HOME/.cargo/env"

View File

@ -25,7 +25,7 @@ def main(args):
m = RE_FILENAME.match(name)
if not m:
print(f"File '{name}' doesn't match usual naming convention. Use --custom to upload custom file names.")
quit()
continue
file_map[name] = f"{m.group(1)}.{m.group(2)}"
@ -52,6 +52,23 @@ def main(args):
print(f"New files not found on the blog: {not_existing}")
# Doing a copy-to?
if args.copy_to:
if os.path.isfile(args.copy_to) and not os.path.isdir(args.copy_to):
print(f"Error: {args.copy_to} already exists and is not a folder")
quit()
if not os.path.isdir(args.copy_to):
os.makedirs(args.copy_to)
for ours, theirs in file_map.items():
if not theirs in not_existing:
continue
cmd = ["cp", ours, f"{args.copy_to}/{theirs}"]
print("Exec:", " ".join(cmd))
subprocess.run(cmd)
quit()
if problems:
quit()
@ -60,6 +77,8 @@ def main(args):
print("NOTE: Test run (--test), not actually uploading")
for ours, theirs in file_map.items():
if not theirs in not_existing:
continue
cmd = ["scp", ours, f"{USERNAME}@{HOSTNAME}:www/static/photos/{theirs}"]
print("Exec:", " ".join(cmd))
if not args.test:
@ -80,6 +99,10 @@ if __name__ == "__main__":
action="store_true",
help="Test run; do not actually upload files",
)
parser.add_argument("--copy-to", "-cp",
type=str,
help="Instead of scp upload, copy the files to another folder on disk",
)
parser.add_argument("files",
type=str,
nargs='+',