return srcrpm
-def parse_spec(specfile):
- try:
- return SpecFile(specfile)
- except IOError, err:
- raise GbpError, "Error reading spec file: %s" % err
-
-
def guess_spec(topdir, recursive=True, preferred_name=None):
"""Guess a spec file"""
specs = []
filenames = [os.path.relpath(spec, abstop) for spec in specs]
raise NoSpecError("Multiple spec files found (%s), don't know which "
"to use." % ', '.join(filenames))
- return specs[0]
+ return SpecFile(specs[0])
+
def guess_spec_repo(repo, branch, packaging_dir):
"""
options.packaging_dir = os.path.dirname(specfile)
if not os.path.exists(specfile):
raise rpm.NoSpecError("Failed to export specfile: %s" % options.spec_file)
+ spec = rpm.SpecFile(specfile)
else:
- specfile = rpm.guess_spec(os.path.join(dump_dir, options.packaging_dir),
- True,
- os.path.basename(repo.path) + '.spec')
- spec = rpm.SpecFile(specfile)
- gbp.log.debug("Using spec file '%s'" % specfile)
+ spec = rpm.guess_spec(os.path.join(dump_dir, options.packaging_dir),
+ True,
+ os.path.basename(repo.path) + '.spec')
+ gbp.log.debug("Using spec file '%s'" % spec.specfile)
if not options.tag_only:
# Setup builder opts
import gbp.command_wrappers as gbpc
import string
from gbp.pkg import parse_archive_filename
-from gbp.rpm import (RpmUpstreamSource, SpecFile, NoSpecError, parse_spec,
- guess_spec, guess_spec_repo)
+from gbp.rpm import (RpmUpstreamSource, SpecFile, NoSpecError, guess_spec,
+ guess_spec_repo)
from gbp.rpm.policy import RpmPkgPolicy
from gbp.rpm.git import (GitRepositoryError, RpmGitRepository)
from gbp.config import GbpOptionParserRpm, GbpOptionGroup, no_upstream_branch_msg
# Try to find the source package name
try:
- spec = parse_spec(guess_spec(os.path.join(repo.path, options.packaging_dir),
- True,
- os.path.basename(repo.path) + '.spec'))
+ preferred_fn = os.path.basename(repo.path) + '.spec'
+ spec = guess_spec(os.path.join(repo.path, options.packaging_dir), True,
+ preferred_fn)
sourcepackage = spec.name
except NoSpecError:
try:
# Check the spec file from the repository, in case
# we're not on the packaging-branch (but upstream, for
# example).
- specfile = guess_spec_repo(repo, options.packaging_branch, options.packaging_dir)
- spec = SpecFile(specfile)
+ spec = guess_spec_repo(repo, options.packaging_branch,
+ options.packaging_dir)
sourcepackage = spec.name
except NoSpecError:
if options.interactive:
import gbp.tmpfile as tempfile
import gbp.command_wrappers as gbpc
-from gbp.rpm import (parse_srpm, guess_spec, NoSpecError, parse_spec,
- RpmUpstreamSource)
+from gbp.rpm import (parse_srpm, guess_spec, SpecFile, NoSpecError,
+ RpmUpstreamSource)
from gbp.rpm.policy import RpmPkgPolicy
from gbp.rpm.git import (RpmGitRepository, GitRepositoryError)
from gbp.git.modifier import GitModifier
if os.path.isdir(srpm):
gbp.log.debug("Trying to import an unpacked srpm from '%s'" % srpm)
dirs['src'] = os.path.abspath(srpm)
- spec = parse_spec(guess_spec(srpm, True, preferred_spec))
+ spec = guess_spec(srpm, True, preferred_spec)
else:
gbp.log.debug("Trying to import an srpm from '%s' with spec "\
"file '%s'" % (os.path.dirname(srpm), srpm))
dirs['src'] = os.path.abspath(os.path.dirname(srpm))
- spec = parse_spec(srpm)
+ spec = SpecFile(srpm)
# Check the repository state
try:
# (only for non-native packages with non-orphan packaging)
force_to_branch_head(repo, options.packaging_branch)
if options.patch_import:
- spec = parse_spec(os.path.join(repo.path,
- options.packaging_dir,
- spec.specfile))
+ spec = SpecFile(os.path.join(repo.path,
+ options.packaging_dir, spec.specfile))
import_spec_patches(repo, spec, dirs)
commit = options.packaging_branch
# Find and parse .spec file
try:
if options.spec_file != 'auto':
- specfilename = options.spec_file
options.packaging_dir = os.path.dirname(specfilename)
+ spec = SpecFile(options.packaging_dir)
else:
- specfilename = guess_spec(options.packaging_dir,
- True,
- os.path.basename(repo.path) + '.spec')
- spec = SpecFile(specfilename)
+ spec = guess_spec(options.packaging_dir, True,
+ os.path.basename(repo.path) + '.spec')
except KeyError:
raise GbpError, "Can't parse spec"
# Find and parse .spec file
try:
if options.spec_file != 'auto':
- specfilename = options.spec_file
- options.packaging_dir = os.path.dirname(specfilename)
+ options.packaging_dir = os.path.dirname(options.spec_file)
+ spec = SpecFile(options.spec_file)
else:
- specfilename = guess_spec(options.packaging_dir,
- True,
- os.path.basename(repo.path) + '.spec')
- spec = SpecFile(specfilename)
+ spec = guess_spec(options.packaging_dir, True,
+ os.path.basename(repo.path) + '.spec')
except KeyError:
raise GbpError, "Can't parse spec"
# Find and parse .spec file
try:
if options.spec_file != 'auto':
- specfilename = options.spec_file
- options.packaging_dir = os.path.dirname(specfilename)
+ options.packaging_dir = os.path.dirname(options.spec_file)
+ spec = SpecFile(options.spec_file)
else:
- specfilename = guess_spec(options.packaging_dir,
- True,
- os.path.basename(repo.path) + '.spec')
- spec = SpecFile(specfilename)
+ spec = guess_spec(options.packaging_dir, True,
+ os.path.basename(repo.path) + '.spec')
except KeyError:
raise GbpError, "Can't parse spec"
from nose.tools import assert_raises
from gbp.errors import GbpError
-from gbp.rpm import (SrcRpmFile, SpecFile, parse_srpm, parse_spec, guess_spec,
- NoSpecError)
+from gbp.rpm import SrcRpmFile, SpecFile, parse_srpm, guess_spec, NoSpecError
DATA_DIR = os.path.abspath(os.path.splitext(__file__)[0] + '_data')
SRPM_DIR = os.path.join(DATA_DIR, 'srpms')
class TestUtilityFunctions(object):
"""Test utility functions of L{gbp.rpm}"""
- def test_parse_spec(self):
- """Test parse_spec() function"""
- parse_spec(os.path.join(SPEC_DIR, 'gbp-test.spec'))
- with assert_raises(NoSpecError):
- parse_spec(os.path.join(DATA_DIR, 'notexists.spec'))
- with assert_raises(GbpError):
- parse_spec(os.path.join(SRPM_DIR, 'gbp-test-1.0-1.src.rpm'))
-
def test_parse_srpm(self):
"""Test parse_srpm() function"""
parse_srpm(os.path.join(SRPM_DIR, 'gbp-test-1.0-1.src.rpm'))
with assert_raises(NoSpecError):
guess_spec(SPEC_DIR, recursive=False)
# Spec found
- spec_fn = guess_spec(SPEC_DIR, recursive=False,
+ spec = guess_spec(SPEC_DIR, recursive=False,
preferred_name = 'gbp-test2.spec')
- assert spec_fn == os.path.join(SPEC_DIR, 'gbp-test2.spec')
+ assert spec.specfile == 'gbp-test2.spec'
+ assert spec.specdir == SPEC_DIR
# vim:et:ts=4:sw=4:et:sts=4:ai:set list listchars=tab\:»·,trail\:·: