#31 add argument destdir to R2spec to specify the generated path of the spec file
Opened 8 months ago by siyuan-lou. Modified 8 months ago
siyuan-lou/r2spec master  into  master

file modified
+5 -1
@@ -85,6 +85,8 @@ 

          help='Give more info about what is going on.')

      parser.add_argument('--debug', action='store_true',

          help='Output bunches of debugging info.')

+     parser.add_argument('--destdir', 

+         help='Custom path to save the generated spec file.')

      if prog == 'R2rpm':

          setup_r2rpm_parser(parser)

      return parser
@@ -284,11 +286,13 @@ 

          pack.get_description()

          pack.determine_arch()

  

+         destdir = args.destdir if hasattr(args, 'destdir') else None

+ 

          spec = Spec(settings, pack, no_check=args.no_check,

                      with_deps=args.with_deps)

          spec.fill_spec_info()

          spec.get_template()

-         spec.write_spec(True)

+         spec.write_spec(True, destdir=destdir)

  

          return pack

  

file modified
+9 -6
@@ -228,12 +228,15 @@ 

              self.log.debug('ERROR: %s', err)

              raise R2specError('Cannot read the file %s' % (err, ))

  

-     def get_specfile(self):

+     def get_specfile(self, destdir=None):

          """ Return the path to the spec file.

          """

-         specdir = get_rpm_tag('_specdir')

-         specname = 'R-%s.spec' % self.package.name

-         return '%s/%s' % (specdir, specname)

+         if destdir:

+             return os.path.join(destdir, f'R-{self.package.name}.spec')

+         else:

+             specdir = get_rpm_tag('_specdir')

+             specname = 'R-%s.spec' % self.package.name

+             return '%s/%s' % (specdir, specname)

  

      def read_specfile(self):

          """ Read the specfile present in the spec directory.
@@ -249,10 +252,10 @@ 

                  self.log.info('Cannot read the file %s', specfile)

                  self.log.debug('ERROR: %s', err)

  

-     def write_spec(self, verbose=False):

+     def write_spec(self, verbose=False, destdir=None):

          """ Write down the spec to the spec directory as returned by rpm.

          """

-         specfile = self.get_specfile()

+         specfile = self.get_specfile(destdir)

          self.log.info('Writing file %s', specfile)

          try:

              stream = open(specfile, 'w')

add argument destdir to R2spec to specify the generated path of the spec file

Metadata