def __get_sqlite_name(self) -> str: """Create the name for the SqliteDB. Therefor combine the Qt Application Defs: QStandardPaths.DataLocation + QtCoreApplication.applicationName + .sqlite3 * *on Mac is this* `~/Library/Application Support/io.jmuelbert.github/jmbde/jmbde.sqlite3` * *on Linux this* `~/.local/share/<APPNAME>/jmbde.sqlite3` * *on Windows is this* `C:/Users/<USER>/AppData/Local/<APPNAME>/jmbde.sqlite3` Returns: The connection string fot the sqlite database. """ db_data_path = QStandardPaths.writableLocation( QStandardPaths.DataLocation) self.log.info("The Database: {}".format(db_data_path)) write_dir = QDir(db_data_path) if not write_dir.mkpath("."): self.log.error("Failed to create writable directory") if not write_dir.exists(): write_dir.mkpath(db_data_path) # Ensure that we have a writable location on all devices. filename = "{}/{}.sqlite3".format(write_dir.absolutePath(), QCoreApplication.applicationName()) return filename
def __init__(self): DossierActuel = QDir(QDir.currentPath()) if not DossierActuel.cd("platform-tools"): url = None if platform.system() == "Windows": url = 'https://dl.google.com/android/repository/platform-tools-latest-windows.zip' elif platform.system() == "Darwin": #MacOS url = 'https://dl.google.com/android/repository/platform-tools-latest-darwin.zip' elif platform.system() == "Linux": url = 'https://dl.google.com/android/repository/platform-tools-latest-linux.zip' reply = requests.get(url) zip_ref = zipfile.ZipFile(io.BytesIO(reply.content)) zip_ref.extractall(DossierActuel.absolutePath()) zip_ref.close() super(MainWindow, self).__init__() self.ui = Ui_MainWindow() self.ui.setupUi(self) self.Manager = ManagerDevice(self) self.Manager.start() self.ui.SelectScript.clicked.connect(self.LoadScripts) self.ui.SelectData.clicked.connect(self.LoadData) self.ui.ButtonAllGo.clicked.connect(self.ButtonAllGo) self.ui.tableWidget.itemActivated.connect(self.ClickDevice)
def open_directory(self, path=''): if not path: path = QFileDialog.getExistingDirectory(self, 'Open Directory', '.', QFileDialog.ShowDirsOnly) if not path: return directory = QDir(path) directory.setNameFilters(self.filters) self.image_list = [] image_files = directory.entryList() for file in image_files: self.add_item(directory.absolutePath() + '/' + file)
def open_directory(self): directory_url = QFileDialog.getExistingDirectory( self, '0Open directory', QDir.homePath()) dir = QDir(directory_url) filters = [ '*.mp4', '*.m4v', '*.mov', '*.mpg', '*.mpeg', '*.mp3', '*.m4a', '*.wmv', '*.wav', '*.aiff' ] dir.setNameFilters(filters) file_list = dir.entryList() path = dir.absolutePath() + '/' for file in file_list: self.add_item(path + file)
def connectToDatabase(): database = QSqlDatabase.database() if not database.isValid(): database = QSqlDatabase.addDatabase("QSQLITE") if not database.isValid(): logger.error("Cannot add database") writeDir = QDir() # writeDir = QStandardPaths.writableLocation(QStandardPaths.AppDataLocation) if not writeDir.mkpath("."): logger.error("Failed to create writable directory") # Ensure that we have a writable location on all devices fileName = writeDir.absolutePath() + "/chat-database.sqlite3" database.setDatabaseName(fileName) # open() will create the SQLite database if it doesn't exist if not database.open(): logger.error("Cannot open database") QFile.remove(fileName)
def connectToDatabase(logger): database = QSqlDatabase.database() if not database.isValid(): database = QSqlDatabase.addDatabase('QSQLITE') if not database.isValid(): logger.error('Cannot add database') write_dir = QDir() if not write_dir.mkpath('.'): logger.error('Failed to create writable directory') # Ensure that we have a writable location on all devices. filename = '{}/chat-database.sqlite3'.format(write_dir.absolutePath()) # When using the SQLite driver, open() will create the SQLite database if it doesn't exist. database.setDatabaseName(filename) if not database.open(): logger.error('Cannot open database') QFile.remove(filename)
def LoadScripts(self): Result = QFileDialog.getExistingDirectory(self) DirScript = QDir(Result) if DirScript.cd("Script"): if not self.ui.PathData.text().strip() != "": ####UnloadScripts ListScript = DirScript.entryInfoList(["*.py"]) for mod in ListScript: # removes module from the system mod_name = mod.baseName() if mod_name in sys.modules: #ListFunction = dir(mod_name) del sys.modules[mod_name] Helper.DeviceHelper.FunctionCallDict = {} self.ui.PathScript.setText(Result) #self.ui.LogTerminal.setText(DirScript.absolutePath()) sys.path.append(DirScript.absolutePath()) DirScript.entryInfoList(["*.py"]) for Script in ListScript: __import__(Script.baseName()) ListFunction = Helper.DeviceHelper.FunctionCallDict.values() for item in ListFunction: self.ui.ListScript.addItem(item) #for function in ListFunction: # Helper.DeviceHelper.function = types.MethodType(function,Helper.DeviceHelper) #setattr(Helper.DeviceHelper, ScriptModule.__dict__[function], function) #Helper.DeviceHelper.__dict__[function] = function ListVar = [] f = open(QDir(Result).absoluteFilePath("Var.txt"), 'r') for ligne in f.readlines(): ListVar.append(ligne) f.close() Helper.add_variable_Masterisation(ListVar) self.Manager.ReloadTerminaux() else: #Error print("Error")
def organize_files(): separator = window.cmb_separator.currentText() target_dir = QDir(window.edit_target_dir.text()) list_target_dirs = target_dir.entryList() progress = progress_window() progress.set_max(window.list_files.count()) for index in range(window.list_files.count()): progress.set_value(index) # # STEP 1: Create target directory if necessary # # Get folder name for file fn_src = window.list_files.item(index).text() progress.set_text("Processing \"{0}\"".format(fn_src)) md = pyexiv2.ImageMetadata(fn_src) image_ts = datetime.date try: md.read() image_ts = md['Exif.Photo.DateTimeOriginal'].value except: print("Cannot open file \"{0}\"".format(fn_src)) continue # Makes sure the day and month are always two digits def correct_format(number): if number < 10: return "0" + str(number) else: return str(number) folder_name_trg = str(image_ts.year) + separator + correct_format( image_ts.month) + separator + correct_format(image_ts.day) dir_name_trg = target_dir.absolutePath() + QDir.separator( ) + folder_name_trg # Create folder for day if necessary target_folder = QDir(dir_name_trg) if not target_folder.exists(): QDir.mkdir(target_dir, dir_name_trg) print("Created directory \"{0}\"".format(dir_name_trg)) # # STEP 2: Move file # # absolute file name of the new file fn_trg_abs = dir_name_trg + QDir.separator() + fn_src.split( QDir.separator())[-1] file_trg = QFile(fn_trg_abs) # Don't overwrite existing files if file_trg.exists(): print("Skipping file \"{0}\"".format(file_trg.fileName())) continue QFile.copy(fn_src, fn_trg_abs) print("Copied file from \"{0}\" to \"{1}\"".format(fn_src, fn_trg_abs)) print("Finished!")