Exemple #1
0
def sru_tracking_bug(repo, sru):
    with ExitStack() as resources:
        debian_changelog = os.path.join(
            repo.working_dir, 'debian', 'changelog')
        infp = resources.enter_context(
            open(debian_changelog, 'r', encoding='utf-8'))
        outfp = resources.enter_context(atomic(debian_changelog))
        changelog = Changelog(infp)
        changelog.add_change('  * SRU tracking number LP: #{}'.format(sru))
        changelog.write_to_open_file(outfp)
 def _create_changelog(self, temp_dir, *args, **kwargs):
     changelog = Changelog()
     changelog.new_block()
     changelog.set_version(self.version)
     changelog.set_package(self.package)
     changelog.set_distributions('all')
     changelog.set_urgency('low')
     changelog.set_author(self.maintainer)
     changelog.set_date(_format_debian_date(self.date))
     changelog.add_change('  * Release of %s' % self.version)
     return changelog
Exemple #3
0
 def generate_changelog_file(self):
     changes = Changelog()
     for version, scheduled_at, change, distribution in \
             self.db.changelog_entries(self.build.id):
         changes.new_block(
             package=self.deb_name,
             version=version,
             distributions=distribution,
             urgency='low',
             author=config.maintainer,
             date=scheduled_at.strftime('%a, %d %b %Y %H:%M:%S %z'))
         changes.add_change('\n  * ' + change + '\n')
     with open(self.debian_file('changelog'), 'w') as f:
         changes.write_to_open_file(f)
Exemple #4
0
def changelog(dpath, ctx, env):
    change = ctx.get('message', 'Autogenerated by py2dsp v{}'.format(VERSION))
    version = ctx['debian_version']
    distribution = ctx.get('distribution', 'UNRELEASED')

    fpath = join(dpath, 'debian', 'changelog')
    if exists(fpath):
        with open(fpath, encoding='utf-8') as fp:
            line = fp.readline()
            if ctx['version'] in line or 'UNRELEASED' in line:
                log.debug('changelog doesn\'t need an update')
                return
            else:
                yield from execute([
                    'dch', '--force-distribution', '--distribution',
                    distribution, '--newversion', version, '-m', change
                ],
                                   cwd=dpath)
        return

    now = datetime.utcnow()
    changelog = Changelog()
    changelog.new_block(package=ctx['src_name'],
                        version=Version(version),
                        distributions=distribution,
                        urgency='low',
                        author=ctx['creator'],
                        date=now.strftime('%a, %d %b %Y %H:%M:%S +0000'))
    changelog.add_change('')
    changelog.add_change('  * {}'.format(change))
    changelog.add_change('')

    with open(fpath, 'w', encoding='utf-8') as fp:
        changelog.write_to_open_file(fp)
    return True
Exemple #5
0
def changelog(dpath, ctx, env):
    change = ctx.get('message', 'Autogenerated by py2dsp v{}'.format(VERSION))
    version = "{}-{}".format(ctx['version'], ctx['debian_revision'])
    distribution = ctx.get('distribution', 'UNRELEASED')

    fpath = join(dpath, 'debian', 'changelog')
    if exists(fpath):
        with open(fpath, encoding='utf-8') as fp:
            line = fp.readline()
            if ctx['version'] in line or 'UNRELEASED' in line:
                log.debug('changelog doesn\'t need an update')
                return
            else:
                yield from execute(['dch', '--force-distribution', '--distribution', distribution,
                                    '--newversion', version, '-m', change], cwd=dpath)
        return

    now = datetime.utcnow()
    changelog = Changelog()
    changelog.new_block(package=ctx['src_name'],
                        version=Version(version),
                        distributions=distribution,
                        urgency='low',
                        author=ctx['creator'],
                        date=now.strftime('%a, %d %b %Y %H:%M:%S +0000'))
    changelog.add_change('')
    changelog.add_change('  * {}'.format(change))
    changelog.add_change('')

    with open(fpath, 'w', encoding='utf-8') as fp:
        changelog.write_to_open_file(fp)
    return True
 def test_mark_uploaded_unkown_dist(self):
     self.make_unuploaded()
     cl = Changelog()
     v = Version("0.1-1")
     cl.new_block(
         package='package',
         version=Version('0.1-1'),
         distributions='UNRELEASED',
         urgency='low',
         author='James Westby <*****@*****.**>',
         date='Thu,  3 Aug 2006 19:16:22 +0100',
     )
     cl.add_change('')
     cl.add_change('  * Initial packaging.')
     cl.add_change('')
     f = open('debian/changelog', 'wb')
     try:
         cl.write_to_open_file(f)
     finally:
         f.close()
     self.wt.commit("two")
     self.run_bzr_error([
         "The changelog still targets 'UNRELEASED', so "
         "apparently hasn't been uploaded."
     ], "mark-uploaded")
Exemple #7
0
 def generate_changelog_file(self):
     changelog = self.debian_file('changelog')
     if os.path.isfile(changelog):
         changes = Changelog(file=open(changelog, 'r'))
         deb_version = changes.get_version()
         deb_version.debian_revision = str(
             int(deb_version.debian_revision) + 1)
         change = 'Rebuild with newer debler'
     else:
         changes = Changelog()
         deb_version = '.'.join([str(v) for v in self.app.version]) + '-1'
         change = 'Build with debler'
     changes.new_block(
         package=self.deb_name,
         version=deb_version,
         distributions=config.distribution,
         urgency='low',
         author=config.maintainer,
         date=datetime.now(
             tz=tzlocal()).strftime('%a, %d %b %Y %H:%M:%S %z'))
     self.deb_version = deb_version
     changes.add_change('\n  * ' + change + '\n')
     with open(changelog, 'w') as f:
         changes.write_to_open_file(f)
Exemple #8
0
    def generate(self, opts, changes):
        from debian.changelog import Changelog, Version
        changelog = Changelog()

        for change in changes:
            data = change

            changelog.new_block(
                package=data['package-name'],
                version=data['ref'],
                distributions=data['distributions'],
                urgency=data['urgency'],
                author=data['author-name'] + " <" + data['author-email'] + ">",
                date=data['date'],
            )
            changelog.add_change('')
            changelog.add_change('  * ' + data['message'])
            f = open(opts[1][1], 'w')
            try:
                changelog.write_to_open_file(f)
                print("wrote to file: " + opts[1][1])
            finally:
                f.close()
        sys.exit(0)
Exemple #9
0
 def make_changelog(self, version=None):
     if version is None:
         version = self.package_version
     c = Changelog()
     c.new_block()
     c.version = Version(version)
     c.package = self.package_name
     c.distributions = 'unstable'
     c.urgency = 'low'
     c.author = 'James Westby <*****@*****.**>'
     c.date = 'The,  3 Aug 2006 19:16:22 +0100'
     c.add_change('')
     c.add_change('  *  test build')
     c.add_change('')
     return c
Exemple #10
0
 def make_unuploaded(self):
     self.wt = self.make_branch_and_tree('.')
     self.build_tree(['debian/'])
     cl = Changelog()
     v = Version("0.1-1")
     cl.new_block(package='package',
                  version=Version('0.1-1'),
                  distributions='unstable',
                  urgency='low',
                  author='James Westby <*****@*****.**>',
                  date='Thu,  3 Aug 2006 19:16:22 +0100',
                  )
     cl.add_change('');
     cl.add_change('  * Initial packaging.');
     cl.add_change('');
     with open('debian/changelog', 'w') as f:
         cl.write_to_open_file(f)
     self.wt.add(["debian/", "debian/changelog"])
     self.wt.commit("one")
Exemple #11
0
    def generate(self, opts, git):
        from debian.changelog import Changelog, Version
        changelog = Changelog()

        for change in git.alltags:
            data = change

            changelog.new_block(
                package=data['package-name'],
                version=data['ref'],
                distributions=data['distributions'],
                urgency=data['urgency'],
                author=data['author-name'] + " <" + data['author-email'] + ">",
                date=data['date'],
            )
            changelog.add_change('')
            changelog.add_change('  * ' + data['message'])
            changelog.add_change('')
        f = open(opts[1][1], 'w')
        try:
            changelog.write_to_open_file(f)
        finally:
            f.close()
        changelog.new_block(
            package=git.headcommit['package-name'],
            version=git.latesttag[0]['ref'] + "+" + str(opts[0].buildnum) +
            '+' + str(git.headcommit['commithash']),
            distributions=git.headcommit['distributions'],
            urgency=git.headcommit['urgency'],
            author=git.headcommit['author-name'] + " <" +
            git.headcommit['author-email'] + ">",
            date=git.headcommit['date'],
        )
        changelog.add_change("\n")
        changelog.add_change('  * ' + git.headcommit['message'])
        changelog.add_change('')

        f = open(opts[1][1], 'w')
        try:
            changelog.write_to_open_file(f)
            print("wrote to file: " + opts[1][1])
        finally:
            f.close()
        sys.exit(0)
Exemple #12
0
# stdlib
from sys import stdout

# 3rd party
from debian.changelog import Changelog, Version

changelog = Changelog()

# from tagim import __version__
changelog.new_block(package='python-tagim',  # will likely need a tagim package that depends on this library
                    version=Version('0.1'),
                    distributions='unstable',
                    urgency='low',
                    author='Hobson Lane <*****@*****.**>', # name and e-mail must match your GPG key
                    date='Thu, 26 Jan 2012 08:29:40 +1100', # must be in the format of `date -R`
                    )

changelog.add_change('')
changelog.add_change('  * Welcome to tagim')
changelog.add_change('  * Features')
changelog.add_change('    - tag images with text embedded in EXIF comment field')
changelog.add_change('    - chose random image from selected folder or tree of folders and display on desktop background at prescribed intervals')
changelog.add_change('')

stdout.write(changelog)

Exemple #13
0
class SourcePackageBuilder(object):
    """An interface to ease building source packages.

    >>> builder = SourcePackageBuilder("package", Version("0.1-1"))
    >>> builder.add_upstream_file("foo")
    >>> builder.add_debian_file("debian/copyright")
    >>> builder.add_default_control()
    >>> builder.build()
    >>> builder.new_version(Version("0.2-1"))
    >>> builder.add_upstream_file("bar")
    >>> builder.remove_upstream_file("foo")
    >>> builder.build()
    >>> builder.dsc_name()
    """
    def __init__(self,
                 name,
                 version,
                 native=False,
                 version3=False,
                 multiple_upstream_tarballs=None):
        """
        :param name: Package name
        :param version: Package version
        :param native: Whether to build a native source package
        :param version3: Whether to build a version 3.0 source package
        :param multiple_upstream_tarballs: A list of each top-level directory
            within the upstream tree which is to be packed as a source format
            3.0 (quilt) additional upstream tarball
        """
        self.upstream_files = {}
        self.upstream_symlinks = {}
        self.debian_files = {}
        self.name = name
        self.native = native
        self.version3 = version3
        self.multiple_upstream_tarballs = multiple_upstream_tarballs
        if multiple_upstream_tarballs and not (version3 and not native):
            raise AssertionError("Multiple upstream tarballs are only "
                                 "possible with 3.0 (quilt) format")
        self._cl = Changelog()
        self.new_version(version)

    def add_upstream_file(self, name, content=None):
        self.add_upstream_files([(name, content)])

    def add_upstream_files(self, files):
        for new_file in files:
            self.upstream_files[new_file[0]] = new_file[1]

    def add_upstream_symlink(self, name, target):
        self.upstream_symlinks[name] = target

    def remove_upstream_file(self, filename):
        del self.upstream_files[filename]

    def add_debian_file(self, name, content=None):
        self.add_debian_files([(name, content)])

    def add_debian_files(self, files):
        for new_file in files:
            self.debian_files[new_file[0]] = new_file[1]

    def remove_debian_file(self, filename):
        del self.debian_files[filename]

    def add_default_control(self):
        text = """Source: %s\nSection: misc\n""" % self.name
        text += "Priority: optional\n"
        text += "Maintainer: Maintainer <*****@*****.**>\n"
        text += "\n"
        text += "Package: %s\n" % self.name
        text += "Architecture: all\n\n"
        self.add_debian_file("debian/control", text)

    def new_version(self, version, change_text=None):
        self._cl.new_block(package=self.name,
                           version=version,
                           distributions="unstable",
                           urgency="low",
                           author="Maint <*****@*****.**>",
                           date="Wed, 19 Mar 2008 21:27:37 +0000")
        if change_text is None:
            self._cl.add_change("  * foo")
        else:
            self._cl.add_change(change_text)

    def dsc_name(self):
        return "%s_%s.dsc" % (self.name, str(self._cl.version))

    def tar_name(self):
        if self.native:
            return "%s_%s.tar.gz" % (self.name, str(self._cl.version))
        return "%s_%s.orig.tar.gz" % (self.name,
                                      str(self._cl.version.upstream_version))

    def diff_name(self):
        assert not self.native, "Can't have a diff with a native package"
        return "%s_%s.diff.gz" % (self.name, str(self._cl.version))

    def changes_name(self):
        return "%s_%s_source.changes" % (self.name, str(self._cl.version))

    def _make_files(self, files_list, basedir):
        for (path, content) in files_list.items():
            dirname = os.path.dirname(path)
            if dirname is not None and dirname != "":
                if not os.path.exists(os.path.join(basedir, dirname)):
                    os.makedirs(os.path.join(basedir, dirname))
            f = open(os.path.join(basedir, path), 'wb')
            try:
                if content is None:
                    content = ''
                f.write(content)
            finally:
                f.close()

    def _make_symlinks(self, files_list, basedir):
        for (path, target) in files_list.items():
            dirname = os.path.dirname(path)
            if dirname is not None and dirname != "":
                if not os.path.exists(os.path.join(basedir, dirname)):
                    os.makedirs(os.path.join(basedir, dirname))
            os.symlink(target, os.path.join(basedir, path))

    def basedir(self):
        return self.name + "-" + str(self._cl.version.upstream_version)

    def write_debian_files(self, basedir):
        self._make_files(self.debian_files, basedir)
        self._make_files({"debian/changelog": str(self._cl)}, basedir)

    def _make_base(self):
        basedir = self.basedir()
        os.mkdir(basedir)
        self._make_files(self.upstream_files, basedir)
        self._make_symlinks(self.upstream_symlinks, basedir)
        return basedir

    def build(self, tar_format=None):
        if tar_format is None:
            tar_format = 'gz'
        basedir = self._make_base()
        if not self.version3:
            if not self.native:
                orig_basedir = basedir + ".orig"
                shutil.copytree(basedir, orig_basedir, symlinks=True)
                cmd = ["dpkg-source", "-sa", "-b", basedir]
                if os.path.exists(
                        "%s_%s.orig.tar.gz" %
                    (self.name, self._cl.version.upstream_version)):
                    cmd = ["dpkg-source", "-ss", "-b", basedir]
            else:
                cmd = ["dpkg-source", "-sn", "-b", basedir]
        else:
            if not self.native:
                if self.multiple_upstream_tarballs:
                    for part in self.multiple_upstream_tarballs:
                        tar_path = "%s_%s.orig-%s.tar.%s" % (
                            self.name, self._cl.version.upstream_version, part,
                            tar_format)
                        if os.path.exists(tar_path):
                            os.unlink(tar_path)
                        tar = tarfile.open(tar_path, 'w:%s' % tar_format)
                        part_basedir = os.path.join(basedir, part)
                        try:
                            tar.add(part_basedir, arcname=part)
                        finally:
                            tar.close()
                        shutil.rmtree(part_basedir)
                tar_path = "%s_%s.orig.tar.%s" % (
                    self.name, self._cl.version.upstream_version, tar_format)
                if os.path.exists(tar_path):
                    os.unlink(tar_path)
                tar = tarfile.open(tar_path, 'w:%s' % tar_format)
                try:
                    tar.add(basedir)
                finally:
                    tar.close()
                cmd = ["dpkg-source", "--format=3.0 (quilt)", "-b", basedir]
            else:
                cmd = ["dpkg-source", "--format=3.0 (native)", "-b", basedir]
        self.write_debian_files(basedir)
        proc = subprocess.Popen(cmd,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT)
        ret = proc.wait()
        assert ret == 0, "dpkg-source failed, output:\n%s" % \
                (proc.stdout.read(),)
        cmd = "dpkg-genchanges -S > ../%s" % self.changes_name()
        proc = subprocess.Popen(cmd,
                                shell=True,
                                stdout=subprocess.PIPE,
                                stderr=subprocess.STDOUT,
                                cwd=basedir)
        ret = proc.wait()
        assert ret == 0, "dpkg-genchanges failed, output:\n%s" % \
                (proc.stdout.read(),)
        shutil.rmtree(basedir)
Exemple #14
0
dist = changelog.distributions
if args.dist:
    dist = args.dist

date_now = datetime.now(tzlocal()).strftime("%a, %d %b %Y %X %z")

changelog.new_block(
    package=changelog.get_package(),
    version=Version(n_version),
    distributions=dist,
    urgency='medium',
    author='UBports auto importer <*****@*****.**>',
    date=date_now,
)

changelog.add_change('')
changelog.add_change('  * Imported to UBports')
changelog.add_change('')

f = open(changelog_file, "w")
changelog.write_to_open_file(f)
f.close()

# Remove source format since jenkins does not support it
try:
    os.remove(outdir + "/debian/source/format")
except Exception as e:
    print("no source format to remove")

# Add jenkinsfile
if not args.no_jenkinsfile: