44 |
44 |
45 def __init__(self, parent=None): |
45 def __init__(self, parent=None): |
46 """ |
46 """ |
47 Constructor |
47 Constructor |
48 |
48 |
49 @param parent reference to the parent object (QObject) |
49 @param parent reference to the parent object |
|
50 @type QObject |
50 """ |
51 """ |
51 super().__init__(parent) |
52 super().__init__(parent) |
52 |
53 |
53 self.__parseLine = self.__parseUnixLine |
54 self.__parseLine = self.__parseUnixLine |
54 self.__modeSwitchAllowed = True |
55 self.__modeSwitchAllowed = True |
55 |
56 |
56 def __ignoreLine(self, line): |
57 def __ignoreLine(self, line): |
57 """ |
58 """ |
58 Private method to check, if the line should be ignored. |
59 Private method to check, if the line should be ignored. |
59 |
60 |
60 @param line to check (string) |
61 @param line to check |
61 @return flag indicating to ignore the line (boolean) |
62 @type str |
|
63 @return flag indicating to ignore the line |
|
64 @rtype bool |
62 """ |
65 """ |
63 return line.strip() == "" or line.strip().lower().startswith("total ") |
66 return line.strip() == "" or line.strip().lower().startswith("total ") |
64 |
67 |
65 def __parseUnixMode(self, modeString, urlInfo): |
68 def __parseUnixMode(self, modeString, urlInfo): |
66 """ |
69 """ |
67 Private method to parse a Unix mode string modifying the |
70 Private method to parse a Unix mode string modifying the |
68 given URL info object. |
71 given URL info object. |
69 |
72 |
70 @param modeString mode string to be parsed (string) |
73 @param modeString mode string to be parsed |
71 @param urlInfo reference to the URL info object (EricUrlInfo) |
74 @type str |
|
75 @param urlInfo reference to the URL info object |
|
76 @type EricUrlInfo |
72 @exception FtpDirLineParserError Raised if the mode cannot be parsed. |
77 @exception FtpDirLineParserError Raised if the mode cannot be parsed. |
73 """ |
78 """ |
74 if len(modeString) != 10: |
79 if len(modeString) != 10: |
75 raise FtpDirLineParserError("invalid mode string '{0}'".format(modeString)) |
80 raise FtpDirLineParserError("invalid mode string '{0}'".format(modeString)) |
76 |
81 |
121 <ul> |
126 <ul> |
122 <li>"Nov 23 02:33" (month name, day of month, time)</li> |
127 <li>"Nov 23 02:33" (month name, day of month, time)</li> |
123 <li>"May 26 2005" (month name, day of month, year)</li> |
128 <li>"May 26 2005" (month name, day of month, year)</li> |
124 </ul> |
129 </ul> |
125 |
130 |
126 @param monthAbbreviation abbreviation of the month name (string) |
131 @param monthAbbreviation abbreviation of the month name |
127 @param day day of the month (string) |
132 @type str |
128 @param yearOrTime string giving the year or a time (string) |
133 @param day day of the month |
129 @param urlInfo reference to the URL info object (EricUrlInfo) |
134 @type str |
|
135 @param yearOrTime string giving the year or a time |
|
136 @type str |
|
137 @param urlInfo reference to the URL info object |
|
138 @type EricUrlInfo |
130 @exception FtpDirLineParserError Raised if the month abbreviation is |
139 @exception FtpDirLineParserError Raised if the month abbreviation is |
131 not recognized. |
140 not recognized. |
132 """ |
141 """ |
133 try: |
142 try: |
134 month = FtpDirLineParser.MonthnamesNumbers[monthAbbreviation.lower()] |
143 month = FtpDirLineParser.MonthnamesNumbers[monthAbbreviation.lower()] |
155 Private method to split a line of a Unix like directory listing. |
164 Private method to split a line of a Unix like directory listing. |
156 |
165 |
157 It splits the line into meta data, number of links, user, group, size, |
166 It splits the line into meta data, number of links, user, group, size, |
158 month, day, year or time and name. |
167 month, day, year or time and name. |
159 |
168 |
160 @param line directory line to split (string) |
169 @param line directory line to split |
|
170 @type str |
161 @return tuple of nine strings giving the meta data, |
171 @return tuple of nine strings giving the meta data, |
162 number of links, user, group, size, month, day, year or time |
172 number of links, user, group, size, month, day, year or time |
163 and name |
173 and name |
|
174 @rtype tuple |
164 @exception FtpDirLineParserError Raised if the line is not of a |
175 @exception FtpDirLineParserError Raised if the line is not of a |
165 recognized Unix format. |
176 recognized Unix format. |
166 """ |
177 """ |
167 # This method encapsulates the recognition of an unusual |
178 # This method encapsulates the recognition of an unusual |
168 # Unix format variant. |
179 # Unix format variant. |
230 |
243 |
231 Date time strings in Windows-style directory listings typically |
244 Date time strings in Windows-style directory listings typically |
232 have the format "10-23-12 03:25PM" (month-day_of_month-two_digit_year, |
245 have the format "10-23-12 03:25PM" (month-day_of_month-two_digit_year, |
233 hour:minute, am/pm). |
246 hour:minute, am/pm). |
234 |
247 |
235 @param date date string (string) |
248 @param date date string |
236 @param time time string (string) |
249 @type str |
237 @param urlInfo reference to the URL info object (EricUrlInfo) |
250 @param time time string |
|
251 @type str |
|
252 @param urlInfo reference to the URL info object |
|
253 @type EricUrlInfo |
238 @exception FtpDirLineParserError Raised if either of the strings is not |
254 @exception FtpDirLineParserError Raised if either of the strings is not |
239 recognized. |
255 recognized. |
240 """ |
256 """ |
241 try: |
257 try: |
242 month, day, year = [int(part) for part in date.split("-")] |
258 month, day, year = [int(part) for part in date.split("-")] |
259 |
275 |
260 def __parseWindowsLine(self, line): |
276 def __parseWindowsLine(self, line): |
261 """ |
277 """ |
262 Private method to parse a Windows style directory listing line. |
278 Private method to parse a Windows style directory listing line. |
263 |
279 |
264 @param line directory line to be parsed (string) |
280 @param line directory line to be parsed |
265 @return URL info object containing the valid data (EricUrlInfo) |
281 @type str |
|
282 @return URL info object containing the valid data |
|
283 @rtype EricUrlInfo |
266 @exception FtpDirLineParserError Raised if the line is not of a |
284 @exception FtpDirLineParserError Raised if the line is not of a |
267 recognized Windows format. |
285 recognized Windows format. |
268 """ |
286 """ |
269 try: |
287 try: |
270 date, time, dirOrSize, name = line.split(None, 3) |
288 date, time, dirOrSize, name = line.split(None, 3) |
316 |
334 |
317 This implementation support Unix and Windows style directory |
335 This implementation support Unix and Windows style directory |
318 listings. It tries Unix style first and if that fails switches |
336 listings. It tries Unix style first and if that fails switches |
319 to Windows style. If that fails as well, an exception is raised. |
337 to Windows style. If that fails as well, an exception is raised. |
320 |
338 |
321 @param line directory line to be parsed (string) |
339 @param line directory line to be parsed |
322 @return URL info object containing the valid data (EricUrlInfo) |
340 @type str |
|
341 @return URL info object containing the valid data |
|
342 @rtype EricUrlInfo |
323 """ |
343 """ |
324 if self.__ignoreLine(line): |
344 if self.__ignoreLine(line): |
325 return None |
345 return None |
326 |
346 |
327 try: |
347 try: |