--- a/Utilities/__init__.py Tue Oct 15 22:03:54 2013 +0200 +++ b/Utilities/__init__.py Fri Oct 18 23:00:41 2013 +0200 @@ -92,11 +92,14 @@ class CodingError(Exception): """ - Class implementing an exception, which is raised, if a given coding is incorrect. + Class implementing an exception, which is raised, if a given coding is + incorrect. """ def __init__(self, coding): """ Constructor + + @param coding coding to include in the message (string) """ self.errorMessage = QCoreApplication.translate("CodingError", "The coding '{0}' is wrong for the given text.").format(coding) @@ -142,12 +145,14 @@ into proper text. @param filename name of the file to read (string) - @return tuple of decoded text, encoding and hash value (string, string, string) + @return tuple of decoded text, encoding and hash value (string, string, + string) """ f = open(filename, "rb") text = f.read() f.close() - hash = str(QCryptographicHash.hash(QByteArray(text), QCryptographicHash.Md5).toHex(), + hash = str(QCryptographicHash.hash( + QByteArray(text), QCryptographicHash.Md5).toHex(), encoding="ASCII") return decode(text) + (hash, ) @@ -177,6 +182,7 @@ @param text text to be encoded (string) @param orig_coding type of the original encoding (string) @return tuple of encoded text and encoding used (bytes, string) + @exception CodingError raised to indicate an invalid encoding """ encoding = None if orig_coding == 'utf-8-bom': @@ -525,7 +531,8 @@ def normcasepath(path): """ - Function returning a path, that is normalized with respect to its case and references. + Function returning a path, that is normalized with respect to its case + and references. @param path file path (string) @return case normalized path (string) @@ -545,8 +552,8 @@ def normcaseabspath(path): """ - Function returning an absolute path, that is normalized with respect to its case - and references. + Function returning an absolute path, that is normalized with respect to + its case and references. @param path file path (string) @return absolute, normalized path (string) @@ -567,7 +574,8 @@ def normabsjoinpath(a, *p): """ - Function returning a normalized, absolute path of the joined parts passed into it. + Function returning a normalized, absolute path of the joined parts passed + into it. @param a first path to be joined (string) @param p variable number of path parts to be joind (string) @@ -582,6 +590,8 @@ @param path path to make relative (string) @param start path to make relative from (string) + @return relative path (string) + @exception ValueError raised to indicate an invalid path """ if not path: raise ValueError("no path specified") @@ -666,9 +676,9 @@ Function to build all full path of an executable file from the environment. @param file filename of the executable (string) - @return list of full executable names (list of strings), if the executable file - is accessible via the searchpath defined by the PATH environment variable, - or an empty list otherwise. + @return list of full executable names (list of strings), if the executable + file is accessible via the searchpath defined by the PATH environment + variable, or an empty list otherwise. """ paths = [] @@ -718,7 +728,8 @@ if f1 is None or f2 is None: return False - if normcaseabspath(os.path.realpath(f1)) == normcaseabspath(os.path.realpath(f2)): + if normcaseabspath(os.path.realpath(f1)) == \ + normcaseabspath(os.path.realpath(f2)): return True return False @@ -775,7 +786,8 @@ @return the complete filename (string) """ if ext[0] != ".": - ext = ".{0}".format(ext) # require leading separator, to match os.path.splitext + ext = ".{0}".format(ext) # require leading separator to match + # os.path.splitext return prefix + EXTSEP + ext[1:] @@ -785,7 +797,8 @@ @param path path to be compacted (string) @param width width for the compacted path (integer) - @param measure reference to a function used to measure the length of the string + @param measure reference to a function used to measure the length of the + string @return compacted path (string) """ if measure(path) <= width: @@ -815,7 +828,8 @@ return "" -def direntries(path, filesonly=False, pattern=None, followsymlinks=True, checkStop=None): +def direntries(path, filesonly=False, pattern=None, followsymlinks=True, + checkStop=None): """ Function returning a list of all files and directories. @@ -856,7 +870,8 @@ if os.path.isdir(fentry): if os.path.islink(fentry) and not followsymlinks: continue - files += direntries(fentry, filesonly, pattern, followsymlinks, checkStop) + files += direntries( + fentry, filesonly, pattern, followsymlinks, checkStop) else: files.append(fentry) except OSError: @@ -926,7 +941,8 @@ def parseEnvironmentString(s): """ - Function used to convert an environment string into a list of environment settings. + Function used to convert an environment string into a list of environment + settings. @param s environment string (string) @return list of environment settings (list of strings) @@ -1057,11 +1073,13 @@ """<p>You may use %-codes as placeholders in the string.""" """ Supported codes are:""" """<table>""" - """<tr><td>%C</td><td>column of the cursor of the current editor</td></tr>""" + """<tr><td>%C</td><td>column of the cursor of the current editor""" + """</td></tr>""" """<tr><td>%D</td><td>directory of the current editor</td></tr>""" """<tr><td>%F</td><td>filename of the current editor</td></tr>""" """<tr><td>%H</td><td>home directory of the current user</td></tr>""" - """<tr><td>%L</td><td>line of the cursor of the current editor</td></tr>""" + """<tr><td>%L</td><td>line of the cursor of the current editor""" + """</td></tr>""" """<tr><td>%P</td><td>path of the current project</td></tr>""" """<tr><td>%S</td><td>selected text of the current editor</td></tr>""" """<tr><td>%U</td><td>username of the current user</td></tr>""" @@ -1100,7 +1118,7 @@ def getHomeDir(): """ - Function to get a users home directory + Function to get a users home directory. @return home directory (string) """ @@ -1246,9 +1264,9 @@ interpreter_name), []) -################################################################################ +############################################################################### # functions for environment handling -################################################################################ +############################################################################### def getEnvironmentEntry(key, default=None): @@ -1265,7 +1283,8 @@ if isWindowsPlatform(): filter.setCaseSensitivity(Qt.CaseInsensitive) - entries = [e for e in QProcess.systemEnvironment() if filter.indexIn(e) != -1] + entries = [e for e in QProcess.systemEnvironment() + if filter.indexIn(e) != -1] if not entries: return default @@ -1285,17 +1304,19 @@ if isWindowsPlatform(): filter.setCaseSensitivity(Qt.CaseInsensitive) - entries = [e for e in QProcess.systemEnvironment() if filter.indexIn(e) != -1] + entries = [e for e in QProcess.systemEnvironment() + if filter.indexIn(e) != -1] return len(entries) > 0 -################################################################################ +############################################################################### # Qt utility functions below -################################################################################ +############################################################################### def generateQtToolName(toolname): """ - Module function to generate the executable name for a Qt tool like designer. + Module function to generate the executable name for a Qt tool like + designer. @param toolname base name of the tool (string) @return the Qt tool name without extension (string) @@ -1315,9 +1336,11 @@ """ qtDir = getQtBinariesPath() bundles = [ - os.path.join(qtDir, 'bin', generateQtToolName(toolname.capitalize())) + ".app", + os.path.join( + qtDir, 'bin', generateQtToolName(toolname.capitalize())) + ".app", os.path.join(qtDir, 'bin', generateQtToolName(toolname)) + ".app", - os.path.join(qtDir, generateQtToolName(toolname.capitalize())) + ".app", + os.path.join( + qtDir, generateQtToolName(toolname.capitalize())) + ".app", os.path.join(qtDir, generateQtToolName(toolname)) + ".app", ] for bundle in bundles: @@ -1351,9 +1374,9 @@ return ("open", newArgs) -################################################################################ +############################################################################### # Qt utility functions below -################################################################################ +############################################################################### def generatePySideToolPath(toolname): @@ -1372,9 +1395,11 @@ except ImportError: # step 2: check for a external Python variant if sys.version_info[0] == 2: - prefix = os.path.dirname(Preferences.getDebugger("Python3Interpreter")) + prefix = os.path.dirname( + Preferences.getDebugger("Python3Interpreter")) else: - prefix = os.path.dirname(Preferences.getDebugger("PythonInterpreter")) + prefix = os.path.dirname( + Preferences.getDebugger("PythonInterpreter")) if toolname == "pyside-uic": return os.path.join(prefix, "Scripts", toolname + '.exe') else: @@ -1391,7 +1416,6 @@ @return tuple of two flags indicating the presence of PySide for Python2 and PySide for Python3 (boolean, boolean) """ - try: # step 1: try internal Python variant of PySide import PySide # __IGNORE_EXCEPTION__ @@ -1425,9 +1449,9 @@ else: return ext_py, int_py -################################################################################ +############################################################################### # Other utility functions below -################################################################################ +############################################################################### def generateVersionInfo(linesep='\n'): @@ -1530,22 +1554,23 @@ else: return bool(dataStr) -################################################################################ +############################################################################### # posix compatibility functions below -################################################################################ +############################################################################### # None right now -################################################################################ +############################################################################### # win32 compatibility functions below -################################################################################ +############################################################################### def win32_Kill(pid): """ Function to provide an os.kill equivalent for Win32. - @param pid process id + @param pid process id (integer) + @return result of the kill (boolean) """ import win32api handle = win32api.OpenProcess(1, 0, pid)