mirror of
https://github.com/sashacmc/photo-importer.git
synced 2024-11-24 08:02:14 +02:00
Removing empty dirs added. Logging changed.
This commit is contained in:
parent
1532900ddc
commit
7c2977bc1a
@ -17,6 +17,7 @@ class Config(object):
|
||||
'time_src_video': 'exif,name,attr',
|
||||
'time_src_audio': 'exif,name,attr',
|
||||
'remove_garbage': 1,
|
||||
'remove_empty_dirs': 1,
|
||||
'move_mode': 0,
|
||||
'threads_count': 2,
|
||||
}
|
||||
|
@ -19,5 +19,8 @@ threads_count = 2
|
||||
# Remove garbage files (photo config, thumbnails, etc.) 0/1
|
||||
remove_garbage = 1
|
||||
|
||||
# Remove empty directories
|
||||
remove_empty_dirs = 1
|
||||
|
||||
# Remove source files (in case of out_path specified) 0/1
|
||||
move_mode = 1
|
||||
|
36
importer.py
36
importer.py
@ -24,21 +24,21 @@ class Importer(threading.Thread):
|
||||
'Start: %s -> %s' %
|
||||
(self.__input_path, self.__output_path))
|
||||
|
||||
self.__stat['stage'] = 'scan'
|
||||
filenames = self.__scan_files(self.__input_path)
|
||||
logging.info('Found %s files' % len(filenames))
|
||||
filenames, dirs = self.__scan_files(self.__input_path)
|
||||
|
||||
self.__stat['stage'] = 'move'
|
||||
new_filenames = self.__move_files(filenames)
|
||||
logging.info('Processed %s files' % len(new_filenames))
|
||||
|
||||
self.__stat['stage'] = 'rotate'
|
||||
if self.__config['main']['remove_empty_dirs']:
|
||||
self.__remove_empty_dirs(dirs)
|
||||
|
||||
self.__rotate_files(new_filenames)
|
||||
|
||||
self.__stat['stage'] = 'done'
|
||||
logging.info('Done')
|
||||
|
||||
def __scan_files(self, input_path):
|
||||
self.__stat['stage'] = 'scan'
|
||||
res_dir = []
|
||||
res = []
|
||||
for root, dirs, files in os.walk(
|
||||
input_path, onerror=self.__on_walk_error):
|
||||
@ -46,28 +46,48 @@ class Importer(threading.Thread):
|
||||
for fname in files:
|
||||
res.append(os.path.join(root, fname))
|
||||
|
||||
for dname in dirs:
|
||||
res_dir.append(os.path.join(root, dname))
|
||||
|
||||
self.__stat['total'] = len(res)
|
||||
return res
|
||||
logging.info('Found %i files and %i dirs' % (len(res), len(res_dir)))
|
||||
return res, res_dir
|
||||
|
||||
def __on_walk_error(self, err):
|
||||
logging.error('Scan files error: %s' % err)
|
||||
|
||||
def __move_files(self, filenames):
|
||||
logging.info('Moving')
|
||||
self.__mov = mover.Mover(
|
||||
self.__config,
|
||||
self.__input_path,
|
||||
self.__output_path,
|
||||
filenames)
|
||||
self.__stat['stage'] = 'move'
|
||||
|
||||
return self.__mov.run()
|
||||
res = self.__mov.run()
|
||||
logging.info('Processed %s files' % len(res))
|
||||
return res
|
||||
|
||||
def __rotate_files(self, filenames):
|
||||
logging.info('Rotating')
|
||||
self.__rot = rotator.Rotator(
|
||||
self.__config,
|
||||
filenames)
|
||||
self.__stat['stage'] = 'rotate'
|
||||
|
||||
self.__rot.run()
|
||||
|
||||
def __remove_empty_dirs(self, dirs):
|
||||
logging.info('Removing empty dirs')
|
||||
len_dirs = reversed(sorted([(len(d), d) for d in dirs]))
|
||||
for l, d in len_dirs:
|
||||
try:
|
||||
os.rmdir(d)
|
||||
logging.info('Removed: %s', d)
|
||||
except OSError:
|
||||
logging.info('Skipped: %s', d)
|
||||
|
||||
def status(self):
|
||||
if self.__mov:
|
||||
self.__stat['move'] = self.__mov.status()
|
||||
|
Loading…
Reference in New Issue
Block a user