-
Notifications
You must be signed in to change notification settings - Fork 55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added new datetime format to support windows FTP Server #181
base: master
Are you sure you want to change the base?
Conversation
strptime = datetime.datetime.strptime | ||
date_time = strptime(date_time_str, "%m/%d/%Y %I:%M %p") | ||
for fmt in possible_formats: | ||
try: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use contextlib.suppress if you don't need to handle exception, but want to ignore it
break | ||
except ValueError: | ||
continue | ||
if not date_time: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use "else" branch for "for" loop instead of value inspection
@@ -501,9 +501,19 @@ def parse_list_line_windows(self, b): | |||
date_time_str = line[: date_time_end + 1].strip().split(" ") | |||
date_time_str = " ".join([x for x in date_time_str if len(x) > 0]) | |||
line = line[date_time_end + 1 :].lstrip() | |||
|
|||
possible_formats = ["%m/%d/%Y %I:%M %p", "%m-%d-%y %I:%M%p"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be multiline, so new rules can be added without commit history loss
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #181 +/- ##
==========================================
- Coverage 98.83% 98.68% -0.16%
==========================================
Files 6 6
Lines 1896 1904 +8
==========================================
+ Hits 1874 1879 +5
- Misses 22 25 +3 ☔ View full report in Codecov by Sentry. |
Description:-
This PR enhances the parse_list_line_windows method to support multiple date/time formats when parsing Microsoft Windows dir command output. Previously, only one specific date/time format was supported. The following improvements were made:
Changes:
Added support for two date/time formats:
"%m/%d/%Y %I:%M %p" (e.g., 12/18/2024 04:40 PM)
"%m-%d-%y %I:%M%p" (e.g., 12-18-24 04:40PM)
Introduced a loop to try each format and parse the date/time correctly.
Raised a ValueError if none of the formats match, ensuring robust error handling.
Why:
Windows FTP servers may use different date/time formats depending on system configurations and locale settings. Supporting multiple formats improves compatibility and reduces parsing failures.