You've already forked photo-importer
							
							
				mirror of
				https://github.com/sashacmc/photo-importer.git
				synced 2025-10-30 23:37:37 +02:00 
			
		
		
		
	
		
			
				
	
	
		
			42 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
		
			1.0 KiB
		
	
	
	
		
			Python
		
	
	
		
			Executable File
		
	
	
	
	
| #!/usr/bin/python3
 | |
| 
 | |
| import configparser
 | |
| import os
 | |
| 
 | |
| 
 | |
| class Config(object):
 | |
|     DEFAULT_CONFIG_FILE = os.path.expanduser('~/.photo-importer.cfg')
 | |
|     DEFAULTS = {
 | |
|         'main': {
 | |
|             'out_time_format': '%%Y-%%m-%%d_%%H-%%M-%%S',
 | |
|             'time_src': 'exif,name,attr',
 | |
|             'remove_garbage': True,
 | |
|             'threads_count': 2,
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     def __init__(self, create=False):
 | |
|         self.__config = configparser.ConfigParser()
 | |
|         self.__config.read_dict(self.DEFAULTS)
 | |
|         self.__config.read([
 | |
|             'photo-importer.cfg',
 | |
|             '/etc/photo-importer.cfg',
 | |
|             self.DEFAULT_CONFIG_FILE])
 | |
| 
 | |
|         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)
 | |
| 
 | |
|     def __getitem__(self, sect):
 | |
|         return self.__config[sect]
 | |
| 
 | |
| 
 | |
| if __name__ == "__main__":
 | |
|     Config(True)
 |