add scripts
Signed-off-by: Martin Matous <m@matous.dev>
This commit is contained in:
parent
c6c66648ea
commit
5a4419bb4e
12 changed files with 802 additions and 1 deletions
38
jxl-restore.py
Executable file
38
jxl-restore.py
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from typing import Final
|
||||
|
||||
source: Final = Path(sys.argv[1])
|
||||
dest: Final = Path(sys.argv[2])
|
||||
|
||||
def find_source_jpg(dest_name: Path) -> Path:
|
||||
ext_list = ['.jpg', '.jpeg', '.JPG', '.JPEG']
|
||||
for ext in ext_list:
|
||||
res = (Path(source) / relative_path / (dest_name + ext))
|
||||
if os.path.exists(dest_file_path):
|
||||
return res
|
||||
raise RuntimeError('No original found', dest_name)
|
||||
|
||||
for dest_root, dirs, files in os.walk(dest):
|
||||
for name in files:
|
||||
dest_name, dest_ext = os.path.splitext(name)
|
||||
if dest_ext.lower() != '.jxl':
|
||||
continue
|
||||
dest_file_path = (Path(dest_root) / (dest_name + '.jpg'))
|
||||
print('scanning for ', dest_file_path, '\n')
|
||||
if os.path.exists(dest_file_path): # both .jxl and jpg exist
|
||||
print(dest_file_path, ' already exists\n')
|
||||
continue
|
||||
relative_path = os.path.relpath(dest_root, dest)
|
||||
print('relapath ', relative_path, '\n')
|
||||
src_file_path = find_source_jpg(dest_name)
|
||||
shutil.copy2(src_file_path, dest_file_path)
|
||||
print('restored ', dest_file_path, ' from ', src_file_path, '\n')
|
||||
#dest_jxl = (Path(dest_root) / (dest_name + '.jxl'))
|
||||
#os.remove(dest_jxl)
|
||||
#print('deleted ', dest_jxl, '\n')
|
||||
Loading…
Add table
Add a link
Reference in a new issue