--- a/Utilities/FtpUtilities.py Tue Oct 15 22:03:54 2013 +0200 +++ b/Utilities/FtpUtilities.py Fri Oct 18 23:00:41 2013 +0200 @@ -20,6 +20,7 @@ """ Exception class raised, if a parser issue was detected. """ + pass class FtpDirLineParser(QObject): @@ -76,7 +77,8 @@ @exception FtpDirLineParserError Raised if the mode cannot be parsed. """ if len(modeString) != 10: - raise FtpDirLineParserError("invalid mode string '{0}'".format(modeString)) + raise FtpDirLineParserError( + "invalid mode string '{0}'".format(modeString)) modeString = modeString.lower() @@ -135,10 +137,12 @@ not recognized. """ try: - month = FtpDirLineParser.MonthnamesNumbers[monthAbbreviation.lower()] + month = FtpDirLineParser.MonthnamesNumbers[ + monthAbbreviation.lower()] except KeyError: - raise FtpDirLineParserError("illegal month abbreviation '{0}'".format( - monthAbbreviation)) + raise FtpDirLineParserError( + "illegal month abbreviation '{0}'".format( + monthAbbreviation)) day = int(day) if ':' in yearOrTime: year = QDate.currentDate().year() @@ -155,10 +159,12 @@ def __splitUnixLine(self, line): """ - Split a line of a Unix like directory listing into meta data, - number of links, user, group, size, month, day, year or time - and name. + Private method to split a line of a Unix like directory listing. + + It splits the line into meta data, number of links, user, group, size, + month, day, year or time and name. + @param line directory line to split (string) @return tuple of nine strings giving the meta data, number of links, user, group, size, month, day, year or time and name @@ -171,7 +177,8 @@ fieldCountWithoutUserID = 8 fieldCountWithUserID = fieldCountWithoutUserID + 1 if len(lineParts) < fieldCountWithoutUserID: - raise FtpDirLineParserError("line '{0}' cannot be parsed".format(line)) + raise FtpDirLineParserError( + "line '{0}' cannot be parsed".format(line)) # If we have a valid format (either with or without user id field), # the field with index 5 is either the month abbreviation or a day. @@ -194,8 +201,6 @@ @param line directory line to be parsed (string) @return URL info object containing the valid data (E5UrlInfo) - @exception FtpDirLineParserError Raised if the line is not of a - recognized Unix format. """ modeString, nlink, user, group, size, month, day, \ yearOrTime, name = self.__splitUnixLine(line) @@ -239,13 +244,15 @@ else: year = 2000 + year except (ValueError, IndexError): - raise FtpDirLineParserError("illegal date string '{0}'".format(month)) + raise FtpDirLineParserError( + "illegal date string '{0}'".format(month)) try: hour, minute, am_pm = time[0:2], time[3:5], time[5] hour = int(hour) minute = int(minute) except (ValueError, IndexError): - raise FtpDirLineParserError("illegal time string '{0}'".format(month)) + raise FtpDirLineParserError( + "illegal time string '{0}'".format(month)) if hour == 12 and am_pm == 'A': hour = 0 if hour != 12 and am_pm == 'P': @@ -267,7 +274,8 @@ date, time, dirOrSize, name = line.split(None, 3) except ValueError: # "unpack list of wrong size" - raise FtpDirLineParserError("line '{0}' cannot be parsed".format(line)) + raise FtpDirLineParserError( + "line '{0}' cannot be parsed".format(line)) if name in [".", ".."]: return None @@ -283,7 +291,8 @@ try: urlInfo.setSize(int(dirOrSize)) except ValueError: - raise FtpDirLineParserError("illegal size '{0}'".format(dirOrSize)) + raise FtpDirLineParserError( + "illegal size '{0}'".format(dirOrSize)) urlInfo.setName(name) ext = os.path.splitext(name.lower())[1] @@ -293,7 +302,8 @@ | E5UrlInfo.ReadGroup | E5UrlInfo.WriteGroup | E5UrlInfo.ReadOther | E5UrlInfo.WriteOther) if ext in [".exe", ".com", ".bat", ".cmd"]: - permissions |= E5UrlInfo.ExeOwner | E5UrlInfo.ExeGroup | E5UrlInfo.ExeOther + permissions |= E5UrlInfo.ExeOwner | E5UrlInfo.ExeGroup | \ + E5UrlInfo.ExeOther urlInfo.setPermissions(permissions) return urlInfo @@ -308,8 +318,6 @@ @param line directory line to be parsed (string) @return URL info object containing the valid data (E5UrlInfo) - @exception FtpDirLineParserError Raised if the line is not of a - recognized format. """ if self.__ignoreLine(line): return None