Ok, I attached my script.
Version 0.0.3 DRAFT
Required Parameter: path to folder containing raw files
optional Parameter: -m: move files with errors to a sub dir
It generates 3 report files in the picture folder: a log file, a list of ok
files
and a list of buggy files.
Does not dive into sub dirs.
Required: Python 3.5.x+
Tested on Windows, 2.4.4 install has a bug, so please create a folder C:
\darktable\darktable-install\share\darktable\rawspeed and copy C:\Program
Files\darktable\share\darktable\rawspeed\cameras.xml into this.
Tested on Linux (Gentoo)
BR, Micha.
Am Dienstag, 30. Oktober 2018, 11:05:19 CET schrieb Roman Lebedev:
> > I sent this to the dev mailing list:
> Ah, that explains why i have not seen it.
> I would have guessed you could simply attach it to the mail to the mailing
> list.
-------------------------------------------------------------
___________________________________________________________________________
darktable developer mailing list
to unsubscribe send a mail to darktable-dev+unsubscr...@lists.darktable.org
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import os
import argparse
import shutil
#import datetime
import time
#import re
#from subprocess import call
import subprocess
VersionString = "0.0.3 DRAFT"
AppName = 'rs-check'
print('Welcome to {} version {}!\n'.format(AppName, VersionString))
verbosity = False
filestocheck = ['3fr', 'ari', 'arw', 'bay', 'crw', 'cr2', 'cr3', 'cap', 'data', 'dcs', 'dcr', 'dng', 'drf', 'eip',
'erf', 'fff', 'gpr', 'iiq', 'k25', 'kdc', 'mdc', 'mef', 'mos', 'mrw', 'nef', 'nrw', 'obm', 'orf',
'pef', 'ptx', 'pxn', 'r3d', 'raf', 'raw', 'rwl', 'rw2', 'rwz', 'sr2', 'srf', 'srw', 'tif', 'x3f']
subdir = 'buggy'
movefiles = False
report_name = 'rs-check.log.txt'
list_ok = 'rs-check.ok.txt'
list_buggy = 'rs-check.buggy.txt'
if sys.version_info[0] > 2:
# Fix Python 2.x.
try:
raw_input = input
except NameError:
pass
if sys.platform == "win32":
checkbin = 'C:\\Program Files\\darktable\\bin\\darktable-rs-identify.exe'
elif sys.platform == "linux":
checkbin = '/usr/bin/darktable-rs-identify'
else:
print('Platform {} not yet supported. Please file a bug.'.format(sys.platform))
askstring = "Press ENTER for exit."
inkey = raw_input(askstring)
sys.exit('Exit...')
# parse command line arguments:
parser = argparse.ArgumentParser(description='Check if files in a directory can be used with rawspeed/darktable. ',
epilog='Use at own risk!' +
' Please report bugs to michael.fri...@web.de;' +
' include version info. Version: ' + VersionString)
parser.add_argument("path", default=os.getcwd(), nargs='?',
help="Path to directory containing raw files.")
parser.add_argument("-v", "--verbose", help="increase output verbosity",
action="store_true")
parser.add_argument('-m', '--move', help='Move buggy files into a subdir.', action="store_true")
args = parser.parse_args()
if args.verbose:
verbosity = True
if args.move:
movefiles = True
if verbosity:
print('OS platform: ' + sys.platform)
print('Python: {}'.format(sys.version))
print('Running \'{}\''.format(__file__))
print('Current path: {0}'.format(os.getcwd()))
if os.path.isdir(args.path):
path = os.path.abspath(args.path)
else:
askstring = "ERROR Path does not exist or is not a directory!"
inkey = raw_input(askstring)
sys.exit('ERROR')
if verbosity:
print('path: ' + path)
print('path length: ' + str(len(path)))
if len(path) > 200 and sys.platform == "win32":
sys.exit("ERROR Path is too long. Please use max. 200 character long paths. This is a bug of Windows.")
####################
reportfile = os.path.join(path, report_name)
okfile = os.path.join(path, list_ok)
buggyfile = os.path.join(path, list_buggy)
datetimestring = time.strftime("%Y-%m-%d_%H.%M.%S", time.localtime(time.time()))
r = open(reportfile, 'w+')
l_ok = open(okfile, 'w')
l_buggy = open(buggyfile, 'w')
r.write('=======================\nResult:\n')
r.write('Running file \'{}\'\n'.format(__file__))
r.write('Running {} version {}\n'.format(AppName, VersionString))
r.write('Python: {}\n'.format(sys.version))
r.write('OS platform:{}\n'.format(sys.platform))
r.write('Current path: {0}\n'.format(os.getcwd()))
r.write('Path to check: {}\n'.format(path))
r.write('Date: {}\n'.format(datetimestring))
filelist = []
for f in os.listdir(path):
filename = os.path.join(path, f)
base, ext = os.path.splitext(f)
ext = ext.lower()[1:]
if verbosity:
print('File {} has extension {}'.format(f, ext))
if ext in filestocheck:
filelist.append(filename)
if verbosity:
print('\nRAW files found:\n')
print(filelist)
print('{} RAW files found.'.format(len(filelist)))
r.write('{} RAW files found.\n'.format(len(filelist)))
print('Start checking. A dot is for a good file, a number is a buggy file (Error Code):')
buglist = []
starttime = time.time()
datetimestring = time.strftime("%Y-%m-%d_%H.%M.%S", time.localtime(starttime))
r.write('\nStarting Check at {}:\n\n'.format(datetimestring))
for f in filelist:
command = []
command.append(checkbin)
command.append(f)
res = subprocess.run(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
if res.returncode > 0:
ferror = res.stderr.decode('UTF-8')
if verbosity:
print('File {} has return code {}. Complete errors:'.format(f, res.returncode))
print(ferror)
buglist.append(f)
sys.stdout.write(str(res.returncode))
sys.stdout.flush()
r.write('BUG {}: {}\n'.format(ferror, f))
l_buggy.write(f + '\n')
else:
sys.stdout.write('.')
sys.stdout.flush()
r.write('OK: {}\n'.format(f))
l_ok.write(f + '\n')
endtime = time.time()
datetimestring = time.strftime("%Y-%m-%d_%H.%M.%S", time.localtime(starttime))
duration = endtime - starttime
l_buggy.close()
l_ok.close()
r.write('\nProcessing finished at {}.\n'.format(datetimestring))
r.write('Duration: {:.3} s / {} hh:mm:ss\n'.format(duration, time.strftime("%H:%M:%S", time.gmtime(duration))))
r.write('Buggy files:\n')
print('\n\nBuggy Files:')
for f in buglist:
print(f)
r.write('{}\n'.format(f))
print('Total Files: {}'.format(len(filelist)))
print('OK Files: {}'.format(len(filelist) - len(buglist)))
print('Buggy Files: {}'.format(len(buglist)))
r.write('Total Files: {}\n'.format(len(filelist)))
r.write('OK Files: {}\n'.format(len(filelist) - len(buglist)))
r.write('Buggy Files: {}\n'.format(len(buglist)))
average = duration / len(filelist)
r.write('Average time per file: {:.3} s.\n'.format(average))
if len(buglist) == 0:
print('No buggy files, yeah!')
r.write('No buggy files, yeah!\n')
movefiles = False
if movefiles:
oktomove = True
subdirpath = os.path.join(path, subdir)
print('Moving Files:')
if not os.path.exists(subdirpath):
try:
os.makedirs(subdirpath)
except Exception as e:
oktomove = False
print('ERROR: {}'.format(e))
r.write('ERROR {} for creating subdir!\n'.format(e))
if oktomove:
for f in buglist:
ft = os.path.join(path, subdir, os.path.basename(f))
fx = f + '.xmp'
ftx = ft + '.xmp'
if verbosity:
print(os.path.basename(f))
else:
sys.stdout.write('.')
sys.stdout.flush()
try:
shutil.move(f, ft)
except Exception as e:
r.write('ERROR {} when moving {}!\n'.format(e, f))
print('ERROR: {}'.format(e))
if os.path.isfile(fx):
try:
shutil.move(fx, ftx)
except Exception as e:
r.write('ERROR {} when moving {}!\n'.format(e, fx))
print('ERROR: {}'.format(e))
else:
print('Something wrong with result dir, no move possible.')
r.write('Something wrong with result dir, no move possible.\n')
r.close()