import glob
import msger
-import utils
from conf import configmgr
import obspkg
import errors
+import gbp.rpm
from gbp.scripts.buildpackage_rpm import main as gbp_build
OSCRC_TEMPLATE = """[general]
msger.warning('multiple specfiles found.')
# get 'name' and 'version' from spec file
- name = utils.parse_spec(specfile, 'name')
- version = utils.parse_spec(specfile, 'version')
- if not name or not version:
+ spec = gbp.rpm.parse_spec(specfile)
+ if not spec.name or not spec.version:
msger.error('can\'t get correct name or version from spec file.')
if opts.base_obsprj is None:
except errors.ObsError, e:
msger.error('%s' % e)
- msger.info('checking out %s/%s to %s ...' % (target_prj, name, tmpdir))
- localpkg = obspkg.ObsPackage(tmpdir, target_prj, name, APISERVER, oscrcpath)
+ msger.info('checking out %s/%s to %s ...' % (target_prj, spec.name, tmpdir))
+ localpkg = obspkg.ObsPackage(tmpdir, target_prj, spec.name, APISERVER, oscrcpath)
oscworkdir = localpkg.get_workdir()
localpkg.remove_all()
msger.info('local changes submitted to build server successfully')
msger.info('follow the link to monitor the build progress:\n'
' %s/package/show?package=%s&project=%s' \
- % (APISERVER.replace('api', 'build'), name, target_prj))
+ % (APISERVER.replace('api', 'build'), spec.name, target_prj))
# TODO need to be better
return '/usr/share/gbs/'
-def parse_spec(spec_path, macro):
- """Parse the spec file to get the specified `macro`
- """
-
- rpmb_cmd = 'rpmbuild'
-
- if which(rpmb_cmd):
- # rpmbuild has been installed in system, use it
- rpmb_cmdline = ("%s -bp --nodeps --force "
- "tmp.spec --define '_topdir .' "
- "--define '_builddir .' "
- "--define '_sourcedir .' "
- "--define '_rpmdir .' "
- "--define '_specdir .' "
- "--define '_srcrpmdir .'") % rpmb_cmd
-
- wf = open('tmp.spec', 'w')
- with file(spec_path) as f:
- for line in f:
- if line.startswith('%prep'):
- line ='%%prep\necho %%{%s}\nexit\n' % macro
- wf.write(line)
- wf.close()
-
- outs = runner.outs(rpmb_cmdline, catch=3)
-
- # clean up
- os.unlink('tmp.spec')
- if os.path.isdir('BUILDROOT'):
- import shutil
- shutil.rmtree('BUILDROOT', ignore_errors=True)
-
- for line in outs.splitlines():
- if line.startswith('+ echo '):
- return line[7:].rstrip()
-
- msger.warning('invalid spec file, cannot get the value of macro %s' \
- % macro)
- return ''
-
- else:
- # TBD parse it directly
- msger.warning('cannot support parsing spec without rpmbuild command')
- return ''
-
def get_processors():
"""
get number of processors (online) based on
+++ /dev/null
-# vim: set fileencoding=utf-8 :
-#
-# check if --help works
-
-import os
-import unittest
-from gitbuildsys import utils
-
-class TestParseSpec(unittest.TestCase):
- """Test utils.parse_spec of gbs function"""
- spec_path = 'tests/testdata/bluez.spec'
- def testParseSpecGoodInput(self):
- valid_keys = ('Name', 'Version', 'Release', 'Summary', 'Description', 'License',
- 'Group', 'Url', 'Os', 'Arch', 'Requireflags', 'Requirename', 'Requireversion',
- 'Platform', 'build', 'buildRoot', 'clean', 'install', 'prep','source0', 'patch0')
- valid_keys2 = (100, 1000, 1001, 1002, 1004, 1005, 1014, 1016, 1020, 1021, 1022, 1048, 1049, 1050, 1132)
- for s in valid_keys:
- ret = utils.parse_spec(self.spec_path, s)
- self.assertNotEqual(ret, '')
- for s in valid_keys2:
- ret = utils.parse_spec(self.spec_path, s)
- self.assertNotEqual(ret, '')
- def testParseSpecBadInput(self):
- invalid_keys = ('names', 'versions', 'test', 'source1000', 'source', 'patch1000', 'patchs','patch-source0',
- '', [], {}, 101, 1003)
- for s in invalid_keys:
- self.assertRaises(Exception, utils.parse_spec, self.spec_path, s)