Ejemplo n.º 1
0
def add_autobuild_changelog_entry(base_branch,
                                  basedir,
                                  package,
                                  distribution=None,
                                  author_name=None,
                                  author_email=None,
                                  append_version=None):
    """Add a new changelog entry for an autobuild.

    :param base_branch: Recipe base branch
    :param basedir: Base working directory
    :param package: package name
    :param distribution: Optional distribution (defaults to last entry
        distribution)
    :param author_name: Name of the build requester
    :param author_email: Email of the build requester
    :param append_version: Optional version suffix to add
    """
    debian_dir = os.path.join(basedir, "debian")
    if not os.path.exists(debian_dir):
        os.makedirs(debian_dir)
    cl_path = os.path.join(debian_dir, "changelog")
    file_found = False
    if os.path.exists(cl_path):
        file_found = True
        cl_f = open(cl_path)
        try:
            contents = cl_f.read()
        finally:
            cl_f.close()
        cl = changelog.Changelog(file=contents)
    else:
        cl = changelog.Changelog()
    if len(cl._blocks) > 0:
        if distribution is None:
            distribution = cl._blocks[0].distributions.split()[0]
    else:
        if file_found:
            if len(contents.strip()) > 0:
                reason = ("debian/changelog didn't contain any "
                          "parseable stanzas")
            else:
                reason = "debian/changelog was empty"
        else:
            reason = "debian/changelog was not present"
        if distribution is None:
            distribution = DEFAULT_UBUNTU_DISTRIBUTION
    if base_branch.format in (0.1, 0.2, 0.3):
        try:
            substitute_changelog_vars(base_branch, None, cl)
        except SubstitutionUnavailable, e:
            raise errors.BzrCommandError(
                "No previous changelog to "
                "take the upstream version from as %s was "
                "used: %s: %s." % (e.name, e.reason, reason))
Ejemplo n.º 2
0
 def test_str_consistent(self):
     # The parsing of the changelog (including the string representation)
     # should be consistent whether we give a single string, a list of
     # lines, or a file object to the Changelog initializer
     f = open('test_changelog')
     cl_data = f.read()
     f.seek(0)
     c1 = changelog.Changelog(f)
     f.close()
     c2 = changelog.Changelog(cl_data)
     c3 = changelog.Changelog(cl_data.splitlines())
     for c in (c1, c2, c3):
         self.assertEqual(str(c), cl_data)
Ejemplo n.º 3
0
 def test_set_version_with_string(self):
     f = open('test_modify_changelog1')
     c1 = changelog.Changelog(f.read())
     f.seek(0)
     c2 = changelog.Changelog(f.read())
     f.close()
     c1.version = '1:2.3.5-2'
     c2.version = changelog.Version('1:2.3.5-2')
     self.assertEqual(c1.version, c2.version)
     self.assertEqual((c1.full_version, c1.epoch, c1.upstream_version,
                       c1.debian_version),
                      (c2.full_version, c2.epoch, c2.upstream_version,
                       c2.debian_version))
Ejemplo n.º 4
0
    def test_changelog_no_author(self):
        cl_no_author = """gnutls13 (1:1.4.1-1) unstable; urgency=low

  * New upstream release.

 --
"""
        c1 = changelog.Changelog()
        c1.parse_changelog(cl_no_author, allow_empty_author=True)
        self.assertEqual(c1.author, None)
        self.assertEqual(c1.date, None)
        self.assertEqual(c1.package, "gnutls13")
        c2 = changelog.Changelog()
        self.assertRaises(changelog.ChangelogParseError, c2.parse_changelog,
                          cl_no_author)
Ejemplo n.º 5
0
def substitute_branch_vars(base_branch, branch_name, branch, revid):
    """Substitute the branch variables for the given branch name in deb_version.

    Where deb_version has a place to substitute the revno for a branch
    this will substitute it for the given branch name.

    :param branch_name: the name of the RecipeBranch to substitute.
    :param branch: Branch object for the branch
    :param revid: Revision id in the branch for which to return the revno
    """
    if base_branch.deb_version is None:
        return
    revno_var = RevnoVariable(branch_name, branch, revid)
    base_branch.deb_version = revno_var.replace(base_branch.deb_version)
    if base_branch.format < 0.4:
        # The other variables were introduced in recipe format 0.4
        return
    svn_revno_var = SubversionRevnumVariable(branch_name, branch, revid)
    base_branch.deb_version = svn_revno_var.replace(base_branch.deb_version)
    git_commit_var = GitCommitVariable(branch_name, branch, revid)
    base_branch.deb_version = git_commit_var.replace(base_branch.deb_version)
    latest_tag_var = LatestTagVariable(branch_name, branch, revid)
    base_branch.deb_version = latest_tag_var.replace(base_branch.deb_version)
    revdate_var = RevdateVariable(branch_name, branch, revid)
    base_branch.deb_version = revdate_var.replace(base_branch.deb_version)
    revtime_var = RevtimeVariable(branch_name, branch, revid)
    base_branch.deb_version = revtime_var.replace(base_branch.deb_version)
    tree = branch.repository.revision_tree(revid)
    if tree.has_filename('debian/changelog'):
        with tree.lock_read():
            cl = changelog.Changelog(tree.get_file_text('debian/changelog'))
            substitute_changelog_vars(base_branch, branch_name, cl)
Ejemplo n.º 6
0
 def test_allow_full_stops_in_distribution(self):
     f = open('test_changelog_full_stops')
     c = changelog.Changelog(f)
     f.close()
     self.assertEqual(c.debian_version, None)
     self.assertEqual(c.full_version, '1.2.3')
     self.assertEqual(str(c.version), c.full_version)
Ejemplo n.º 7
0
    def test_add_changelog_section(self):
        f = open('test_modify_changelog2')
        c = f.read()
        f.close()
        cl = changelog.Changelog(c)
        cl.new_block(package='gnutls14',
                     version=changelog.Version('1:1.4.1-3'),
                     distributions='experimental',
                     urgency='low',
                     author='James Westby <*****@*****.**>')

        self.assertRaises(changelog.ChangelogCreateError, cl.__str__)

        cl.set_date('Sat, 16 Jul 2008 11:11:08 +0200')
        cl.add_change('')
        cl.add_change('  * Foo did not work, let us try bar')
        cl.add_change('')

        f = open('test_modify_changelog3')
        c = f.read()
        f.close()
        clines = c.split('\n')
        cslines = str(cl).split('\n')
        for i in range(len(clines)):
            self.assertEqual(clines[i], cslines[i])
        self.assertEqual(len(clines), len(cslines), "Different lengths")
Ejemplo n.º 8
0
 def test_unicode_object_input(self):
     f = open('test_changelog_unicode', 'rb')
     c_bytes = f.read()
     f.close()
     c_unicode = c_bytes.decode('utf-8')
     c = changelog.Changelog(c_unicode)
     self.assertEqual(six.text_type(c), c_unicode)
     self.assertEqual(bytes(c), c_bytes)
Ejemplo n.º 9
0
    def write_changelog(self, version):
        contents = textwrap.dedent("""
            package (%s) experimental; urgency=low

              * Initial release. (Closes: #XXXXXX)

             -- Jelmer Vernooij <*****@*****.**>  Thu, 19 May 2011 10:07:41 +0100
            """ % version)[1:]
        return changelog.Changelog(file=contents)
Ejemplo n.º 10
0
 def test_magic_version_properties(self):
     f = open('test_changelog')
     c = changelog.Changelog(f)
     f.close()
     self.assertEqual(c.debian_version, '1')
     self.assertEqual(c.full_version, '1:1.4.1-1')
     self.assertEqual(c.upstream_version, '1.4.1')
     self.assertEqual(c.epoch, '1')
     self.assertEqual(str(c.version), c.full_version)
Ejemplo n.º 11
0
 def test_create_changelog(self):
     f = open('test_changelog')
     c = f.read()
     f.close()
     cl = changelog.Changelog(c)
     cs = str(cl)
     clines = c.split('\n')
     cslines = cs.split('\n')
     for i in range(len(clines)):
         self.assertEqual(clines[i], cslines[i])
     self.assertEqual(len(clines), len(cslines), "Different lengths")
Ejemplo n.º 12
0
 def test_cmd_dailydeb_with_version_from_changelog(self):
     self.requireFeature(NotUnderFakeRootFeature)
     self.make_simple_package("source")
     self.build_tree_contents(
         [("test.recipe", "# bzr-builder format 0.3 "
           "deb-version {debversion}-2\nsource 1\n")])
     out, err = self.run_dailydeb(
         "test.recipe working --allow-fallback-to-native")
     cl = changelog.Changelog(
         self._get_file_contents(
             "working/test-{debversion}-2/debian/changelog"))
     self.assertEquals("0.1-1-2", str(cl._blocks[0].version))
Ejemplo n.º 13
0
 def test_non_utf8_encoding(self):
     f = open('test_changelog_unicode', 'rb')
     c_bytes = f.read()
     f.close()
     c_unicode = c_bytes.decode('utf-8')
     c_latin1_str = c_unicode.encode('latin1')
     c = changelog.Changelog(c_latin1_str, encoding='latin1')
     self.assertEqual(six.text_type(c), c_unicode)
     self.assertEqual(bytes(c), c_latin1_str)
     for block in c:
         self.assertEqual(bytes(block),
                          six.text_type(block).encode('latin1'))
Ejemplo n.º 14
0
def get_changelog_entries(tmp_dir, dsc_name):
	#print('getting changelog entries from %s', dsc_name)

	# Preparation
	extract_path = os.path.join(tmp_dir,'extracted')

	# Unpack the source tree
	#print('unpacking source package %s', dsc_name)
	cmdline = ['dpkg-source', '-x', dsc_name, 'extracted']
	process = subprocess.Popen(cmdline, cwd=tmp_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=subprocess_setup)
	output = process.communicate()[0]
	if process.returncode:
		logging.warning('dpkg-source reported failure to extract %s:', dsc_name)
		logging.warning(output)
		cmdline = ['ls', '-lR', '--time-style=+']
		process = subprocess.Popen(cmdline, cwd=tmp_dir, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, preexec_fn=subprocess_setup)
		output = process.communicate()[0]
		logging.warning(output)
		rmtree(extract_path)
		return None
	#print(os.listdir(tmp_dir))
	# Sanitise the debian dir and changelog file in case it is a symlink to outside
	debian_dir = os.path.join(extract_path, 'debian')
	changelog_filename = os.path.join(debian_dir,'changelog')
	if os.path.islink(debian_dir) or os.path.islink(changelog_filename):
		logging.warning('debian dir or changelog is a symbolic link %s', dsc_name)
		rmtree(extract_path)
		return None

	# Check if the changelog exists
	if not os.path.exists(changelog_filename):
		logging.warning('could not find changelog in %s', dsc_name)
		rmtree(extract_path)
		return None

	# Find out which source package is the most likely derivative
	#print('parsing changelog for %s', dsc_name)
	changelog_file = open(changelog_filename)
	changelog_obj = changelog.Changelog(changelog_file)
	try:
		changelog_entries = [(entry.package, str(entry._raw_version)) for entry in changelog_obj]
	except:
		logging.warning('could not read changelog from %s', dsc_name)
		rmtree(extract_path)
		return None
	del changelog_obj
	changelog_file.close()

	print('Debug: Clean up again '+extract_path);
	rmtree(extract_path)

	return changelog_entries
Ejemplo n.º 15
0
def import_one(pkgname, fh):
    try:
        c = changelog.Changelog(fh)
        date = parser.parse(c.date).strftime('%Y-%m-%d')
        df = pd.DataFrame([{
            '_srcpkg': c.package,
            'version': c.version,
            'date': date,
            'author': c.author
        }])
    except:
        return
    return (df)
Ejemplo n.º 16
0
 def test_cmd_dailydeb_with_version_from_changelog(self):
     self.requireFeature(NotUnderFakeRootFeature)
     self.make_simple_package("source")
     self.build_tree_contents([("test.recipe", "# bzr-builder format 0.3 "
                                "deb-version {debversion}-2\nsource 1\n")])
     out, err = self.run_bzr(
         "dailydeb --allow-fallback-to-native -q test.recipe working")
     new_cl_contents = (
         "package (0.1-2) unstable; urgency=low\n\n"
         "  * Auto build.\n\n -- M. Maintainer <*****@*****.**>  ")
     cl = changelog.Changelog(
         self._get_file_contents(
             "working/test-{debversion}-2/debian/changelog"))
     self.assertEquals("0.1-1-2", str(cl._blocks[0].version))
Ejemplo n.º 17
0
 def addChangelogEntryDebian(self, package, version):
     fname = "{path}/debian.changelog".format(path=self.packageDir(package))
     c = changelog.Changelog(open(fname, encoding="utf-8").read())
     if (c.upstream_version != version):
         c.new_block(
             package=package.name,
             version="{epoch}{v}-0~kolab1".format(epoch=config.epoch.get(
                 package.name, ""),
                                                  v=version),
             distributions="unstable",
             urgency="medium",
             author="{} {} <{}>".format(config.name, config.comment,
                                        config.mail),
             date=datetime.now(Local).strftime("%a, %d %b %Y %H:%M:%S %z"),
             changes=[
                 "", "  * New upstream release {v}".format(v=version), ""
             ])
         c.write_to_open_file(open(fname, "w", encoding="utf-8"))
Ejemplo n.º 18
0
    def test_utf8_encoded_file_input(self):
        f = open_utf8('test_changelog_unicode')
        c = changelog.Changelog(f)
        f.close()
        u = six.text_type(c)
        expected_u = six.u("""haskell-src-exts (1.8.2-3) unstable; urgency=low

  * control: Use versioned Replaces: and Conflicts:

 -- Marco T\xfalio Gontijo e Silva <*****@*****.**>  Wed, 05 May 2010 18:01:53 -0300

haskell-src-exts (1.8.2-2) unstable; urgency=low

  * debian/control: Rename -doc package.

 -- Marco T\xfalio Gontijo e Silva <*****@*****.**>  Tue, 16 Mar 2010 10:59:48 -0300
""")
        self.assertEqual(u, expected_u)
        self.assertEqual(bytes(c), u.encode('utf-8'))
Ejemplo n.º 19
0
 def test_cmd_dailydeb_with_version_from_other_branch_changelog(self):
     self.requireFeature(NotUnderFakeRootFeature)
     source = self.make_simple_package("source")
     other = self.make_simple_package("other")
     cl_contents = ("package (0.4-1) unstable; urgency=low\n  * foo\n"
                    " -- maint <*****@*****.**>  Tue, 04 Aug 2009 "
                    "10:03:10 +0100\n")
     self.build_tree_contents([(os.path.join("other", "debian",
                                             "changelog"), cl_contents)])
     other.commit("new changelog entry")
     self.build_tree_contents([("test.recipe", "# bzr-builder format 0.4 "
                                "deb-version {debversion:other}.2\n"
                                "source 1\n"
                                "nest other other other\n")])
     out, err = self.run_bzr(
         "dailydeb --allow-fallback-to-native -q test.recipe working")
     cl = changelog.Changelog(
         self._get_file_contents(
             "working/test-{debversion:other}.2/debian/changelog"))
     self.assertEquals("0.4-1.2", str(cl._blocks[0].version))
Ejemplo n.º 20
0
    def upgrade(self, upstream_version, msg):
        self.upstream_version = upstream_version
        version = "%s-0~kolab1" % self.upstream_version

        try:
            version = config.epoch[self.name] + version
        except KeyError:
            pass

        with cd(self.path):
            os.system('DEBEMAIL="{}" DEBFULLNAME="{} {}"  dch -v {} "{}"'.format(
                config.mail, config.name, config.comment, version, msg).encode("utf-8")
                )
            os.system('DEBEMAIL="{}" DEBFULLNAME="{} {}"  dch -r ""'.format(
                config.mail, config.name, config.comment).encode("utf-8")
                )
            c = changelog.Changelog(open("debian/changelog", encoding="utf-8").read())
            self.version = c.version
            self.upstream_version = c.upstream_version
            self.base_version = re.search("^([0-9\.]+:)?(?P<version>[0-9\.]+)(\+|~|$)", c.upstream_version).group("version")
Ejemplo n.º 21
0
 def test_modify_changelog(self):
     f = open('test_modify_changelog1')
     c = f.read()
     f.close()
     cl = changelog.Changelog(c)
     cl.package = 'gnutls14'
     cl.version = '1:1.4.1-2'
     cl.distributions = 'experimental'
     cl.urgency = 'medium'
     cl.add_change('  * Add magic foo')
     cl.author = 'James Westby <*****@*****.**>'
     cl.date = 'Sat, 16 Jul 2008 11:11:08 -0200'
     f = open('test_modify_changelog2')
     c = f.read()
     f.close()
     clines = c.split('\n')
     cslines = str(cl).split('\n')
     for i in range(len(clines)):
         self.assertEqual(clines[i], cslines[i])
     self.assertEqual(len(clines), len(cslines), "Different lengths")
Ejemplo n.º 22
0
    def test_create_changelog_single_block(self):
        f = open('test_changelog')
        c = f.read()
        f.close()
        cl = changelog.Changelog(c, max_blocks=1)
        cs = str(cl)
        self.assertEqual(
            cs, """gnutls13 (1:1.4.1-1) unstable; urgency=HIGH

  [ James Westby ]
  * New upstream release.
  * Remove the following patches as they are now included upstream:
    - 10_certtoolmanpage.diff
    - 15_fixcompilewarning.diff
    - 30_man_hyphen_*.patch
  * Link the API reference in /usr/share/gtk-doc/html as gnutls rather than
    gnutls-api so that devhelp can find it.

 -- Andreas Metzler <*****@*****.**>  Sat, 15 Jul 2006 11:11:08 +0200

""")
Ejemplo n.º 23
0
from debian import changelog

from setuptools import find_packages, setup


__version__ = str(changelog.Changelog(open('debian/changelog')).version)
__desc__ = 'Orchestrator next-gen prototype'


setup(
    name='cocaine-orca',
    version=__version__,
    packages=find_packages('src'),
    url='https://github.com/karitra/burlak',
    license='Copyleft',
    author='Alex Karev',
    author_email='*****@*****.**',
    install_requires=[
        # 'cocaine',
        'tornado>=4.3,<5.0',
        'click>=5.0',
        'PyYAML>=3.0',
        'cerberus>=0.9.0',
        'raven>=5.0.0',
        'six',
    ],
    namespace_packages=['cocaine'],
    setup_requires=[
        'pytest-runner',
        'python-debian',
        'setuptools_scm<=1.17'],
Ejemplo n.º 24
0
 def test_block_iterator(self):
     f = open('test_changelog')
     c = changelog.Changelog(f)
     f.close()
     self.assertEqual([str(b) for b in c._blocks], [str(b) for b in c])
Ejemplo n.º 25
0
 def debianUpstreamVersion(self, package):
     fname = "{path}/debian.changelog".format(path=self.packageDir(package))
     c = changelog.Changelog(open(fname, encoding="utf-8").read())
     return c.upstream_version
Ejemplo n.º 26
0
 def test_empty_changelog(self):
     var = DebVersionVariable.from_changelog(None, changelog.Changelog())
     self.assertRaises(SubstitutionUnavailable, var.get)
Ejemplo n.º 27
0
 def test_len(self):
     f = open('test_changelog')
     c = changelog.Changelog(f)
     f.close()
     self.assertEqual(len(c._blocks), len(c))
Ejemplo n.º 28
0
def debianPackage(name):
    base = os.path.join(config.debianBase, name)
    c = changelog.Changelog(open(os.path.join(base,'debian/changelog'), encoding="utf-8").read())
    return DebianPackage(base, c)
Ejemplo n.º 29
0
def generate_debian_package(args, buildconfig):
    global APT_CACHE

    project_name = args.project_name

    chglog = changelog.Changelog(open("debian/changelog"))
    old_chglog = changelog.Changelog(open("debian/changelog"))

    print("[buildpkg::generate_debian_package] ({})"
          " Run 'lsb_release'".format(project_name))
    try:
        dist = subprocess.check_output(["lsb_release", "-sc"]).strip()
    except subprocess.CalledProcessError:
        print("[buildpkg::generate_debian_package] ({})"
              " ERROR: Running 'lsb_release'".format(project_name))
        exit(1)
    else:
        print("[buildpkg::generate_debian_package] ({})"
              " Found distro code: {}".format(project_name, dist))

    print("[buildpkg::generate_debian_package] ({})"
          " Retrieve version from the project's metadata".format(project_name))
    new_version = get_debian_version(args.simplify_dev_version, dist)
    if new_version is None:
        print("[buildpkg::generate_debian_package] ({}) ERROR:"
              " No valid version in the project's metada".format(project_name))
        exit(1)

    chglog.new_block(version=new_version,
                     package=chglog.package,
                     distributions="testing",
                     changes=["\n  Generating new package version\n"],
                     author=chglog.author,
                     date=strftime("%a, %d %b %Y %H:%M:%S %z"),
                     urgency=chglog.urgency)

    chglog.write_to_open_file(open("debian/changelog", 'w'))

    # Execute commands defined in the build configuration file
    if buildconfig.has_key("prebuild-command"):
        print("[buildpkg::generate_debian_package] ({})"
              " Run prebuild-command: '{}'".format(
                  project_name, str(buildconfig["prebuild-command"])))
        try:
            subprocess.check_call(buildconfig["prebuild-command"], shell=True)
        except subprocess.CalledProcessError:
            print("[buildpkg::generate_debian_package] ({}) ERROR:"
                  " Running prebuild-command".format(project_name))
            exit(1)

    cpu_count = multiprocessing.cpu_count()

    print("[buildpkg::generate_debian_package] ({})"
          " Run 'dpkg-buildpackage', jobs: {}".format(project_name, cpu_count))
    try:
        subprocess.check_call(
            ["dpkg-buildpackage", "-uc", "-us", "-j" + str(cpu_count)])
    except subprocess.CalledProcessError:
        print("[buildpkg::generate_debian_package] ({}) ERROR:"
              " Running 'dpkg-buildpackage'".format(project_name))
        exit(1)

    paths_glob = "../*" + new_version + "_*.deb"
    file_paths = glob.glob(paths_glob)

    # Install the generated files (plus their installation dependencies)
    # FIXME: The Apt Python API (apt.debfile.DebPackage) doesn't have a
    # reliable method to do this.
    # Also there is the `gdebi` command, but it doesn't accept multiple files.
    print("[buildpkg::generate_debian_package] ({})"
          " Run 'dpkg -i' with generated files: {}".format(
              project_name, file_paths))
    if file_paths:
        root_privileges_gain()
        try:
            subprocess.check_call("dpkg -i " + paths_glob, shell=True)
        except subprocess.CalledProcessError:
            print("[buildpkg::generate_debian_package] ({})"
                  " 'dpkg -i' left unconfigured packages; try to solve that".
                  format(project_name))
            if subprocess.call(["apt-get", "install", "-f", "-y", "-q"]) != 0:
                print("[buildpkg::generate_debian_package] ({}) ERROR:"
                      " Running 'apt-get install -f'".format(project_name))
                exit(1)
        APT_CACHE.open()
        root_privileges_drop()

    if args.command == "upload":
        for file_path in file_paths:
            is_last = bool(file_path is file_paths[-1])

            if new_version.find("~") == -1 or args.force_release:
                upload_package(args,
                               buildconfig,
                               dist,
                               file_path,
                               publish=is_last)
            elif args.force_testing:
                upload_package(args,
                               buildconfig,
                               dist + "-test",
                               file_path,
                               publish=is_last)

            upload_package(args,
                           buildconfig,
                           dist + "-dev",
                           file_path,
                           publish=is_last)

    if args.clean:
        file_paths = glob.glob("../*" + new_version + "*")
        for file_path in file_paths:
            os.remove(file_path)

    # Write old changelog to let everything as it was
    old_chglog.write_to_open_file(open("debian/changelog", 'w'))
Ejemplo n.º 30
0
# General information about the project.
project = u'Autopilot'
copyright = u'2012-2014, Canonical'

# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
version = '1.5'

# The full version, including alpha/beta/rc tags.
try:
    from debian import changelog
    chl = changelog.Changelog(open('../debian/changelog'))
    release = str(chl.version).split('ubuntu')[0]
except ImportError:
    # If we don't have python-debian installed, guess a coarse-grained version
    # string
    release = version

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
# language = None

# There are two options for replacing |today|: either, you set today to some
# non-false value, then it is used:
# today = ''
# Else, today_fmt is used as the format for a strftime call.
# today_fmt = '%B %d, %Y'