Created
November 1, 2017 13:51
-
-
Save iamn3/36979c4b6302c4a0e1c0f3d73deede8e to your computer and use it in GitHub Desktop.
developing raw data RW2 format.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#codeing:utf-8 | |
# | |
# Useage: | |
# $ mkdir -p /path/to/workspace | |
# $ mkdir -p /path/to/workspace/negative_film | |
# $ mkdir -p /path/to/workspace/jpeg | |
# $ cp *.RW2 /path/to/workspace/negative_filem/ | |
# $ ./developing_machine.py /path/to/workspace | |
# | |
# use python3 | |
import os,subprocess,sys | |
# 指定されたフォルダを対象に出力先のワークフォルダを作成する | |
# (RAWを入れるフォルダ, 現像後のJPEGを入れるフォルダ) を返す | |
def make_work_dirs(work_dir): | |
film_dir = os.path.join(work_dir, "negative_film") | |
out_dir = os.path.join(work_dir, "jpeg") | |
if not os.path.exists(film_dir): | |
os.makedirs(film_dir, exist_ok=True) | |
if not os.path.exists(out_dir): | |
os.makedirs(out_dir, exist_ok=True) | |
return film_dir, out_dir | |
# raw_fileを現像し、out_file_nameとして保存する | |
def developing(raw_file, out_file_name): | |
subprocess.run(["ufraw-batch", | |
"--wb=auto", | |
"--exposure=auto", | |
"--out-type=jpeg", | |
"--output=%s" % out_file_name, | |
raw_file | |
]) | |
if __name__ == "__main__": | |
lock_file = ".developing_machine.lock" | |
if len(sys.argv) == 2: | |
work_dir = sys.argv[1] | |
else: | |
exit() | |
# ロックファイルを作成して、プロセスが実行中か判断する | |
# 実行中であれば、処理を抜ける | |
# 未実行であれば、ロックファイルを作成して処理を続行する | |
if os.path.exists(os.path.join(work_dir, lock_file)): | |
exit() | |
else: | |
with open(os.path.join(work_dir, lock_file), "w") as lock_fp: | |
lock_fp.write("") | |
film_dir, out_dir = make_work_dirs( work_dir ) | |
raw_files = [ os.path.join( film_dir, f ) for f in os.listdir( film_dir ) ] | |
developed_files = [ os.path.join( out_dir, f ) for f in os.listdir( out_dir ) ] | |
developed_file_roots = [ os.path.splitext( os.path.split( f )[1] )[0] for f in developed_files ] | |
# row_filesを一つずつ現像していく | |
for raw_file in raw_files: | |
root = os.path.splitext( os.path.split( raw_file )[1])[0] | |
if not root in developed_file_roots: | |
out_file = os.path.join( out_dir, root ) + ".jpeg" | |
developing( raw_file, out_file ) | |
# 処理が終了したら、ロックファイルを削除 | |
if os.path.exists(os.path.join(work_dir, lock_file)): | |
os.remove(os.path.join(work_dir, lock_file)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment