Created
May 30, 2014 18:16
-
-
Save qpfiffer/a3f40ed0e0046b168355 to your computer and use it in GitHub Desktop.
Path for logpurge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From ff762c18533097f528899f2d1d2a83a6eba2d8ca Mon Sep 17 00:00:00 2001 | |
From: Quinlan Pfiffer <[email protected]> | |
Date: Fri, 30 May 2014 11:14:49 -0700 | |
Subject: [PATCH] Improvements from production. | |
- Moved regex to single expression. WOOOOO! | |
- Sorted output. | |
--- | |
logpurge/__init__.py | 9 +++------ | |
1 file changed, 3 insertions(+), 6 deletions(-) | |
diff --git a/logpurge/__init__.py b/logpurge/__init__.py | |
index 7b11107..4cb5cdd 100644 | |
--- a/logpurge/__init__.py | |
+++ b/logpurge/__init__.py | |
@@ -118,11 +118,8 @@ def find_datetime(string): | |
""" | |
regexs = [ | |
- re.compile('(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})-(?P<hour>\d{2}):(?P<minute>\d{2}):(?P<second>\d{2})'), | |
- re.compile('(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2}) (?P<hour>\d{1,2}):(?P<minute>\d{2}):(?P<second>\d{2})'), | |
- re.compile('(?P<year>\d{4})_(?P<month>\d{2})_(?P<day>\d{2})_(?P<hour>\d{2})_(?P<minute>\d{2})_(?P<second>\d{2})'), | |
- re.compile('(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})'), | |
- re.compile('(?P<year>\d{4})(?P<month>\d{2})(?P<day>\d{2})'), | |
+ # WE PERL NOW | |
+ re.compile('(?P<year>\d{4})[-_]?(?P<month>\d{2})[-_]?((?P<day>\d{2})[-_ ]?(?P<hour>\d{2})[-_:]?(?P<minute>\d{2})[-_:]?(?P<second>\d{2}))?'), | |
] | |
for regex in regexs: | |
@@ -183,7 +180,7 @@ def main(): | |
files_to_remove = get_purgeables(files_timestamps) | |
# Print out which ones will be removed | |
- for file_, date in files_dates.items(): | |
+ for file_, date in sorted(files_dates.items(), key=lambda x: x[1]): | |
print '{} - {} {}'.format(file_, date, file_ in files_to_remove) | |
cont = None | |
-- | |
1.7.9.5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment