Trash rejected and secondary file permanentely
This commit is contained in:
parent
e26a859659
commit
b71fc60548
55
remove_permanently.py
Normal file
55
remove_permanently.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
from pytable.models import Image, ImageFlags, FilmRoll
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("--execute", action='store_true')
|
||||||
|
|
||||||
|
options = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
n_rejected = 0
|
||||||
|
n_less_than_three = 0
|
||||||
|
n_total = 0
|
||||||
|
n_total_leaders = 0
|
||||||
|
n_less_than_three_leaders = 0
|
||||||
|
n_rejected_leaders = 0
|
||||||
|
|
||||||
|
def is_leader(image):
|
||||||
|
return not image.group_id or image.group_id == image.id
|
||||||
|
|
||||||
|
def should_remove(image):
|
||||||
|
is_rejected = image.flag(ImageFlags.REJECTED)
|
||||||
|
return is_rejected or (image.stars < 3 and not is_leader(image))
|
||||||
|
|
||||||
|
query: list[Image] = Image.filter().prefetch(FilmRoll)
|
||||||
|
images = query
|
||||||
|
images_to_remove = filter(should_remove, images)
|
||||||
|
|
||||||
|
d_root = "/home/oke/Pictures/Darktable"
|
||||||
|
d_local = "/home/oke/Pictures/DarktableLocal"
|
||||||
|
d_remote = "/home/oke/Pictures/DarktableRemote"
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
ids_to_remove = []
|
||||||
|
|
||||||
|
for i in images_to_remove:
|
||||||
|
fn = os.path.join(i.film.folder, i.filename)
|
||||||
|
assert fn.startswith(d_root)
|
||||||
|
print(fn.replace(d_root + '/', ''))
|
||||||
|
|
||||||
|
remote_file = fn.replace(d_root, d_remote)
|
||||||
|
local_file = fn.replace(d_root, d_local)
|
||||||
|
ids_to_remove.append(i.id)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if ids_to_remove and options.execute:
|
||||||
|
print(len(ids_to_remove))
|
||||||
|
query = Image.delete().where(Image.id.in_(ids_to_remove))
|
||||||
|
query.execute()
|
14
trash.sh
Normal file
14
trash.sh
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
PW="eko,1994"
|
||||||
|
echo "Trashing local files"
|
||||||
|
python trash_to.py "${@:1}" ~/Pictures/DarktableLocal ~/trash files.txt
|
||||||
|
echo "Copy script and filelist"
|
||||||
|
sshpass -p $PW scp -P2200 \
|
||||||
|
trash_to.py files.txt har0ke@192.168.20.2:/homes/har0ke/
|
||||||
|
echo "Trash remote files"
|
||||||
|
echo "$PW" | sshpass -p $PW ssh -t har0ke@192.168.20.2 -p2200 \
|
||||||
|
sudo -S python \
|
||||||
|
trash_to.py "${@:1}" \
|
||||||
|
/volume1/homes/oke/lenovo-darktable/home/oke/Pictures/DarktableLocal \
|
||||||
|
/volume1/homes/oke/trash \
|
||||||
|
files.txt
|
74
trash_to.py
Normal file
74
trash_to.py
Normal file
@ -0,0 +1,74 @@
|
|||||||
|
|
||||||
|
import os
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("-u", action='store_true')
|
||||||
|
parser.add_argument("-a", action='store_true')
|
||||||
|
parser.add_argument("-n", "--dry-run", action='store_true')
|
||||||
|
parser.add_argument("base")
|
||||||
|
parser.add_argument("trash")
|
||||||
|
parser.add_argument("file_list")
|
||||||
|
|
||||||
|
options = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def me_and_extras(fn):
|
||||||
|
directory, filename = os.path.split(fn)
|
||||||
|
basename, ext = os.path.splitext(filename)
|
||||||
|
yield fn
|
||||||
|
iphone_movie = os.path.join(directory, "." + basename + ".mov")
|
||||||
|
yield iphone_movie
|
||||||
|
yield fn + ".xmp"
|
||||||
|
for i in range(1, 10):
|
||||||
|
xmp = os.path.join(directory, f"{basename}_{i:02d}.{ext}.xmp")
|
||||||
|
if os.path.exists(xmp):
|
||||||
|
yield xmp
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
base = os.path.abspath(options.base)
|
||||||
|
trash = os.path.abspath(options.trash)
|
||||||
|
if options.u:
|
||||||
|
if options.a:
|
||||||
|
print("Restoring all!")
|
||||||
|
for path, dirs, files in os.walk(trash):
|
||||||
|
for file in files:
|
||||||
|
src = os.path.join(path, file)
|
||||||
|
dst = os.path.join(base, os.path.relpath(src, trash))
|
||||||
|
|
||||||
|
print("Moving:")
|
||||||
|
print(src)
|
||||||
|
print(dst)
|
||||||
|
if not options.dry_run:
|
||||||
|
os.rename(src, dst)
|
||||||
|
else:
|
||||||
|
print("Restoring list!")
|
||||||
|
with open(options.file_list, 'r') as f:
|
||||||
|
for base_fn in f.readlines():
|
||||||
|
full_fn = os.path.join(trash, base_fn.strip())
|
||||||
|
for src in me_and_extras(full_fn):
|
||||||
|
dst = os.path.join(base, os.path.relpath(src, trash))
|
||||||
|
if os.path.exists(src):
|
||||||
|
print("Moving:")
|
||||||
|
print(src)
|
||||||
|
print(dst)
|
||||||
|
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
||||||
|
if not options.dry_run:
|
||||||
|
os.rename(src, dst)
|
||||||
|
else:
|
||||||
|
print("Does not exit:", src)
|
||||||
|
else:
|
||||||
|
print("Trashing list!")
|
||||||
|
with open(options.file_list, 'r') as f:
|
||||||
|
for base_fn in f.readlines():
|
||||||
|
full_fn = os.path.join(base, base_fn.strip())
|
||||||
|
for src in me_and_extras(full_fn):
|
||||||
|
dst = os.path.join(trash, os.path.relpath(src, base))
|
||||||
|
if os.path.exists(src):
|
||||||
|
print("Moving:")
|
||||||
|
print(src)
|
||||||
|
print(dst)
|
||||||
|
os.makedirs(os.path.dirname(dst), exist_ok=True)
|
||||||
|
if not options.dry_run:
|
||||||
|
os.rename(src, dst)
|
Loading…
x
Reference in New Issue
Block a user