--- a/bin/expand-zone Thu Mar 15 18:33:36 2012 +0200
+++ b/bin/expand-zone Thu Mar 15 18:33:59 2012 +0200
@@ -56,9 +56,6 @@
parser.add_option('--serial', metavar='FILE',
help="Read/expand serial from given .serial file")
- parser.add_option('--update-serial', action='store_true',
- help="Update serial in given .serial file")
-
# defaults
parser.set_defaults(
loglevel = logging.WARN,
@@ -109,74 +106,17 @@
# open
return codecs.open(path, mode, charset)
-def process_serial (path, update=False) :
+def process_serial (path) :
"""
- Update/process new serial number from given file, based on date.
+ Use serial number from given file.
Returns the new serial as a string.
"""
- DATE_FMT = '%Y%m%d'
- DATE_LEN = 8
-
- SERIAL_FMT = "{date:8}{count:02}"
- SERIAL_LEN = 10
-
- if os.path.exists(path) :
- # read current
- serial = open(path).read().strip()
-
- assert len(serial) == SERIAL_LEN
-
- old_serial = int(serial)
-
- old_date = datetime.strptime(serial[:DATE_LEN], DATE_FMT).date()
- old_count = int(serial[DATE_LEN:])
-
- else :
- log.warn("given .serial does not exist, assuming from today: %s", path)
- old_serial = old_date = old_count = None
-
- if update :
- # update
- today = datetime.now().date()
+ if not os.path.exists(path) :
+ raise Exception("Given --serial does not exist: %s" % path)
- if not old_serial :
- # fresh start
- date = today
- count = 1
-
- log.info("Starting with fresh serial: %s:%s", date, count)
-
- elif old_date < today :
- # update date
- date = today
- count = 1
-
- log.info("Updating to today: %s -> %s", old_date, date)
-
- elif old_date == today :
- # keep date, update count
- date = old_date
- count = old_count + 1
-
- if count > 99 :
- raise Exception("Serial update rollover: %s, %s", date, count)
-
- log.info("Updating today's count: %s, %s", date, count)
-
- else :
- raise Exception("Invalid serial: %s:%s", old_date, old_count)
-
- else :
- date = old_date
- count = old_count
-
- serial = SERIAL_FMT.format(date=date.strftime(DATE_FMT), count=count)
-
- open(path, 'w').write(serial)
-
- return serial
+ return open(path).read().strip()
def parse_expand (expand) :
"""
@@ -197,7 +137,7 @@
# serial?
if options.serial :
- serial = process_serial(options.serial, update=options.update_serial)
+ serial = process_serial(options.serial)
expand['serial'] = serial