From 20f0043e2a9a0f9e69885da061a1632fc307a3d2 Mon Sep 17 00:00:00 2001 From: Alexander Bushnev Date: Sun, 30 Jan 2022 12:41:13 +0100 Subject: [PATCH] Add windows compatibility by means of use_shutil option + small bugfixes --- debian/changelog | 6 ++++++ photo-importer.cfg | 6 +++++- photo_importer/config.py | 3 ++- photo_importer/mover.py | 24 ++++++++++++++++++------ photo_importer/run.py | 3 ++- setup.py | 2 +- 6 files changed, 34 insertions(+), 10 deletions(-) diff --git a/debian/changelog b/debian/changelog index 61ba729..285ea06 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +photo-importer (1.0.9) stable; urgency=medium + + * Add windows compatibility by means of use_shutil option + + -- Alexander Bushnev Sun, 30 Jan 2022 12:20:53 +0100 + photo-importer (1.0.8) stable; urgency=medium * Add jpegtran support diff --git a/photo-importer.cfg b/photo-importer.cfg index 2866ac4..4060323 100644 --- a/photo-importer.cfg +++ b/photo-importer.cfg @@ -15,7 +15,7 @@ out_subdir_audio = Audio # File extensions file_ext_image = jpeg,jpg,cr2 -file_ext_video = mp4,mpg,mpeg,mov,avi,mts,3gp +file_ext_video = mp4,mpg,mpeg,mov,avi,mts,3gp,m4v file_ext_audio = mp3,3gpp,m4a,wav file_ext_garbage = thm,ctg file_ext_ignore = ini,zip,db @@ -38,6 +38,10 @@ umask = 0o000 # use jpegtran in place of exiftran 0/1 use_jpegtran = 0 +# use shutil libarary in place of system calls 0/1 +# slower but provide more cross platform compatibility +use_shutil = 0 + [server] # server port port = 8080 diff --git a/photo_importer/config.py b/photo_importer/config.py index 23a28eb..83b9059 100755 --- a/photo_importer/config.py +++ b/photo_importer/config.py @@ -17,7 +17,7 @@ class Config(object): 'time_src_video': 'exif,name,attr', 'time_src_audio': 'exif,name,attr', 'file_ext_image': 'jpeg,jpg', - 'file_ext_video': 'mp4,mpg,mpeg,mov,avi,mts,m2ts,3gp', + 'file_ext_video': 'mp4,mpg,mpeg,mov,avi,mts,m2ts,3gp,m4v', 'file_ext_audio': 'mp3,3gpp,m4a,wav', 'file_ext_garbage': 'thm,ctg', 'file_ext_ignore': 'ini,zip,db', @@ -27,6 +27,7 @@ class Config(object): 'threads_count': 2, 'umask': '0o000', 'use_jpegtran': 0, + 'use_shutil': 0, }, 'server': { 'port': 8080, diff --git a/photo_importer/mover.py b/photo_importer/mover.py index da8cb6e..00b7dc7 100755 --- a/photo_importer/mover.py +++ b/photo_importer/mover.py @@ -1,6 +1,7 @@ #!/usr/bin/python3 import os +import shutil import logging import subprocess @@ -23,6 +24,7 @@ def __init__(self, config, input_path, output_path, filenames, dryrun): self.__move_mode = int(config['main']['move_mode']) self.__remove_garbage = int(config['main']['remove_garbage']) self.__umask = int(config['main']['umask'], 8) + self.__use_shutil = int(config['main']['use_shutil']) self.__stat = {'total': len(filenames)} self.__file_prop = fileprop.FileProp(self.__config) @@ -79,15 +81,11 @@ def __move_file(self, fname, prop): fullname = prop.out_name_full(path) if self.__move_mode: - if not self.__run(["mv", fname, fullname]): - self.__stat['errors'] += 1 - return None + self.__move(fname, fullname) logging.info('"%s" moved "%s"' % (fname, fullname)) self.__stat['moved'] += 1 else: - if not self.__run(["cp", "-a", fname, fullname]): - self.__stat['errors'] += 1 - return None + self.__copy(fname, fullname) logging.info('"%s" copied "%s"' % (fname, fullname)) self.__stat['copied'] += 1 @@ -104,6 +102,20 @@ def __move_file(self, fname, prop): self.__stat['moved'] += 1 return new_fname + def __move(self, src, dst): + if self.__use_shutil: + shutil.move(src, dst) + else: + if not self.__run(["mv", src, dst]): + raise SystemError('mv "%s" "%s" failed' % (src, dst)) + + def __copy(self, src, dst): + if self.__use_shutil: + shutil.copy2(src, dst) + else: + if not self.__run(["cp", "-a", src, dst]): + raise SystemError('mv "%s" "%s" failed' % (src, dst)) + def __run(self, args): if self.__dryrun: return True diff --git a/photo_importer/run.py b/photo_importer/run.py index b0d7dd8..63819f1 100755 --- a/photo_importer/run.py +++ b/photo_importer/run.py @@ -58,7 +58,8 @@ def run(self): self.__pbar.finish() break - if stage == 'move' or stage == 'rotate': + if (stage == 'move' or stage == 'rotate') and \ + self.__pbar is not None: self.__pbar.update(stat[stage]['processed']) diff --git a/setup.py b/setup.py index 204bc51..0f3f741 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup setup(name='photo-importer', - version='1.0.8', + version='1.0.9', description='Photo importer tool', author='Alexander Bushnev', author_email='Alexander@Bushnev.ru',