#5 Call rpmspec with macros defined using --define
Merged 7 years ago by tibbs. Opened 7 years ago by zbyszek.
zbyszek/spectool master  into  master

file modified
+24 -13
@@ -1,5 +1,6 @@ 

  #!/usr/bin/python3

  import argparse

+ import collections

  import operator

  import glob

  import re
@@ -34,6 +35,7 @@ 

  

  USER_AGENT = 'spectool/' + __version__

  

+ DEFINES = collections.OrderedDict()

  

  # Sure wish I had Python 3.5's subprocess.run(), so here's a hacked one.

  class CompletedProcess(object):
@@ -112,11 +114,8 @@ 

      def parse(self):

          """Call rpmspec and process the result, looking for intersting tags."""

          cmdline = ['rpmspec', '-P', self.spec]

-         try:

-             proc = run(cmdline)

-         except ProcError as e:

-             error('Error: rpmspec call failed!', e)

-         for line in proc.stdout.splitlines():

+         stdout = run_rpm_cmd(cmdline)

+         for line in stdout.splitlines():

              self.parseline(line)

  

      def parseline(self, line):
@@ -289,26 +288,28 @@ 

  

      return opts

  

- 

  def check_rpmspec():

      try:

          run(['rpmspec', '--version'])

      except CalledProcessError:

          error("rpmspec does not appear to be installed.")

  

+ def run_rpm_cmd(cmdline):

+     for macro,value in DEFINES.items():

+         cmdline.extend(['--define', '{} {}'.format(macro, value)])

+     try:

+         proc = run(cmdline)

+     except ProcError as e:

+         error('Error: {} call failed!'.format(cmdline[0]))

+     return proc.stdout

  

  def expand_sourcedir_macro(spec):

      cmdline = ['rpm']

      for arg in 'epoch', 'name', 'release', 'version':

          cmdline.extend(['--define', '{} {}'.format(arg, getattr(spec, arg))])

      cmdline.extend(['--eval', '%_sourcedir'])

- 

-     try:

-         proc = run(cmdline)

-     except ProcError as e:

-         error('Error: rpm call failed!')

-     return proc.stdout.strip()

- 

+     stdout = run_rpm_cmd(cmdline)

+     return stdout.split()

  

  def get_download_location(spec, opts):

      dir = '.'
@@ -477,9 +478,19 @@ 

      print("-> Patches:\n  -> {}".format('\n  -> '.join(spec.patches)))

      print()

  

+ def update_defines(defines):

+     if defines is None:

+         return

+ 

+     for define in defines:

+         macro, _, value = define.partition(' ')

+         if value is None:

+             error('Cannot parse definition {!r}'.format(define))

+         DEFINES[macro] = value

  

  def main():

      opts = parseopts()

+     update_defines(opts.defines)

      check_rpmspec()

      spec = Spec(opts.spec)

  

--define was accepted but essentially ignored.

I don't know how I managed to forget about this. Sorry about that.

I don't know how I managed to forget about this. Sorry about that.

Pull-Request has been merged by tibbs

7 years ago
Metadata