Skip to content

Commit

Permalink
Merge pull request #6 from sashacmc/use-shutil
Browse files Browse the repository at this point in the history
Add windows compatibility by means of use_shutil option
  • Loading branch information
sashacmc authored Jan 30, 2022
2 parents 116588a + 20f0043 commit 0fa0acf
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 10 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
photo-importer (1.0.9) stable; urgency=medium

* Add windows compatibility by means of use_shutil option

-- Alexander Bushnev <[email protected]> Sun, 30 Jan 2022 12:20:53 +0100

photo-importer (1.0.8) stable; urgency=medium

* Add jpegtran support
Expand Down
6 changes: 5 additions & 1 deletion photo-importer.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion photo_importer/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -27,6 +27,7 @@ class Config(object):
'threads_count': 2,
'umask': '0o000',
'use_jpegtran': 0,
'use_shutil': 0,
},
'server': {
'port': 8080,
Expand Down
24 changes: 18 additions & 6 deletions photo_importer/mover.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/python3

import os
import shutil
import logging
import subprocess

Expand All @@ -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)

Expand Down Expand Up @@ -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

Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion photo_importer/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'])


Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -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='[email protected]',
Expand Down

0 comments on commit 0fa0acf

Please sign in to comment.