def _check_dsc(self, verify_signature=False): "Check that the dsc matches what we are expecting" assert self._dsc is not None self.source = self.dsc['Source'] self.version = debian.debian_support.Version(self.dsc['Version']) valid = False message = None gpg_info = None try: gpg_info = self.dsc.get_gpg_info() valid = gpg_info.valid() except IOError: message = ('Signature on %s could not be verified, install ' 'debian-keyring' % self.dsc_name) if message is None: if valid: message = 'Valid signature' else: message = ('Signature on %s could not be verified' % self.dsc_name) if gpg_info is not None: if 'GOODSIG' in gpg_info: message = ('Good signature by %s (0x%s)' % (gpg_info['GOODSIG'][1], gpg_info['GOODSIG'][0])) elif 'VALIDSIG' in gpg_info: message = 'Valid signature by 0x%s' % gpg_info['VALIDSIG'][0] if verify_signature: if valid: Logger.normal(message) else: Logger.error(message) raise DownloadError(message) else: Logger.info(message)
def __init__(self, patch): self._patch = patch self._patch_file = re.sub(" |/", "_", patch.title) if not reduce(lambda r, x: r or self._patch.title.endswith(x), (".debdiff", ".diff", ".patch"), False): Logger.info("Patch %s does not have a proper file extension." % (self._patch.title)) self._patch_file += ".patch" self._full_path = os.path.realpath(self._patch_file) self._changed_files = None
def download(self): """Downloads the patch from Launchpad.""" Logger.info("Downloading %s." % (self._patch_file)) patch_f = open(self._patch_file, "w") patch_f.write(self._patch.data.open().read()) patch_f.close() cmd = ["diffstat", "-l", "-p0", self._full_path] process = subprocess.Popen(cmd, stdout=subprocess.PIPE) changed_files = process.communicate()[0] self._changed_files = [f for f in changed_files.split("\n") if f != ""]
def get_open_ubuntu_bug_task(launchpad, bug, branch=None): """Returns an open Ubuntu bug task for a given Launchpad bug. The bug task needs to be open (not complete) and target Ubuntu. The user will be ask to select one if multiple open Ubuntu bug task exits for the bug. """ bug_tasks = [BugTask(x, launchpad) for x in bug.bug_tasks] ubuntu_tasks = [x for x in bug_tasks if x.is_ubuntu_task()] bug_id = bug.id if branch: branch = branch.split('/') # Non-production LP? if len(branch) > 5: branch = branch[3:] if len(ubuntu_tasks) == 0: Logger.error("No Ubuntu bug task found on bug #%i." % (bug_id)) sys.exit(1) elif len(ubuntu_tasks) == 1: task = ubuntu_tasks[0] if len(ubuntu_tasks) > 1 and branch and branch[1] == 'ubuntu': tasks = [ t for t in ubuntu_tasks if t.get_series() == branch[2] and t.package == branch[3] ] if len(tasks) > 1: # A bug targeted to the development series? tasks = [t for t in tasks if t.series is not None] assert len(tasks) == 1 task = tasks[0] elif len(ubuntu_tasks) > 1: task_list = [t.get_short_info() for t in ubuntu_tasks] Logger.info("%i Ubuntu tasks exist for bug #%i.\n%s", len(ubuntu_tasks), bug_id, "\n".join(task_list)) open_ubuntu_tasks = [x for x in ubuntu_tasks if not x.is_complete()] if len(open_ubuntu_tasks) == 1: task = open_ubuntu_tasks[0] else: Logger.normal( "https://launchpad.net/bugs/%i has %i Ubuntu tasks:" % (bug_id, len(ubuntu_tasks))) for i in range(len(ubuntu_tasks)): print("%i) %s" % (i + 1, ubuntu_tasks[i].get_package_and_series())) selected = input_number( "To which Ubuntu task does the patch belong", 1, len(ubuntu_tasks)) task = ubuntu_tasks[selected - 1] Logger.info("Selected Ubuntu task: %s" % (task.get_short_info())) return task
def download_source(self): source_files = self.get_source().sourceFileUrls() dsc_file = "" for url in source_files: filename = unquote(os.path.basename(url)) Logger.info("Downloading %s..." % (filename)) # HttpLib2 isn't suitable for large files (it reads into memory), # but we want its https certificate validation on the .dsc if url.endswith(".dsc"): response, data = httplib2.Http().request(url) assert response.status == 200 with open(filename, 'w') as f: f.write(data) dsc_file = os.path.join(os.getcwd(), filename) else: urlretrieve(url, filename) assert os.path.isfile(dsc_file), "%s does not exist." % (dsc_file) return dsc_file
def _download_and_change_into(task, dsc_file, patch, branch): """Downloads the patch and branch and changes into the source directory.""" if branch: branch_dir = download_branch(task.get_branch_link()) # change directory Logger.command(["cd", branch_dir]) os.chdir(branch_dir) else: if patch: patch.download() Logger.info("Ubuntu package: %s" % (task.package)) if task.is_merge(): Logger.info("The task is a merge request.") if task.is_sync(): Logger.info("The task is a sync request.") extract_source(dsc_file, Logger.verbose) # change directory directory = task.package + '-' + task.get_version().upstream_version Logger.command(["cd", directory]) os.chdir(directory)
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.")
def ack_sync(self, upload, task, launchpad): """Acknowledge a sync request and subscribe ubuntu-archive.""" if upload == "ubuntu": self._print_logs() question = Question(["yes", "edit", "no"]) answer = question.ask("Do you want to acknowledge the sync request", "no") if answer == "edit": return False elif answer == "no": user_abort() bug = task.bug task.status = "Confirmed" if task.importance == "Undecided": task.importance = "Wishlist" task.lp_save() Logger.info("Set bug #%i status to Confirmed.", bug.id) msg = "Sync request ACK'd." if self._build_log: msg = ("%s %s builds on %s. " + msg) % \ (self._package, self._version, self._builder.get_architecture()) bug.newMessage(content=msg, subject="sponsor-patch") Logger.info("Acknowledged sync request bug #%i.", bug.id) bug.subscribe(person=launchpad.people['ubuntu-archive']) Logger.info("Subscribed ubuntu-archive to bug #%i.", bug.id) bug.subscribe(person=launchpad.me) Logger.info("Subscribed me to bug #%i.", bug.id) sponsorsteam = launchpad.people['ubuntu-sponsors'] for sub in bug.subscriptions: if sub.person == sponsorsteam and sub.canBeUnsubscribedByUser(): bug.unsubscribe(person=launchpad.people['ubuntu-sponsors']) Logger.info("Unsubscribed ubuntu-sponsors from bug #%i.", bug.id) elif sub.person == sponsorsteam: Logger.info("Couldn't unsubscribe ubuntu-sponsors from " "bug #%i.", bug.id) Logger.normal("Successfully acknowledged sync request bug #%i.", bug.id) else: Logger.error("Sync requests can only be acknowledged when the " "upload target is Ubuntu.") sys.exit(1) return True