Exemple #1
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
Exemple #2
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
 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 #4
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)
Exemple #5
0
def tree_set_changelog_version(tree: WorkingTree, build_version: Version,
                               subpath: str) -> None:
    cl_path = osutils.pathjoin(subpath, "debian/changelog")
    with tree.get_file(cl_path) as f:
        cl = Changelog(f)
    if Version(str(cl.version) + "~") > build_version:
        return
    cl.version = build_version
    with open(tree.abspath(cl_path), "w") as f:
        cl.write_to_open_file(f)
Exemple #6
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 #7
0
def munge_lp_bug_numbers(repo):
    debian_changelog = os.path.join(repo.working_dir, 'debian', 'changelog')
    with ExitStack() as resources:
        infp = resources.enter_context(
            open(debian_changelog, 'r', encoding='utf-8'))
        outfp = resources.enter_context(atomic(debian_changelog))
        changelog = Changelog(infp)
        # Iterate through every line in the top changelog block.  Because we
        # want to modify the existing LP bug numbers, and because the API
        # doesn't give us direct access to those lines, we need to pop the
        # hood, reach in, and manipulate them ourselves.
        for i, line in enumerate(changelog[0]._changes):
            munged = re.sub('LP: #([0-9]+)', 'LP:\\1', line)
            changelog[0]._changes[i] = munged
        changelog.write_to_open_file(outfp)
Exemple #8
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 #9
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 #10
0
    def manage_current_distribution(self, distrib):
        """manage debian files depending of the current distrib from options

        We copy debian_dir directory into tmp build depending of the target distribution
        in all cases, we copy the debian directory of the default version (unstable)
        If a file should not be included, touch an empty file in the overlay
        directory.

        This is specific to Logilab (debian directory is in project directory)
        """
        try:
            # don't forget the final slash!
            export(osp.join(self.config.pkg_dir, 'debian'),
                   osp.join(self.origpath, 'debian/'),
                   verbose=(self.config.verbose == 2))
        except IOError as err:
            raise LGPException(err)

        debian_dir = self.get_debian_dir(distrib)
        if debian_dir != "debian":
            self.logger.info("overriding files from '%s' directory..." %
                             debian_dir)
            # don't forget the final slash!
            export(osp.join(self.config.pkg_dir, debian_dir),
                   osp.join(self.origpath, 'debian/'),
                   verbose=self.config.verbose)

        from debian.changelog import Changelog
        debchangelog = osp.join(self.origpath, 'debian', 'changelog')
        changelog = Changelog(open(debchangelog))
        # substitute distribution string in changelog
        if distrib:
            # squeeze python-debian doesn't handle unicode well, see Debian bug#561805
            changelog.distributions = str(distrib)
        # append suffix string (or timestamp if suffix is empty) to debian revision
        if self.config.suffix is not None:
            suffix = self.config.suffix or '+%s' % int(time.time())
            self.logger.debug("suffix '%s' added to package version" % suffix)
            changelog.version = str(changelog.version) + suffix
        changelog.write_to_open_file(open(debchangelog, 'w'))

        return self.origpath
Exemple #11
0
def update_changelog(repo, series, version):
    # Update d/changelog.
    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.distributions = series
        series_version = {
            'groovy': '20.10',
            'focal': '20.04',
            'bionic': '18.04',
            'xenial': '16.04',
        }[series]
        new_version = '{}+{}ubuntu1'.format(version, series_version)
        changelog.version = new_version
        changelog.write_to_open_file(outfp)
    return new_version
Exemple #12
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 #13
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)
def generate_debian_package(args, config):
    debfile = Deb822(
        open("debian/control"),
        fields=["Build-Depends", "Build-Depends-Indep"])

    rel_str = debfile.get("Build-Depends")
    if debfile.has_key("Build-Depends-Indep"):
        rel_str = rel_str + "," + debfile.get("Build-Depends-Indep")

    relations = PkgRelation.parse_relations(rel_str)

    cache = Cache()

    # Check if all required packages are installed
    for dep in relations:
        if not check_deb_dependency_installed(cache, dep):
            # Install not found dependencies
            print("Dependency not matched: " + str(dep))
            if not install_dependency(cache, dep):
                print("Dependency cannot be installed: " + PkgRelation.str([dep
                                                                            ]))
                exit(1)

    changelog = Changelog(open("debian/changelog"))
    old_changelog = Changelog(open("debian/changelog"))

    dist = os.popen("lsb_release -c").read()
    dist = dist[dist.rfind(":") + 1::].replace("\n", "").replace(
        "\t", "").replace(" ", "")

    new_version = get_debian_version(args, dist)

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

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

    # Execute commands defined in config:
    if config.has_key("prebuild-command"):
        print("Executing prebuild-command: " + str(config["prebuild-command"]))
        if os.system(config["prebuild-command"]) != 0:
            print("Failed to execute prebuild command")
            exit(1)

    if os.system("dpkg-buildpackage -uc -us") != 0:
        print("Error generating package")
        exit(1)

    if os.system("sudo dpkg -i ../*" + new_version + "_*.deb") != 0:
        print("Packages are not installable")
        exit(1)

    files = glob.glob("../*" + new_version + "_*.deb")
    if args.command == "upload":
        for f in files:
            if f is files[-1]:
                is_last = True
            else:
                is_last = False
            if new_version.find("~") == -1:
                upload_package(args, config, dist, f)
            upload_package(args, config, dist + "-dev", f, publish=is_last)

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

    # Write old changelog to let everything as it was
    old_changelog.write_to_open_file(open("debian/changelog", 'w'))
Exemple #15
0
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:
    urllib.request.urlretrieve(
        "https://raw.githubusercontent.com/ubports/build-tools/master/Jenkinsfile",
        outdir + "/Jenkinsfile")

if args.git: