Exemplo n.º 1
0
 def apply(self, task):
     """Applies the patch in the current directory."""
     assert self._changed_files is not None, "You forgot to download the patch."
     edit = False
     if self.is_debdiff():
         cmd = [
             "patch", "--merge", "--force", "-p",
             str(self.get_strip_level()), "-i", self._full_path
         ]
         Logger.command(cmd)
         if subprocess.call(cmd) != 0:
             Logger.error("Failed to apply debdiff %s to %s %s.",
                          self._patch_file, task.package,
                          task.get_version())
             if not edit:
                 ask_for_manual_fixing()
                 edit = True
     else:
         cmd = ["add-patch", self._full_path]
         Logger.command(cmd)
         if subprocess.call(cmd) != 0:
             Logger.error("Failed to apply diff %s to %s %s.",
                          self._patch_file, task.package,
                          task.get_version())
             if not edit:
                 ask_for_manual_fixing()
                 edit = True
     return edit
Exemplo n.º 2
0
    def build_source(self, keyid, upload, previous_version):
        """Tries to build the source package.

        Returns true if the source package was built successfully. Returns false
        if the user wants to change something.
        """

        if self._branch:
            cmd = ['bzr', 'builddeb', '--builder=debuild', '-S',
                   '--', '--no-lintian', '-nc']
        else:
            cmd = ['debuild', '--no-lintian', '-nc', '-S']
        cmd.append("-v" + previous_version.full_version)
        if previous_version.upstream_version == \
           self._changelog.upstream_version and upload == "ubuntu":
            # FIXME: Add proper check that catches cases like changed
            # compression (.tar.gz -> tar.bz2) and multiple orig source tarballs
            cmd.append("-sd")
        else:
            cmd.append("-sa")
        if keyid is not None:
            cmd += ["-k" + keyid]
        env = os.environ
        if upload == 'ubuntu':
            env['DEB_VENDOR'] = 'Ubuntu'
        Logger.command(cmd)
        if subprocess.call(cmd, env=env) != 0:
            Logger.error("Failed to build source tarball.")
            # TODO: Add a "retry" option
            ask_for_manual_fixing()
            return False
        return True
Exemplo n.º 3
0
 def update(self, dist):
     cmd = ["sudo", "-E", "ARCH=" + self.architecture, "DIST=" + dist,
            self.name, "--update",
            "--architecture", self.architecture, "--distribution", dist]
     Logger.command(cmd)
     returncode = subprocess.call(cmd)
     return self._update_failure(returncode, dist)
Exemplo n.º 4
0
 def build(self, dsc_file, dist, result_directory):
     _build_preparation(result_directory)
     cmd = [self.name, dist, self.architecture,
            "build", dsc_file, "--buildresult", result_directory]
     Logger.command(cmd)
     returncode = subprocess.call(cmd)
     return self._build_failure(returncode, dsc_file)
Exemplo n.º 5
0
    def update(self, dist):
        cmd = ["schroot", "--list"]
        Logger.command(cmd)
        process = subprocess.Popen(cmd, stdout=subprocess.PIPE)
        chroots, _ = process.communicate()[0].strip().split()
        if process.returncode != 0:
            return process.returncode

        params = {"dist": dist, "arch": self.architecture}
        for chroot in ("%(dist)s-%(arch)s-sbuild-source",
                       "%(dist)s-sbuild-source",
                       "%(dist)s-%(arch)s-source",
                       "%(dist)s-source"):
            chroot = chroot % params
            if chroot in chroots:
                break
        else:
            return 1

        commands = [["sbuild-update"],
                    ["sbuild-distupgrade"],
                    ["sbuild-clean", "-a", "-c"]]
        for cmd in commands:
            # pylint: disable=W0631
            Logger.command(cmd + [chroot])
            ret = subprocess.call(cmd + [chroot])
            # pylint: enable=W0631
            if ret != 0:
                return self._update_failure(ret, dist)
        return 0
Exemplo n.º 6
0
def extract_source(dsc_file, verbose=False):
    cmd = ["dpkg-source", "--no-preparation", "-x", dsc_file]
    if not verbose:
        cmd.insert(1, "-q")
    Logger.command(cmd)
    if subprocess.call(cmd) != 0:
        Logger.error("Extraction of %s failed." % (os.path.basename(dsc_file)))
        sys.exit(1)
Exemplo n.º 7
0
    def ask_and_upload(self, upload):
        """Ask the user before uploading the source package.

        Returns true if the source package is uploaded successfully. Returns
        false if the user wants to change something.
        """

        # Upload package
        if upload:
            self._print_logs()
            if upload == "ubuntu":
                target = "the official Ubuntu archive"
            else:
                target = upload
            question = Question(["yes", "edit", "no"])
            answer = question.ask("Do you want to upload the package to %s" % target, "no")
            if answer == "edit":
                return False
            elif answer == "no":
                user_abort()
            cmd = ["dput", "--force", upload, self._changes_file]
            Logger.command(cmd)
            if subprocess.call(cmd) != 0:
                Logger.error("Upload of %s to %s failed." %
                             (os.path.basename(self._changes_file), upload))
                sys.exit(1)

            # Push the branch if the package is uploaded to the Ubuntu archive.
            if upload == "ubuntu" and self._branch:
                cmd = ['debcommit']
                Logger.command(cmd)
                if subprocess.call(cmd) != 0:
                    Logger.error('Bzr commit failed.')
                    sys.exit(1)
                cmd = ['bzr', 'mark-uploaded']
                Logger.command(cmd)
                if subprocess.call(cmd) != 0:
                    Logger.error('Bzr tagging failed.')
                    sys.exit(1)
                cmd = ['bzr', 'push', ':parent']
                Logger.command(cmd)
                if subprocess.call(cmd) != 0:
                    Logger.error('Bzr push failed.')
                    sys.exit(1)
        return True
Exemplo n.º 8
0
 def build(self, dsc_file, dist, result_directory):
     _build_preparation(result_directory)
     cmd = ["sudo", "-E", "ARCH=" + self.architecture, "DIST=" + dist,
            self.name, "--build",
            "--architecture", self.architecture, "--distribution", dist,
            "--buildresult", result_directory, dsc_file]
     Logger.command(cmd)
     returncode = subprocess.call(cmd)
     return self._build_failure(returncode, dsc_file)
Exemplo n.º 9
0
 def unpack(self, destdir=None):
     "Unpack in workdir"
     cmd = ['dpkg-source', '-x', self.dsc_name]
     if destdir:
         cmd.append(destdir)
     Logger.command(cmd)
     if subprocess.call(cmd, cwd=self.workdir):
         Logger.error('Source unpack failed.')
         sys.exit(1)
Exemplo n.º 10
0
def merge_branch(branch):
    edit = False
    cmd = ["bzr", "merge", branch]
    Logger.command(cmd)
    if subprocess.call(cmd) != 0:
        Logger.error("Failed to merge branch %s." % (branch))
        ask_for_manual_fixing()
        edit = True
    return edit
Exemplo n.º 11
0
 def debdiff(self, newpkg, diffstat=False):
     """Write a debdiff comparing this src pkg to a newer one.
     Optionally print diffstat.
     Return the debdiff filename.
     """
     cmd = ['debdiff', self.dsc_name, newpkg.dsc_name]
     difffn = newpkg.dsc_name[:-3] + 'debdiff'
     Logger.command(cmd + ['> %s' % difffn])
     with open(difffn, 'w') as f:
         if subprocess.call(cmd, stdout=f, cwd=self.workdir) > 2:
             Logger.error('Debdiff failed.')
             sys.exit(1)
     if diffstat:
         cmd = ('diffstat', '-p1', difffn)
         Logger.command(cmd)
         if subprocess.call(cmd):
             Logger.error('diffstat failed.')
             sys.exit(1)
     return os.path.abspath(difffn)
Exemplo n.º 12
0
def download_branch(branch):
    dir_name = os.path.basename(branch)
    if os.path.isdir(dir_name):
        shutil.rmtree(dir_name)
    cmd = ["bzr", "branch", branch]
    Logger.command(cmd)
    if subprocess.call(cmd) != 0:
        Logger.error("Failed to download branch %s." % (branch))
        sys.exit(1)
    return dir_name
Exemplo n.º 13
0
 def build(self, dsc_file, dist, result_directory):
     _build_preparation(result_directory)
     workdir = os.getcwd()
     Logger.command(["cd", result_directory])
     os.chdir(result_directory)
     cmd = ["sbuild", "--arch-all", "--dist=" + dist,
            "--arch=" + self.architecture, dsc_file]
     Logger.command(cmd)
     returncode = subprocess.call(cmd)
     Logger.command(["cd", workdir])
     os.chdir(workdir)
     return self._build_failure(returncode, dsc_file)
Exemplo n.º 14
0
def edit_source():
    # Spawn shell to allow modifications
    cmd = [get_user_shell()]
    Logger.command(cmd)
    print("""An interactive shell was launched in
file://%s
Edit your files. When you are done, exit the shell. If you wish to abort the
process, exit the shell such that it returns an exit code other than zero.
""" % (os.getcwd()),
          end=' ')
    returncode = subprocess.call(cmd)
    if returncode != 0:
        Logger.error("Shell exited with exit value %i." % (returncode))
        sys.exit(1)
Exemplo n.º 15
0
    def sync(self, upload, series, bug_number, requester):
        """Does a sync of the source package."""

        if upload == "ubuntu":
            cmd = ["syncpackage", self._package, "-b", str(bug_number), "-f",
                   "-s", requester, "-V", str(self._version),
                   "-d", series]
            Logger.command(cmd)
            if subprocess.call(cmd) != 0:
                Logger.error("Syncing of %s %s failed.", self._package,
                             str(self._version))
                sys.exit(1)
        else:
            # FIXME: Support this use case!
            Logger.error("Uploading a synced package other than to Ubuntu "
                         "is not supported yet!")
            sys.exit(1)
        return True
Exemplo n.º 16
0
 def update(self, dist):
     cmd = [self.name, dist, self.architecture, "update"]
     Logger.command(cmd)
     returncode = subprocess.call(cmd)
     return self._update_failure(returncode, dist)
Exemplo n.º 17
0
def _update_timestamp():
    """Run dch to update the timestamp of debian/changelog."""
    cmd = ["dch", "--maintmaint", "--release", ""]
    Logger.command(cmd)
    if subprocess.call(cmd) != 0:
        Logger.info("Failed to update timestamp in debian/changelog.")