def __check_folders(self, path): for f_type in FSWorker.get_all_types(path): folder = Config().type_paths.get(f_type) FSWorker.log('type folder', folder) if folder is None: continue FSWorker.log(FSWorker.check_create(Path.join(Path.dirname(__file__), '..', folder), False))
def __date_to_folder(self, date, f_type): type_path = Config().type_paths.get(f_type) if type_path is not None: path = Path.join(Path.dirname(__file__), '..', type_path, str(date.year), str(date.month), str(date.day)) if FSWorker.check_create(path, False): return path return None
def execute(self): """ перенос """ if not Flags().got_work: return # проверить папки по типам import_path = Path.join(Path.dirname(__file__), '..', Config().type_paths.get('import')) self.__check_folders(import_path) types = FSWorker.get_all_types(import_path) # получить список файлов files = FSWorker.get_all_files(import_path) # пройти по файлам for file, f_type in files.items(): if f_type not in types: continue if not FSWorker.check_free_space(file): FSWorker.log('For "{}" not enaugh space'.format(file)) raise Exception f_hash = FSWorker.get_hash_md5(file) FSWorker.log(f_hash, file) if not DBWorker.check_hash(f_hash, file): # проверить хэш date = FSWorker.get_born_date(file) FSWorker.log('born date of "{}" is "{}"'.format(file, date)) # создать/проверить папку folder = self.__date_to_folder(date, f_type) if folder is None: continue _, f = Path.split(file) src = FSWorker.get_filename(Path.join(folder, f)) if FSWorker.copy_file(file, src) and FSWorker.check_create(src): # переместить и записать хэш if f_hash == FSWorker.get_hash_md5(src): # запись хэша DBWorker.write_hash(f_hash, src) FSWorker.remove(file) else: FSWorker.remove(file) FSWorker.remove_empty(import_path) self.make_done()
def __check_start_paths(self): FSWorker.check_create(Config().type_paths.get('import'), False)