You've already forked photo-importer
							
							
				mirror of
				https://github.com/sashacmc/photo-importer.git
				synced 2025-10-30 23:37:37 +02:00 
			
		
		
		
	Files coping added. Folders structure creation. Names deduplication.
This commit is contained in:
		| @@ -1,6 +1,6 @@ | ||||
| # photo-importer | ||||
| Command line tools for photo importing/renaming/rotating | ||||
|  | ||||
| #Dependencies | ||||
| # Dependencies | ||||
| python3-exif | ||||
| exiftran | ||||
|   | ||||
| @@ -9,9 +9,10 @@ class Config(object): | ||||
|     DEFAULTS = { | ||||
|         'main': { | ||||
|             'out_time_format': '%%Y-%%m-%%d_%%H-%%M-%%S', | ||||
|             'out_date_format': '%%Y-%%m-%%d', | ||||
|             'time_src': 'exif,name,attr', | ||||
|             'remove_garbage': True, | ||||
|             'move_mode': False, | ||||
|             'remove_garbage': 1, | ||||
|             'move_mode': 0, | ||||
|             'threads_count': 2, | ||||
|         } | ||||
|     } | ||||
|   | ||||
							
								
								
									
										11
									
								
								fileprop.py
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								fileprop.py
									
									
									
									
									
								
							| @@ -143,7 +143,16 @@ class FileProp(object): | ||||
|         if path is None: | ||||
|             path = self.__path | ||||
|  | ||||
|         return os.path.join(path, self.out_name()) + self.ext() | ||||
|         out_name = self.out_name() | ||||
|  | ||||
|         res = os.path.join(path, out_name) + self.ext() | ||||
|  | ||||
|         i = 1 | ||||
|         while (os.path.isfile(res)): | ||||
|             i += 1 | ||||
|             res = os.path.join(path, out_name + '_' + str(i) + self.ext()) | ||||
|  | ||||
|         return res | ||||
|  | ||||
|  | ||||
| if __name__ == '__main__': | ||||
|   | ||||
							
								
								
									
										28
									
								
								importer.py
									
									
									
									
									
								
							
							
						
						
									
										28
									
								
								importer.py
									
									
									
									
									
								
							| @@ -1,6 +1,7 @@ | ||||
| #!/usr/bin/python3 | ||||
|  | ||||
| import os | ||||
| import shutil | ||||
| import logging | ||||
| import threading | ||||
|  | ||||
| @@ -15,8 +16,8 @@ class Importer(threading.Thread): | ||||
|         self.__config = config | ||||
|         self.__input_path = input_path | ||||
|         self.__output_path = output_path | ||||
|         self.__move_mode = bool(config['main']['move_mode']) | ||||
|         self.__remove_garbage = bool(config['main']['remove_garbage']) | ||||
|         self.__move_mode = int(config['main']['move_mode']) | ||||
|         self.__remove_garbage = int(config['main']['remove_garbage']) | ||||
|         self.__rot = None | ||||
|         self.__stat = {} | ||||
|  | ||||
| @@ -45,10 +46,13 @@ class Importer(threading.Thread): | ||||
|  | ||||
|     def __move_files(self, filenames): | ||||
|         self.__stat['moved'] = 0 | ||||
|         self.__stat['copied'] = 0 | ||||
|         self.__stat['removed'] = 0 | ||||
|         self.__stat['skipped'] = 0 | ||||
|         self.__stat['processed'] = 0 | ||||
|         res = [] | ||||
|         for fname in filenames: | ||||
|             self.__stat['processed'] += 1 | ||||
|             prop = fileprop.FileProp(self.__config, fname) | ||||
|  | ||||
|             if prop.type() == prop.GARBAGE: | ||||
| @@ -59,18 +63,32 @@ class Importer(threading.Thread): | ||||
|                     self.__stat['skipped'] += 1 | ||||
|                 continue | ||||
|  | ||||
|             if prop.type() == prop.OTHER: | ||||
|             if prop.type() == prop.OTHER or prop.time() is None: | ||||
|                 self.__stat['skipped'] += 1 | ||||
|                 continue | ||||
|  | ||||
|             if self.__output_path: | ||||
|                 pass | ||||
|                 subdir = prop.time().strftime( | ||||
|                     self.__config['main']['out_date_format']) | ||||
|  | ||||
|                 path = os.path.join(self.__output_path, subdir) | ||||
|                 if not os.path.isdir(path): | ||||
|                     os.makedirs(path) | ||||
|  | ||||
|                 fullname = prop.out_name_full(path) | ||||
|                 if self.__move_mode: | ||||
|                     shutil.move(fname, fullname) | ||||
|                     self.__stat['moved'] += 1 | ||||
|                 else: | ||||
|                     shutil.copy2(fname, fullname) | ||||
|                     self.__stat['copied'] += 1 | ||||
|                 res.append(fullname) | ||||
|             else: | ||||
|                 if prop.ok(): | ||||
|                     res.append(fname) | ||||
|                 else: | ||||
|                     new_fname = prop.out_name_full() | ||||
|                     os.rename(fname, new_fname)  # TODO: CHECK DUPLICATES!!!! | ||||
|                     os.rename(fname, new_fname) | ||||
|                     res.append(new_fname) | ||||
|  | ||||
|                 self.__stat['moved'] += 1 | ||||
|   | ||||
							
								
								
									
										4
									
								
								log.py
									
									
									
									
									
								
							
							
						
						
									
										4
									
								
								log.py
									
									
									
									
									
								
							| @@ -18,10 +18,10 @@ def initLogger(filename=None): | ||||
|             os.makedirs(os.path.split(filename)[0]) | ||||
|         except OSError: | ||||
|             pass | ||||
|         #init file logger and console | ||||
|         # init file logger and console | ||||
|         fh = logging.FileHandler(filename, 'a') | ||||
|     else: | ||||
|         #init only console | ||||
|         # init only console | ||||
|         fh = logging.StreamHandler() | ||||
|  | ||||
|     form = '[%(asctime)s] [%(levelname)s] %(message)s' | ||||
|   | ||||
		Reference in New Issue
	
	Block a user