From 38bcf9412304a5c7b99ab64da0e285a45a04e0b0 Mon Sep 17 00:00:00 2001 From: Jeena Date: Wed, 8 Sep 2021 12:08:48 +0900 Subject: [PATCH] Add Darktable to export files --- darktable.py | 26 ++++++++++++++++++++++++++ synology.py | 12 +++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 darktable.py diff --git a/darktable.py b/darktable.py new file mode 100755 index 0000000..a3e06b7 --- /dev/null +++ b/darktable.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 + +from os import access, R_OK +from os.path import isfile +from helper import escape_file_path as ef +import sys, os + +class Darktable: + def __init__(self, path): + self.original_path = path + + def export(self): + escaped_file_path = self.original_path + filename, file_extension = os.path.splitext(self.original_path) + new_path = filename + ".jpeg" + cmd = "darktable-cli " + ef(self.original_path) + " " + ef(new_path) + os.system(cmd) + return new_path + +if __name__ == "__main__": + if len(sys.argv) != 2: + print("Usage: darktable.py path/to/picture.NEF") + else: + img_path = sys.argv[1] + d = Darktable(img_path) + print(d.export()) diff --git a/synology.py b/synology.py index 3d47d51..eb31a85 100755 --- a/synology.py +++ b/synology.py @@ -5,6 +5,7 @@ import tempfile import shutil import os import helper +import darktable def connect_db(db_host, db_user, db_passwd): return psycopg2.connect( @@ -41,7 +42,16 @@ def fetch_files(remotehost, lib_path, pictures): localfile = '/'.join([dirpath, picture[1]]) escaped_remotefile = helper.escape_file_path(remotefile) cmd = 'scp "' + remotehost + ':' + escaped_remotefile + '" "' + localfile + '"' - os.system(cmd) + if os.system(cmd): + # Get .xmp file if available + cmd = 'scp "' + remotehost + ':' + escaped_remotefile + '.xmp" "' + localfile + '.xmp"' + if os.system(cmd): + # Use darktable + d = Darktable(localfile) + d.export() + os.remove(localfile) + os.remove(localfile + ".xmp") + return dirpath