73 @param modeString mode string to be parsed (string) |
73 @param modeString mode string to be parsed (string) |
74 @param urlInfo reference to the URL info object (E5UrlInfo) |
74 @param urlInfo reference to the URL info object (E5UrlInfo) |
75 @exception FtpDirLineParserError Raised if the mode cannot be parsed. |
75 @exception FtpDirLineParserError Raised if the mode cannot be parsed. |
76 """ |
76 """ |
77 if len(modeString) != 10: |
77 if len(modeString) != 10: |
78 raise FtpDirLineParserError("invalid mode string '{0}'".format(modeString)) |
78 raise FtpDirLineParserError( |
|
79 "invalid mode string '{0}'".format(modeString)) |
79 |
80 |
80 modeString = modeString.lower() |
81 modeString = modeString.lower() |
81 |
82 |
82 permission = 0 |
83 permission = 0 |
83 if modeString[1] != '-': |
84 if modeString[1] != '-': |
132 @param urlInfo reference to the URL info object (E5UrlInfo) |
133 @param urlInfo reference to the URL info object (E5UrlInfo) |
133 @exception FtpDirLineParserError Raised if the month abbreviation is |
134 @exception FtpDirLineParserError Raised if the month abbreviation is |
134 not recognized. |
135 not recognized. |
135 """ |
136 """ |
136 try: |
137 try: |
137 month = FtpDirLineParser.MonthnamesNumbers[monthAbbreviation.lower()] |
138 month = FtpDirLineParser.MonthnamesNumbers[ |
|
139 monthAbbreviation.lower()] |
138 except KeyError: |
140 except KeyError: |
139 raise FtpDirLineParserError("illegal month abbreviation '{0}'".format( |
141 raise FtpDirLineParserError( |
140 monthAbbreviation)) |
142 "illegal month abbreviation '{0}'".format( |
|
143 monthAbbreviation)) |
141 day = int(day) |
144 day = int(day) |
142 if ':' in yearOrTime: |
145 if ':' in yearOrTime: |
143 year = QDate.currentDate().year() |
146 year = QDate.currentDate().year() |
144 hour, minute = yearOrTime.split(':') |
147 hour, minute = yearOrTime.split(':') |
145 hour = int(hour) |
148 hour = int(hour) |
170 # Unix format variant. |
173 # Unix format variant. |
171 lineParts = line.split() |
174 lineParts = line.split() |
172 fieldCountWithoutUserID = 8 |
175 fieldCountWithoutUserID = 8 |
173 fieldCountWithUserID = fieldCountWithoutUserID + 1 |
176 fieldCountWithUserID = fieldCountWithoutUserID + 1 |
174 if len(lineParts) < fieldCountWithoutUserID: |
177 if len(lineParts) < fieldCountWithoutUserID: |
175 raise FtpDirLineParserError("line '{0}' cannot be parsed".format(line)) |
178 raise FtpDirLineParserError( |
|
179 "line '{0}' cannot be parsed".format(line)) |
176 |
180 |
177 # If we have a valid format (either with or without user id field), |
181 # If we have a valid format (either with or without user id field), |
178 # the field with index 5 is either the month abbreviation or a day. |
182 # the field with index 5 is either the month abbreviation or a day. |
179 try: |
183 try: |
180 int(lineParts[5]) |
184 int(lineParts[5]) |
236 if year >= 70: |
240 if year >= 70: |
237 year = 1900 + year |
241 year = 1900 + year |
238 else: |
242 else: |
239 year = 2000 + year |
243 year = 2000 + year |
240 except (ValueError, IndexError): |
244 except (ValueError, IndexError): |
241 raise FtpDirLineParserError("illegal date string '{0}'".format(month)) |
245 raise FtpDirLineParserError( |
|
246 "illegal date string '{0}'".format(month)) |
242 try: |
247 try: |
243 hour, minute, am_pm = time[0:2], time[3:5], time[5] |
248 hour, minute, am_pm = time[0:2], time[3:5], time[5] |
244 hour = int(hour) |
249 hour = int(hour) |
245 minute = int(minute) |
250 minute = int(minute) |
246 except (ValueError, IndexError): |
251 except (ValueError, IndexError): |
247 raise FtpDirLineParserError("illegal time string '{0}'".format(month)) |
252 raise FtpDirLineParserError( |
|
253 "illegal time string '{0}'".format(month)) |
248 if hour == 12 and am_pm == 'A': |
254 if hour == 12 and am_pm == 'A': |
249 hour = 0 |
255 hour = 0 |
250 if hour != 12 and am_pm == 'P': |
256 if hour != 12 and am_pm == 'P': |
251 hour = hour + 12 |
257 hour = hour + 12 |
252 |
258 |
264 """ |
270 """ |
265 try: |
271 try: |
266 date, time, dirOrSize, name = line.split(None, 3) |
272 date, time, dirOrSize, name = line.split(None, 3) |
267 except ValueError: |
273 except ValueError: |
268 # "unpack list of wrong size" |
274 # "unpack list of wrong size" |
269 raise FtpDirLineParserError("line '{0}' cannot be parsed".format(line)) |
275 raise FtpDirLineParserError( |
|
276 "line '{0}' cannot be parsed".format(line)) |
270 |
277 |
271 if name in [".", ".."]: |
278 if name in [".", ".."]: |
272 return None |
279 return None |
273 |
280 |
274 urlInfo = E5UrlInfo() |
281 urlInfo = E5UrlInfo() |
280 urlInfo.setDir(False) |
287 urlInfo.setDir(False) |
281 urlInfo.setFile(True) |
288 urlInfo.setFile(True) |
282 try: |
289 try: |
283 urlInfo.setSize(int(dirOrSize)) |
290 urlInfo.setSize(int(dirOrSize)) |
284 except ValueError: |
291 except ValueError: |
285 raise FtpDirLineParserError("illegal size '{0}'".format(dirOrSize)) |
292 raise FtpDirLineParserError( |
|
293 "illegal size '{0}'".format(dirOrSize)) |
286 urlInfo.setName(name) |
294 urlInfo.setName(name) |
287 |
295 |
288 ext = os.path.splitext(name.lower())[1] |
296 ext = os.path.splitext(name.lower())[1] |
289 urlInfo.setSymLink(ext == ".lnk") |
297 urlInfo.setSymLink(ext == ".lnk") |
290 |
298 |
291 permissions = (E5UrlInfo.ReadOwner | E5UrlInfo.WriteOwner |
299 permissions = (E5UrlInfo.ReadOwner | E5UrlInfo.WriteOwner |
292 | E5UrlInfo.ReadGroup | E5UrlInfo.WriteGroup |
300 | E5UrlInfo.ReadGroup | E5UrlInfo.WriteGroup |
293 | E5UrlInfo.ReadOther | E5UrlInfo.WriteOther) |
301 | E5UrlInfo.ReadOther | E5UrlInfo.WriteOther) |
294 if ext in [".exe", ".com", ".bat", ".cmd"]: |
302 if ext in [".exe", ".com", ".bat", ".cmd"]: |
295 permissions |= E5UrlInfo.ExeOwner | E5UrlInfo.ExeGroup | E5UrlInfo.ExeOther |
303 permissions |= E5UrlInfo.ExeOwner | E5UrlInfo.ExeGroup | \ |
|
304 E5UrlInfo.ExeOther |
296 urlInfo.setPermissions(permissions) |
305 urlInfo.setPermissions(permissions) |
297 |
306 |
298 return urlInfo |
307 return urlInfo |
299 |
308 |
300 def parseLine(self, line): |
309 def parseLine(self, line): |