2018-05-07 11:58:34 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import configparser
|
|
|
|
import os
|
|
|
|
|
|
|
|
|
|
|
|
class Config(object):
|
|
|
|
DEFAULT_CONFIG_FILE = os.path.expanduser('~/.photo-importer.cfg')
|
|
|
|
DEFAULTS = {
|
|
|
|
'main': {
|
2018-05-07 15:59:47 +02:00
|
|
|
'out_time_format': '%%Y-%%m-%%d_%%H-%%M-%%S',
|
2018-05-11 23:11:01 +02:00
|
|
|
'out_date_format': '%%Y-%%m-%%d',
|
2018-05-20 14:08:34 +02:00
|
|
|
'out_subdir_image': 'Foto',
|
|
|
|
'out_subdir_video': 'Video',
|
|
|
|
'out_subdir_audio': 'Audio',
|
2018-05-20 21:23:21 +02:00
|
|
|
'time_src_image': 'exif,name',
|
2018-06-13 18:36:55 +02:00
|
|
|
'time_src_video': 'name,attr',
|
|
|
|
'time_src_audio': 'name,attr',
|
|
|
|
'file_ext_image': 'jpeg,jpg',
|
|
|
|
'file_ext_video': 'mp4,mpg,mpeg,mov,avi',
|
2018-09-23 21:55:10 +02:00
|
|
|
'file_ext_audio': 'mp3,3gp,3gpp,m4a,wav',
|
2018-06-13 18:36:55 +02:00
|
|
|
'file_ext_garbage': 'thm,ctg',
|
|
|
|
'file_ext_ignore': 'ini,zip,db',
|
2018-05-11 23:11:01 +02:00
|
|
|
'remove_garbage': 1,
|
2018-05-21 21:37:08 +02:00
|
|
|
'remove_empty_dirs': 1,
|
2018-05-11 23:11:01 +02:00
|
|
|
'move_mode': 0,
|
2018-05-11 00:14:52 +02:00
|
|
|
'threads_count': 2,
|
2018-06-25 09:47:59 +02:00
|
|
|
},
|
|
|
|
'server': {
|
|
|
|
'port': 8080,
|
2018-09-22 23:34:44 +02:00
|
|
|
'web_path': 'web',
|
|
|
|
'remote_drive_reg': 'sd[d-z][0-9]',
|
|
|
|
'out_path': '/mnt/multimedia/NEW/',
|
2018-05-07 11:58:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-13 00:56:09 +02:00
|
|
|
def __init__(self, filename=None, create=False):
|
|
|
|
if filename is None:
|
|
|
|
filename = self.DEFAULT_CONFIG_FILE
|
|
|
|
|
2018-05-07 11:58:34 +02:00
|
|
|
self.__config = configparser.ConfigParser()
|
|
|
|
self.__config.read_dict(self.DEFAULTS)
|
2018-05-13 00:56:09 +02:00
|
|
|
self.__config.read([filename, ])
|
2018-05-07 11:58:34 +02:00
|
|
|
|
|
|
|
if create:
|
|
|
|
self.__create_if_not_exists()
|
|
|
|
|
|
|
|
def __create_if_not_exists(self):
|
|
|
|
if os.path.exists(self.DEFAULT_CONFIG_FILE):
|
|
|
|
return
|
|
|
|
|
|
|
|
with open(self.DEFAULT_CONFIG_FILE, 'w') as conffile:
|
|
|
|
self.__config.write(conffile)
|
|
|
|
|
2018-05-07 14:54:56 +02:00
|
|
|
def __getitem__(self, sect):
|
|
|
|
return self.__config[sect]
|
2018-05-07 11:58:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2018-05-13 00:56:09 +02:00
|
|
|
Config(create=True)
|