def ValidateSave(self) -> bool: """Checks if a valid footprint name and folder are selected Returns: bool: true if the selected folder exists """ name = self.ui.le_Name.text() folder = QDir(self.ui.le_Path.text()) folderInfo = QFileInfo(folder.absolutePath()) if (folderInfo.isDir() and folderInfo.isWritable()): return folder.exists() and name != "" else: return False
def _ensure_writable_location(self, dstDir): while True: dstDirInfo = QFileInfo(dstDir) if ( dstDirInfo.isDir() and dstDirInfo.isWritable() ): return dstDir else: # Display error messagebox msgBox = QtWidgets.QMessageBox(self) msgBox.setWindowTitle(_translate("MessageBox", "PyCirkuit - Error", "Message Box title")) msgBox.setIcon(QtWidgets.QMessageBox.Critical) msgBox.setText(_translate("MessageBox", "The exporting destination directory is not writable.", "Message box text." )) msgBox.setInformativeText(_translate("MessageBox", "Please enter a suitable directory to write into.", "Message Box text")) msgBox.setStandardButtons(QtWidgets.QMessageBox.Ok) msgBox.exec() # Ask user to choose another directory dstDir = self._ask_writable_dir(dstDirInfo.canonicalPath())[0]
def Output(filename, output_dir, mod, suffix, rewrite=True, index=-1): """ Take input filename, output dir path, and make a new filename using mod and suffix. Rewrite a file by default. Can be used with Blister.Threading(). """ METHOD_NAME = f"Blister.Output" thread_id = Blister.ThreadID(index) if mod != "": mod = "_" + mod if (suffix != ""): suffix = "." + suffix fileinfo_old = QFileInfo(filename) fileinfo = QFileInfo(QDir(output_dir), fileinfo_old.baseName() + mod + suffix) if (fileinfo.exists() and (not fileinfo.isFile())): print(f"{thread_id}{METHOD_NAME}: This path is a dir:\n{thread_id}\t{fileinfo.absoluteFilePath()}", end='\n') return False if ((fileinfo.exists() and (not fileinfo.isWritable())) or ((not fileinfo.exists()) and (not QFileInfo(fileinfo.absolutePath()).permission(QFile.WriteUser)))): print(f"{thread_id}{METHOD_NAME}: Writing this file is not permitted:\n{thread_id}\t{fileinfo.absoluteFilePath()}", end='\n') return False if (fileinfo.exists() and (rewrite == False)): fileinfo = QFileInfo(QDir(output_dir), fileinfo_old.baseName()+ "_" + str(int(time.time()) % 100000) + suffix) print(f"{thread_id}{METHOD_NAME}: File to write already exists [rewriting is forbidden]. It will be renamed:\n{thread_id}\t{fileinfo_old.absoluteFilePath()} --> {fileinfo.absoluteFilePath()}", end='\n') return fileinfo.absoluteFilePath()
def choose_mountpoint(self): while True: path = QFileDialog.getExistingDirectory( self, QCoreApplication.translate("GlobalSettingsWidget", "Choose a mountpoint"), str(pathlib.Path.home()), ) if not path: return path_info = QFileInfo(path) if not path_info.isDir() or not path_info.isWritable(): show_error( self, QCoreApplication.translate( "GlobalSettingsWidget", "The choosen folder is not writable."), ) else: self.line_edit_mountpoint.setText(path_info.absoluteFilePath()) return
def main(): # Initialise. defaultContext = "@default" fetchedTor = MetaTranslator() codecForTr = '' codecForSource = '' tsFileNames = [] uiFileNames = [] verbose = False noObsolete = False metSomething = False numFiles = 0 standardSyntax = True metTsFlag = False tr_func = None translate_func = None # Parse the command line. for arg in sys.argv[1:]: if arg == "-ts": standardSyntax = False argc = len(sys.argv) i = 1 while i < argc: arg = sys.argv[i] i += 1 if arg == "-help": printUsage() sys.exit(0) if arg == "-version": sys.stderr.write("pylupdate5 v%s\n" % PYQT_VERSION_STR) sys.exit(0) if arg == "-noobsolete": noObsolete = True continue if arg == "-verbose": verbose = True continue if arg == "-ts": metTsFlag = True continue if arg == "-tr-function": if i >= argc: sys.stderr.write( "pylupdate5 error: missing -tr-function name\n") sys.exit(2) tr_func = sys.argv[i] i += 1 continue if arg == "-translate-function": if i >= argc: sys.stderr.write( "pylupdate5 error: missing -translate-function name\n") sys.exit(2) translate_func = sys.argv[i] i += 1 continue numFiles += 1 fullText = "" if not metTsFlag: f = QFile(arg) if not f.open(QIODevice.ReadOnly): sys.stderr.write("pylupdate5 error: Cannot open file '%s'\n" % arg) sys.exit(1) t = QTextStream(f) fullText = t.readAll() f.close() if standardSyntax: oldDir = QDir.currentPath() QDir.setCurrent(QFileInfo(arg).path()) fetchedTor = MetaTranslator() codecForTr = '' codecForSource = '' tsFileNames = [] uiFileNames = [] for key, value in proFileTagMap(fullText).items(): for t in value.split(' '): if key == "SOURCES": fetchtr_py(QDir.current().absoluteFilePath(t), fetchedTor, defaultContext, True, codecForSource, tr_func, translate_func) metSomething = True elif key == "TRANSLATIONS": tsFileNames.append(QDir.current().absoluteFilePath(t)) metSomething = True elif key in ("CODEC", "DEFAULTCODEC", "CODECFORTR"): codecForTr = t fetchedTor.setCodec(codecForTr) elif key == "CODECFORSRC": codecForSource = t elif key == "FORMS": fetchtr_ui(QDir.current().absoluteFilePath(t), fetchedTor, defaultContext, True) updateTsFiles(fetchedTor, tsFileNames, codecForTr, noObsolete, verbose) if not metSomething: sys.stderr.write( "pylupdate5 warning: File '%s' does not look like a " "project file\n" % arg) elif len(tsFileNames) == 0: sys.stderr.write( "pylupdate5 warning: Met no 'TRANSLATIONS' entry in " "project file '%s'\n" % arg) QDir.setCurrent(oldDir) else: if metTsFlag: if arg.lower().endswith(".ts"): fi = QFileInfo(arg) if not fi.exists() or fi.isWritable(): tsFileNames.append(arg) else: sys.stderr.write( "pylupdate5 warning: For some reason, I " "cannot save '%s'\n" % arg) else: sys.stderr.write( "pylupdate5 error: File '%s' lacks .ts extension\n" % arg) else: fi = QFileInfo(arg) if fi.suffix() in ("py", "pyw"): fetchtr_py(fi.absoluteFilePath(), fetchedTor, defaultContext, True, codecForSource, tr_func, translate_func) else: fetchtr_ui(fi.absoluteFilePath(), fetchedTor, defaultContext, True) if not standardSyntax: updateTsFiles(fetchedTor, tsFileNames, codecForTr, noObsolete, verbose) if numFiles == 0: printUsage() sys.exit(1)
def main(): # Initialise. defaultContext = "@default" fetchedTor = MetaTranslator() codecForTr = '' codecForSource = '' tsFileNames = [] uiFileNames = [] verbose = False noObsolete = False metSomething = False numFiles = 0 standardSyntax = True metTsFlag = False tr_func = None translate_func = None # Parse the command line. for arg in sys.argv[1:]: if arg == "-ts": standardSyntax = False argc = len(sys.argv) i = 1 while i < argc: arg = sys.argv[i] i += 1 if arg == "-help": printUsage() sys.exit(0) if arg == "-version": sys.stderr.write("pylupdate5 v%s\n" % PYQT_VERSION_STR) sys.exit(0) if arg == "-noobsolete": noObsolete = True continue if arg == "-verbose": verbose = True continue if arg == "-ts": metTsFlag = True continue if arg == "-tr-function": if i >= argc: sys.stderr.write( "pylupdate5 error: missing -tr-function name\n") sys.exit(2) tr_func = sys.argv[i] i += 1 continue if arg == "-translate-function": if i >= argc: sys.stderr.write( "pylupdate5 error: missing -translate-function name\n") sys.exit(2) translate_func = sys.argv[i] i += 1 continue numFiles += 1 fullText = "" if not metTsFlag: f = QFile(arg) if not f.open(QIODevice.ReadOnly): sys.stderr.write( "pylupdate5 error: Cannot open file '%s'\n" % arg) sys.exit(1) t = QTextStream(f) fullText = t.readAll() f.close() if standardSyntax: oldDir = QDir.currentPath() QDir.setCurrent(QFileInfo(arg).path()) fetchedTor = MetaTranslator() codecForTr = '' codecForSource = '' tsFileNames = [] uiFileNames = [] for key, value in proFileTagMap(fullText).items(): for t in value.split(' '): if key == "SOURCES": fetchtr_py(QDir.current().absoluteFilePath(t), fetchedTor, defaultContext, True, codecForSource, tr_func, translate_func) metSomething = True elif key == "TRANSLATIONS": tsFileNames.append(QDir.current().absoluteFilePath(t)) metSomething = True elif key in ("CODEC", "DEFAULTCODEC", "CODECFORTR"): codecForTr = t fetchedTor.setCodec(codecForTr) elif key == "CODECFORSRC": codecForSource = t elif key == "FORMS": fetchtr_ui(QDir.current().absoluteFilePath(t), fetchedTor, defaultContext, True) updateTsFiles(fetchedTor, tsFileNames, codecForTr, noObsolete, verbose) if not metSomething: sys.stderr.write( "pylupdate5 warning: File '%s' does not look like a " "project file\n" % arg) elif len(tsFileNames) == 0: sys.stderr.write( "pylupdate5 warning: Met no 'TRANSLATIONS' entry in " "project file '%s'\n" % arg) QDir.setCurrent(oldDir) else: if metTsFlag: if arg.lower().endswith(".ts"): fi = QFileInfo(arg) if not fi.exists() or fi.isWritable(): tsFileNames.append(arg) else: sys.stderr.write( "pylupdate5 warning: For some reason, I " "cannot save '%s'\n" % arg) else: sys.stderr.write( "pylupdate5 error: File '%s' lacks .ts extension\n" % arg) else: fi = QFileInfo(arg) if fi.suffix() in ("py", "pyw"): fetchtr_py(fi.absoluteFilePath(), fetchedTor, defaultContext, True, codecForSource, tr_func, translate_func) else: fetchtr_ui(fi.absoluteFilePath(), fetchedTor, defaultContext, True) if not standardSyntax: updateTsFiles(fetchedTor, tsFileNames, codecForTr, noObsolete, verbose) if numFiles == 0: printUsage() sys.exit(1)