cheetahgenerator.patch 1.42 KB
Newer Older
Philipp's avatar
Philipp committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
--- cheetahgenerator.orig.py	2018-04-05 11:53:40.322833632 +0200
+++ cheetahgenerator.py	2018-04-05 12:43:28.971182834 +0200
@@ -59,6 +59,8 @@
 import os.path
 import syslog
 import time
+# Needed for week-of-year calculation, added by stimpy.
+import datetime
 
 import configobj
 
@@ -380,18 +382,21 @@
 
         _filename = os.path.basename(template).replace('.tmpl', '')
 
-        # If the filename contains YYYY, MM, or DD, then do the replacement
-        if 'YYYY' in _filename or 'MM' in _filename or 'DD' in _filename:
+        # If the filename contains YYYY, MM, DD or WW, then do the replacement
+        if 'YYYY' in _filename or 'MM' in _filename or 'DD' in _filename or 'WW' in _filename:
             # Get strings representing year, month, and day
             _yr_str  = "%4d"  % ref_tt[0]
             _mo_str  = "%02d" % ref_tt[1]
             _day_str = "%02d"  % ref_tt[2]
+            _week_str = "%02d"  % datetime.date( ref_tt[0], ref_tt[1], ref_tt[2] ).isocalendar()[1];
             # Replace any instances of 'YYYY' with the year string
             _filename = _filename.replace('YYYY', _yr_str)
             # Do the same thing with the month...
             _filename = _filename.replace('MM', _mo_str)
             # ... and the day
             _filename = _filename.replace('DD', _day_str)
+            # added by stimpy: The week.
+            _filename = _filename.replace('WW', _week_str)
 
         return _filename