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

44 lines
1.1 KiB
Python
Raw Normal View History

#!/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',
'out_date_format': '%%Y-%%m-%%d',
'time_src': 'exif,name,attr',
'remove_garbage': 1,
'move_mode': 0,
'threads_count': 2,
}
}
def __init__(self, filename=None, create=False):
if filename is None:
filename = self.DEFAULT_CONFIG_FILE
self.__config = configparser.ConfigParser()
self.__config.read_dict(self.DEFAULTS)
self.__config.read([filename, ])
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]
if __name__ == "__main__":
Config(create=True)