def __open_button_click(self): files = QtWidgets.QFileDialog.getOpenFileName( self, "Open File", str( pathlib.Path(self.__config.ROOT_DIR).joinpath( self.__config.DUPS)), "Dups file (*.txt)") self.__files.clear() self.__iterator = 0 f = pathlib.Path(files[0]) if files[0] != "" and f.exists(): f = f.open("r") for line in f: if ' | ' in line: sp = line.replace("\n", "").split(' | ') if len(sp) == 2: f1 = pathlib.Path(sp[0]) f2 = pathlib.Path(sp[1]) if f1.exists() and f2.exists( ) and f1.suffix in DowMimeType( "" ).image_formats_suffix_list and f2.suffix in DowMimeType( "").image_formats_suffix_list: self.__files.append([sp[0], sp[1]]) if len(self.__files) > 0: self.__set_image(self.__files[self.__iterator][0], True) self.__set_image(self.__files[self.__iterator][1], False) else: self.__clear_image(True) self.__clear_image(False)
def file_in_db(module, file): global db global config for f in file[1]: f = pathlib.Path(f) if f.suffix in DowMimeType("").video_formats_suffix_list: dbf = db.SelectAllFilesLike(f.name) if dbf is None: download_file(module, file) else: for df in dbf: real = pathlib.Path(df[1]).joinpath(df[0]) if real.exists(): new = pathlib.Path(df[1]).joinpath(f.name) if new.name != real.name: real.replace(new) print(f"Update {df[0]} to {new.name}") db.Update(df[0], "name", new.name) else: gl = pathlib.Path(config.ROOT_DIR).glob(f"**/{f.stem}") something_in = False for gf in gl: something_in = True new_folder = gf.parents[0] new_name = f.name print(f"Update {df} to {new_folder}, {new_name}") db.Update(df[0], "path", new_folder) db.Update(df[0], "name", new_name) if not something_in: download_file(module, file) return True
def download_file(module, file): global db global download_dir short_name = module.GetShortFileName(file) if module.DownloadFile(file): if len(file[1]) > 1: for f in file[1]: f = pathlib.Path(f) p = download_dir.joinpath(short_name) new_name = check_file_type(p.joinpath(f)) if new_name.suffix != f.suffix: p.joinpath(f).replace(new_name) print("Insert to db: %s" % new_name) db.Insert(new_name.name, p, file[2]) else: f = pathlib.Path(file[1][0]) new_name = check_file_type( download_dir.joinpath(f)) if f.suffix not in DowMimeType( "").video_formats_suffix_list else download_dir.joinpath(f) if new_name.suffix != f.suffix: download_dir.joinpath(f).replace(new_name) print("Insert to db: %s" % new_name) db.Insert(new_name.name, download_dir, file[2])
def __load_image(self): file_path = pathlib.Path(self.__logic.current_file) if file_path.name != "" and file_path.exists(): if file_path.suffix in DowMimeType("").image_formats_suffix_list: self.__image.SetImage(file_path) else: self.__image.SetVideo(file_path) else: self.__image.Clear()
def check_file_type(file): file = pathlib.Path(file) img_type = DowMimeType(file).GetType() img_type = "jpg" if img_type == "jpeg" else img_type if img_type != None and img_type != file.suffix: img_type = "." + img_type new_file = pathlib.Path(str(file).split(".")[0] + img_type) return new_file else: return file
def __set_image(self, filename, left: bool): x, y = DowMimeType(filename).GetSize() filename = pathlib.Path(filename) if left: self.__left_image.SetImage(str(filename)) self.__left_image_info.setText(f"{filename.name} {x}x{y}") self.__left_image.update() else: self.__right_image.SetImage(str(filename)) self.__right_image_info.setText(f"{filename.name} {x}x{y}") self.__right_image.update()
def files_diff(): files_db = set() files_glob = set() for t in db.SelectAll(): files_db.add(pathlib.Path(t[1]).joinpath(t[0])) for t in pathlib.Path(config.ROOT_DIR).glob("**/*"): if t.suffix in DowMimeType("").image_formats_suffix_list: files_glob.add(t) inter = files_glob.difference(files_db) print(inter)
def files_format(): for t in pathlib.Path(config.ROOT_DIR).glob("**/*.*"): db_file = db.SelectFileLike(t.stem) if db_file is not None: true_ext = DowMimeType(t).GetType() if true_ext is None: if t.suffix in DowMimeType("").image_formats_suffix_list: folder = pathlib.Path(config.ROOT_DIR).joinpath( config.ERROR_FOLDER) folder.mkdir(parents=True, exist_ok=True) t.replace(folder.joinpath(t.name)) print("Error : " + str(t)) db.Update(db_file[0], "path", folder) continue true_ext = ".jpg" if true_ext == "jpeg" else "." + true_ext if t.suffix != true_ext or pathlib.Path( db_file[0]).suffix != true_ext or t.suffix != pathlib.Path( db_file[0]).suffix: new_name = pathlib.Path(t.stem + true_ext) print(f"Old name: {t}, New name: {new_name}") t.replace(new_name) db.Update(db_file[0], "name", new_name.name)
def __load_files(self): files = [] features = [] for f in pathlib.Path(self.__config.ROOT_DIR).glob("**/*"): if f.suffix in DowMimeType("").image_formats_suffix_list: db_res = self.__db.SelectFile(f.name) if db_res is None: self.__move_to_error(f) elif db_res[3] == "no": try: fts = self.get_features(f) st = ' '.join(str(x) for x in fts) self.__db.Update(f.name, "features", st) files.append(f) features.append(fts) except: self.__move_to_error(f) else: ts = np.array(list(map(np.float32, db_res[3].split(' ')))) files.append(f) features.append(ts) return files, features
from classes.Config import DowConfig from classes.Database import DowDatabase from classes.MimeType import DowMimeType import pathlib config = DowConfig(pathlib.Path(".").joinpath("config.json")) db = DowDatabase(config.ROOT_DIR, config.DB_NAME) add_folder = pathlib.Path(config.ROOT_DIR, config.ADD_FOLDER) for file in add_folder.glob("**/*"): if file.suffix in DowMimeType("").all_formats_suffix_list: if not db.IsFileIn(file.name): db.Insert(file.name, file.parents[0], "tagme")