#66 Add explicit --datestamp option for rpmdev-bumpspec
Merged 3 years ago by ngompa. Opened 3 years ago by churchyard.
churchyard/rpmdevtools bumpspec-custom-date  into  master

file modified
+15 -1
@@ -147,6 +147,16 @@ 

  

      _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]):
@@ -154,7 +164,9 @@ 

                      evrstring = ' - %s' % evr

                  else:

                      evrstring = ''

-                 if opts.legacy_datestamp:

+                 if opts.datestamp:

+                     date = self.validateDatestamp(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 +302,8 @@ 

                        "(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',

no initial comment

What's the use-case for this?

When we try to automatically handle git conflicts wrt changelogs and releases, we can parse the changelog content, author and name form the diff junk. Than, we'd like to use rpmdev-bumpspec to create the new changelog entry.

https://github.com/fedora-python/ferrypick/pull/10

Currently, we can only have that with today's date, but I'd like to reuse the one from the diff junk (assuming it's >= than the latest one).

Makes sense to me, but can you please add some date format validation here? As it stands, you can pass garbage in and break a package build that way.

That was my intention. Garbage in, garbage out. Same as with userstring, where you can pass garbage as well. For our use case, if the git conflict has garbage date, we want to preserve it.

If you want to shoot yourself in the foot, you can. I can certainly emphasize that in the help text if that helps.

The author name can be pretty much arbitrary, but datestamps cannot be. Borked datestamps in terms of formatting and structure will break it.

If you insist. Let me try to figure out how does rpm validate that datestamp.

To be clear, I am not trying to enforce that you validate the chronology. If it is chronologically wrong, that's on you. I just want you to ensure that the datestamp is formatted as %a %b %e %T %Z %Y when passed to be in the rpm changelog, regardless of input format.

1 new commit added

  • Validate user-provided datestamp
3 years ago

Note that I was unable to use either %e or %T in it, so I had to improvise. I hope it is good enough.

2 new commits added

  • Validate user-provided datestamp
  • Add explicit --datestamp option for rpmdev-bumpspec
3 years ago

That's fine. Odd, but fine.

Pull-Request has been merged by ngompa

3 years ago
Metadata