1
0
mirror of https://github.com/sashacmc/photo-importer.git synced 2024-11-24 08:02:14 +02:00

Add add_orig_name option

Add /etc/photo-importer.cfg as additional default config
Update config comments
This commit is contained in:
Alexander Bushnev 2022-12-20 01:05:10 +01:00
parent a990e00b06
commit e1b4cc04b4
6 changed files with 67 additions and 32 deletions

8
debian/changelog vendored
View File

@ -1,3 +1,11 @@
photo-importer (1.2.2) stable; urgency=medium
* Add /etc/photo-importer.cfg as additional default config
* Add add_orig_name option
* Update config comments
-- Alexander Bushnev <Alexander@Bushnev.pro> Tue, 20 Dec 2022 01:01:34 +0100
photo-importer (1.2.1) stable; urgency=medium
* Handle server pmount errors

View File

@ -20,40 +20,44 @@ file_ext_audio = mp3,3gpp,m4a,wav,aac
file_ext_garbage = thm,ctg
file_ext_ignore = ini,zip,db
# Thread count
# Thread count (int, count)
threads_count = 2
# Remove garbage files (photo config, thumbnails, etc.) 0/1
# Remove garbage files (photo config, thumbnails, etc.) (bool, 0/1)
remove_garbage = 1
# Remove empty directories
# Remove empty directories (bool, 0/1)
remove_empty_dirs = 1
# Remove source files (in case of out_path specified) 0/1
# Remove source files (in case of out_path specified) (bool, 0/1)
move_mode = 1
# umask for new folder and copied files
# Umask for new folder and copied files (int, octal)
umask = 0o000
# use jpegtran in place of exiftran 0/1
use_jpegtran = 1
# Use jpegtran in place of exiftran (bool, 0/1)
use_jpegtran = 1
# use shutil libarary in place of system calls 0/1
# Use shutil libarary in place of system calls (bool, 0/1)
# slower but provide more cross platform compatibility
use_shutil = 1
# Add original filename, if it does not contain a timestamp (bool, 0/1)
# (Useful if filename contains some notable information)
add_orig_name = 0
[server]
# server port
# Server port
port = 8080
# path to html files
# Path to html files
web_path = ..\web
# imported output path
# Imported output path
out_path = C:\
# fixed input path
in_path =
# Fixed input path
in_path =
# log file
# Log file
log_file = ..\photo-importer-server.log

View File

@ -20,40 +20,44 @@ file_ext_audio = mp3,3gpp,m4a,wav,aac
file_ext_garbage = thm,ctg
file_ext_ignore = ini,zip,db
# Thread count
# Thread count (int, count)
threads_count = 2
# Remove garbage files (photo config, thumbnails, etc.) 0/1
# Remove garbage files (photo config, thumbnails, etc.) (bool, 0/1)
remove_garbage = 1
# Remove empty directories
# Remove empty directories (bool, 0/1)
remove_empty_dirs = 1
# Remove source files (in case of out_path specified) 0/1
# Remove source files (in case of out_path specified) (bool, 0/1)
move_mode = 1
# umask for new folder and copied files
# Umask for new folder and copied files (int, octal)
umask = 0o000
# use jpegtran in place of exiftran 0/1
# Use jpegtran in place of exiftran (bool, 0/1)
use_jpegtran = 0
# use shutil libarary in place of system calls 0/1
# Use shutil libarary in place of system calls (bool, 0/1)
# slower but provide more cross platform compatibility
use_shutil = 0
# Add original filename, if it does not contain a timestamp (bool, 0/1)
# (Useful if filename contains some notable information)
add_orig_name = 0
[server]
# server port
# Server port
port = 8080
# path to html files
# Path to html files
web_path = /usr/share/photo-importer/web/
# imported output path
# Imported output path
out_path = /mnt/multimedia/NEW/
# fixed input path
# Fixed input path
in_path =
# log file
# Log file
log_file = /var/log/photo-importer-server.log

View File

@ -5,7 +5,10 @@ import configparser
class Config(object):
DEFAULT_CONFIG_FILE = os.path.expanduser('~/.photo-importer.cfg')
DEFAULT_CONFIG_FILES = (
os.path.expanduser('~/.photo-importer.cfg'),
'/etc/photo-importer.cfg',
)
DEFAULTS = {
'main': {
'out_time_format': '%%Y-%%m-%%d_%%H-%%M-%%S',
@ -28,6 +31,7 @@ class Config(object):
'umask': '0o000',
'use_jpegtran': 0,
'use_shutil': 0,
'add_orig_name': 0,
},
'server': {
'port': 8080,
@ -40,7 +44,9 @@ class Config(object):
def __init__(self, filename=None, create=False):
if filename is None:
filename = self.DEFAULT_CONFIG_FILE
for f in self.DEFAULT_CONFIG_FILES:
if os.path.exists(f):
filename = f
self.__config = configparser.ConfigParser()
self.__config.read_dict(self.DEFAULTS)
@ -54,10 +60,10 @@ class Config(object):
self.__create_if_not_exists()
def __create_if_not_exists(self):
if os.path.exists(self.DEFAULT_CONFIG_FILE):
if os.path.exists(self.DEFAULT_CONFIG_FILES[0]):
return
with open(self.DEFAULT_CONFIG_FILE, 'w') as conffile:
with open(self.DEFAULT_CONFIG_FILES[0], 'w') as conffile:
self.__config.write(conffile)
def __getitem__(self, sect):

View File

@ -43,6 +43,8 @@ class FileProp(object):
(re.compile('\d{8}'), '%Y%m%d'),
]
SPACE_REGEX = re.compile(r'\s+')
TIME_SRC_CFG = {
IMAGE: 'time_src_image',
VIDEO: 'time_src_video',
@ -156,6 +158,15 @@ class FileProp(object):
except (FileNotFoundError, KeyError) as ex:
logging.warning('time by attr (%s) exception: %s' % (fullname, ex))
def __calc_orig_name(self, fname):
if not int(self.__config['main']['add_orig_name']):
return ''
for exp, fs in self.DATE_REGEX:
mat = exp.findall(fname)
if len(mat):
return ''
return '_' + self.SPACE_REGEX.sub('_', fname)
def _out_name_full(self, path, out_name, ext):
res = os.path.join(path, out_name) + ext
@ -177,7 +188,9 @@ class FileProp(object):
ftime = self.__time(fullname, fname, tp)
if ftime:
out_name = ftime.strftime(self.__config['main']['out_time_format'])
out_name = ftime.strftime(
self.__config['main']['out_time_format']
) + self.__calc_orig_name(fname)
else:
out_name = None

View File

@ -14,7 +14,7 @@ def get_long_description():
setup(
name='photo-importer',
version='1.2.1',
version='1.2.2',
description='Photo importer tool',
author='Alexander Bushnev',
author_email='Alexander@Bushnev.pro',