mirror of
https://github.com/sashacmc/photo-importer.git
synced 2024-11-24 08:02:14 +02:00
Merge pull request #6 from sashacmc/use-shutil
Add windows compatibility by means of use_shutil option
This commit is contained in:
commit
0fa0acfc99
6
debian/changelog
vendored
6
debian/changelog
vendored
@ -1,3 +1,9 @@
|
||||
photo-importer (1.0.9) stable; urgency=medium
|
||||
|
||||
* Add windows compatibility by means of use_shutil option
|
||||
|
||||
-- Alexander Bushnev <Alexander@Bushnev.ru> Sun, 30 Jan 2022 12:20:53 +0100
|
||||
|
||||
photo-importer (1.0.8) stable; urgency=medium
|
||||
|
||||
* Add jpegtran support
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -1,6 +1,7 @@
|
||||
#!/usr/bin/python3
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import logging
|
||||
import subprocess
|
||||
|
||||
@ -23,6 +24,7 @@ class Mover(object):
|
||||
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 @@ class Mover(object):
|
||||
|
||||
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 @@ class Mover(object):
|
||||
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
|
||||
|
@ -58,7 +58,8 @@ class ProgressBar(threading.Thread):
|
||||
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'])
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user