From b60781dca47c423afc847644f66641a45c7f800b Mon Sep 17 00:00:00 2001 From: Miro Hrončok Date: Sep 02 2020 19:21:46 +0000 Subject: [PATCH 1/2] Add explicit --datestamp option for rpmdev-bumpspec --- diff --git a/rpmdev-bumpspec b/rpmdev-bumpspec index de3ee84..9312756 100755 --- a/rpmdev-bumpspec +++ b/rpmdev-bumpspec @@ -154,7 +154,9 @@ class SpecFile(object): evrstring = ' - %s' % evr else: evrstring = '' - if opts.legacy_datestamp: + if opts.datestamp: + date = opts.datestamp + elif opts.legacy_datestamp: date = time.strftime("%a %b %e %Y", time.gmtime()) else: date = time.strftime("%a %b %e %T %Z %Y", time.localtime()) @@ -290,6 +292,8 @@ the Free Software Foundation; either version 2 of the License, or "(simple spec files only)") parser.add_option("-D", "--legacy-datestamp", default=False, action='store_true', help="use legacy datestamp for changelog entries") + parser.add_option("-d", "--datestamp", + help="changelog date string (default: today)") parser.add_option("-V", "--verbose", default=False, action='store_true', help="more output") parser.add_option("-v", "--version", default=False, action='store_true', From c4dd46a46d1f56e206166e91cfcff8b175d6ee3c Mon Sep 17 00:00:00 2001 From: Miro Hrončok Date: Sep 02 2020 20:08:56 +0000 Subject: [PATCH 2/2] Validate user-provided datestamp --- diff --git a/rpmdev-bumpspec b/rpmdev-bumpspec index 9312756..bc0a84c 100755 --- a/rpmdev-bumpspec +++ b/rpmdev-bumpspec @@ -147,6 +147,16 @@ class SpecFile(object): _changelog_pattern = re.compile(r"^%changelog(\s|$)", re.I) + def validateDatestamp(self, datestamp): + try: + time.strptime(datestamp, "%a %b %d %H:%M:%S %Z %Y") + except ValueError: + try: + time.strptime(datestamp, "%a %b %d %Y") + except ValueError: + raise BumpSpecError('Bad datestamp: %s\n' % datestamp) + return datestamp + def addChangelogEntry(self, evr, entry, email): for i in range(len(self.lines)): if SpecFile._changelog_pattern.match(self.lines[i]): @@ -155,7 +165,7 @@ class SpecFile(object): else: evrstring = '' if opts.datestamp: - date = opts.datestamp + date = self.validateDatestamp(opts.datestamp) elif opts.legacy_datestamp: date = time.strftime("%a %b %e %Y", time.gmtime()) else: