Esempio n. 1
0
    def test_guess_spec_repo(self):
        """Test guess_spec_repo() and spec_from_repo() functions"""
        # Create dummy repository with some commits
        repo = GitRepository.create(self.tmpdir)
        with open(os.path.join(repo.path, 'foo.txt'), 'w') as fobj:
            fobj.write('bar\n')
        repo.add_files('foo.txt')
        repo.commit_all('Add dummy file')
        os.mkdir(os.path.join(repo.path, 'packaging'))
        shutil.copy(os.path.join(SPEC_DIR, 'gbp-test.spec'),
                    os.path.join(repo.path, 'packaging'))
        repo.add_files('packaging/gbp-test.spec')
        repo.commit_all('Add spec file')

        # Spec not found
        with assert_raises(NoSpecError):
            guess_spec_repo(repo, 'HEAD~1', recursive=True)
        with assert_raises(NoSpecError):
            guess_spec_repo(repo, 'HEAD', recursive=False)
        # Spec found
        spec = guess_spec_repo(repo, 'HEAD', 'packaging', recursive=False)
        spec = guess_spec_repo(repo, 'HEAD', recursive=True)
        eq_(spec.specfile, 'gbp-test.spec')
        eq_(spec.specdir, 'packaging')
        eq_(spec.specpath, 'packaging/gbp-test.spec')

        # Test spec_from_repo()
        with assert_raises(NoSpecError):
            spec_from_repo(repo, 'HEAD~1', 'packaging/gbp-test.spec')
        spec = spec_from_repo(repo, 'HEAD', 'packaging/gbp-test.spec')
        eq_(spec.specfile, 'gbp-test.spec')
    def test_guess_spec_repo(self):
        """Test guess_spec_repo() and spec_from_repo() functions"""
        # Create dummy repository with some commits
        repo = GitRepository.create(self.tmpdir)
        with open(os.path.join(repo.path, 'foo.txt'), 'w') as fobj:
            fobj.write('bar\n')
        repo.add_files('foo.txt')
        repo.commit_all('Add dummy file')
        os.mkdir(os.path.join(repo.path, 'packaging'))
        shutil.copy(os.path.join(SPEC_DIR, 'gbp-test.spec'),
                    os.path.join(repo.path, 'packaging'))
        repo.add_files('packaging/gbp-test.spec')
        repo.commit_all('Add spec file')

        # Spec not found
        with assert_raises(NoSpecError):
            guess_spec_repo(repo, 'HEAD~1', recursive=True)
        with assert_raises(NoSpecError):
            guess_spec_repo(repo, 'HEAD', recursive=False)
        # Spec found
        spec = guess_spec_repo(repo, 'HEAD', 'packaging', recursive=False)
        spec = guess_spec_repo(repo, 'HEAD', recursive=True)
        eq_(spec.specfile, 'gbp-test.spec')
        eq_(spec.specdir, 'packaging')
        eq_(spec.specpath, 'packaging/gbp-test.spec')

        # Test spec_from_repo()
        with assert_raises(NoSpecError):
            spec_from_repo(repo, 'HEAD~1', 'packaging/gbp-test.spec')
        spec = spec_from_repo(repo, 'HEAD', 'packaging/gbp-test.spec')
        eq_(spec.specfile, 'gbp-test.spec')
    def test_guess_spec_repo(self):
        """Test guess_spec_repo() and spec_from_repo() functions"""
        # Create dummy repository with some commits
        repo = GitRepository.create(self.tmpdir)
        with open(os.path.join(repo.path, "foo.txt"), "w") as fobj:
            fobj.write("bar\n")
        repo.add_files("foo.txt")
        repo.commit_all("Add dummy file")
        os.mkdir(os.path.join(repo.path, "packaging"))
        shutil.copy(os.path.join(SPEC_DIR, "gbp-test.spec"), os.path.join(repo.path, "packaging"))
        repo.add_files("packaging/gbp-test.spec")
        repo.commit_all("Add spec file")

        # Spec not found
        with assert_raises(NoSpecError):
            guess_spec_repo(repo, "HEAD~1", recursive=True)
        with assert_raises(NoSpecError):
            guess_spec_repo(repo, "HEAD", recursive=False)
        # Spec found
        spec = guess_spec_repo(repo, "HEAD", "packaging", recursive=False)
        spec = guess_spec_repo(repo, "HEAD", recursive=True)
        eq_(spec.specfile, "gbp-test.spec")
        eq_(spec.specdir, "packaging")
        eq_(spec.specpath, "packaging/gbp-test.spec")

        # Test spec_from_repo()
        with assert_raises(NoSpecError):
            spec_from_repo(repo, "HEAD~1", "packaging/gbp-test.spec")
        spec = spec_from_repo(repo, "HEAD", "packaging/gbp-test.spec")
        eq_(spec.specfile, "gbp-test.spec")
Esempio n. 4
0
def parse_spec(options, repo, treeish=None):
    """
    Find and parse spec file.

    If treeish is given, try to find the spec file from that. Otherwise, search
    for the spec file in the working copy.
    """
    try:
        if options.spec_file:
            if not treeish:
                spec = SpecFile(options.spec_file)
            else:
                spec = spec_from_repo(repo, treeish, options.spec_file)
        else:
            preferred_name = os.path.basename(repo.path) + '.spec'
            if not treeish:
                spec = guess_spec(options.packaging_dir, True, preferred_name)
            else:
                spec = guess_spec_repo(repo, treeish, options.packaging_dir,
                                       True, preferred_name)
    except NoSpecError as err:
        raise GbpError("Can't parse spec: %s" % err)
    relpath = spec.specpath if treeish else os.path.relpath(
        spec.specpath, repo.path)
    options.packaging_dir = os.path.dirname(relpath)
    gbp.log.debug("Using '%s' from '%s'" %
                  (relpath, treeish or 'working copy'))
    return spec
Esempio n. 5
0
def parse_spec(options, repo, treeish=None):
    """
    Find and parse spec file.

    If treeish is given, try to find the spec file from that. Otherwise, search
    for the spec file in the working copy.
    """
    try:
        if options.spec_file:
            options.packaging_dir = os.path.dirname(options.spec_file)
            if not treeish:
                spec = SpecFile(options.spec_file)
            else:
                spec = spec_from_repo(repo, treeish, options.spec_file)
        else:
            preferred_name = os.path.basename(repo.path) + '.spec'
            if not treeish:
                spec = guess_spec(options.packaging_dir, True, preferred_name)
            else:
                spec = guess_spec_repo(repo, treeish, options.packaging_dir,
                                       True, preferred_name)
    except NoSpecError as err:
        raise GbpError("Can't parse spec: %s" % err)
    relpath = spec.specpath if treeish else os.path.relpath(spec.specpath,
                                                            repo.path)
    gbp.log.debug("Using '%s' from '%s'" % (relpath, treeish or 'working copy'))
    return spec