def main(self):
        """Generate signing keys for the selected PPAs."""
        owner_name = self.options.archive_owner_name

        if owner_name is not None:
            owner = getUtility(IPersonSet).getByName(owner_name)
            if owner is None:
                raise LaunchpadScriptFailure(
                    "No person named '%s' could be found." % owner_name)
            if owner.archive is None:
                raise LaunchpadScriptFailure("Person named '%s' has no PPA." %
                                             owner_name)
            if owner.archive.signing_key is not None:
                raise LaunchpadScriptFailure(
                    "%s already has a signing_key (%s)" %
                    (owner.archive.displayname,
                     owner.archive.signing_key.fingerprint))
            archives = [owner.archive]
        else:
            archive_set = getUtility(IArchiveSet)
            archives = list(archive_set.getPPAsPendingSigningKey())

        for archive in archives:
            self.generateKey(archive)
            self.txn.commit()
Exemple #2
0
    def main(self):
        self.logger.info('Initializing...')
        if self.options.cvefile is not None:
            try:
                cve_db = open(self.options.cvefile, 'r').read()
            except IOError:
                raise LaunchpadScriptFailure(
                    'Unable to open CVE database in %s' % self.options.cvefile)

        elif self.options.cveurl is not None:
            self.logger.info("Downloading CVE database from %s..." %
                             self.options.cveurl)
            try:
                url = urllib2.urlopen(self.options.cveurl)
            except (urllib2.HTTPError, urllib2.URLError):
                raise LaunchpadScriptFailure(
                    'Unable to connect for CVE database %s' %
                    self.options.cveurl)

            cve_db_gz = url.read()
            self.logger.info("%d bytes downloaded." % len(cve_db_gz))
            cve_db = gzip.GzipFile(fileobj=StringIO.StringIO(cve_db_gz)).read()
        else:
            raise LaunchpadScriptFailure('No CVE database file or URL given.')

        # Start analysing the data.
        start_time = time.time()
        self.logger.info("Processing CVE XML...")
        self.processCVEXML(cve_db)
        finish_time = time.time()
        self.logger.info('%d seconds to update database.' %
                         (finish_time - start_time))
Exemple #3
0
    def main(self):
        if len(self.args) != 1:
            raise LaunchpadScriptFailure(
                "Need to be given exactly one non-option "
                "argument, namely the fsroot for the upload.")

        self.options.base_fsroot = os.path.abspath(self.args[0])

        if not os.path.isdir(self.options.base_fsroot):
            raise LaunchpadScriptFailure("%s is not a directory" %
                                         self.options.base_fsroot)

        self.logger.debug("Initializing connection.")

        def getPolicy(distro, build):
            self.options.distro = distro.name
            policy = findPolicyByName(self.options.context)
            policy.setOptions(self.options)
            if self.options.builds:
                assert build, "--builds specified but no build"
                policy.distroseries = build.distro_series
                policy.pocket = build.pocket
                policy.archive = build.archive
            return policy

        processor = UploadProcessor(self.options.base_fsroot,
                                    self.options.dryrun, self.options.nomails,
                                    self.options.builds, self.options.keep,
                                    getPolicy, self.txn, self.logger)
        processor.processUploadQueue(self.options.leafname)
 def main(self):
     if len(self.args) < 1:
         raise LaunchpadScriptFailure('Please specify a target directory.')
     if len(self.args) > 1:
         raise LaunchpadScriptFailure('Too many arguments.')
     target_dir = self.args[0]
     with server(get_rw_server()):
         if self.options.finish:
             Upgrader.finish_all_upgrades(target_dir, self.logger)
         else:
             Upgrader.start_all_upgrades(target_dir, self.logger)
Exemple #5
0
    def checkOptions(self):
        """Verify if the given command-line options are sane."""
        if ((self.options.gen_orphan_repos or self.options.gen_missing_repos
             or self.options.gen_over_quota) and self.options.gen_user_emails):
            raise LaunchpadScriptFailure(
                'Users-list cannot be combined with other reports.')

        if ((self.options.gen_orphan_repos or self.options.gen_missing_repos)
                and self.options.archive_owner_name is not None):
            raise LaunchpadScriptFailure(
                'Cannot calculate repository paths for a single PPA.')

        if ((self.options.gen_orphan_repos or self.options.gen_missing_repos)
                and not os.path.exists(config.personalpackagearchive.root)):
            raise LaunchpadScriptFailure('Cannot access PPA root directory.')
Exemple #6
0
def execute(logger, command, args=None):
    """Execute a shell command.

    :param logger: Output from the command will be logged here.
    :param command: Command to execute, as a string.
    :param args: Optional list of arguments for `command`.
    :raises LaunchpadScriptFailure: If the command returns failure.
    """
    command_line = [command]
    if args is not None:
        command_line += args
    description = ' '.join(command_line)

    logger.debug("Execute: %s", description)
    # Some of these commands can take a long time.  Use CommandSpawner
    # and friends to provide "live" log output.  Simpler ways of running
    # commands tend to save it all up and then dump it at the end, or
    # have trouble logging it as neat lines.
    stderr_logger = OutputLineHandler(logger.info)
    stdout_logger = OutputLineHandler(logger.debug)
    receiver = ReturnCodeReceiver()
    spawner = CommandSpawner()
    spawner.start(command_line,
                  completion_handler=receiver,
                  stderr_handler=stderr_logger,
                  stdout_handler=stdout_logger)
    spawner.complete()
    stdout_logger.finalize()
    stderr_logger.finalize()
    if receiver.returncode != 0:
        raise LaunchpadScriptFailure("Failure while running command: %s" %
                                     description)
    def main(self):
        """Entry point for `LaunchpadScript`s."""
        try:
            self.setupLocation()
        except SoyuzScriptError as err:
            raise LaunchpadScriptFailure(err)

        if not self.options.arch_tags:
            self.parser.error("Specify at least one architecture.")

        arches = []
        for arch_tag in self.options.arch_tags:
            try:
                das = self.location.distroseries.getDistroArchSeries(arch_tag)
                arches.append(das)
            except NotFoundError:
                self.parser.error("%s not a valid architecture for %s" %
                                  (arch_tag, self.location.distroseries.name))

        # I'm tired of parsing options.  Let's do it.
        try:
            self.add_missing_builds(self.location.archive, arches,
                                    self.location.distroseries,
                                    self.location.pocket)
            self.txn.commit()
            self.logger.info("Finished adding builds.")
        except Exception as err:
            self.logger.error(err)
            self.txn.abort()
            self.logger.info("Errors, aborted transaction.")
            sys.exit(1)
Exemple #8
0
def run_parts(distribution_name, parts, log=None, env=None):
    """Execute run-parts.

    :param distribution_name: The name of the distribution to execute
        run-parts scripts for.
    :param parts: The run-parts directory to execute:
        "publish-distro.d" or "finalize.d".
    :param log: An optional logger.
    :param env: A dict of additional environment variables to pass to the
        scripts in the run-parts directory, or None.
    """
    parts_dir = find_run_parts_dir(distribution_name, parts)
    if parts_dir is None:
        if log is not None:
            log.debug("Skipping run-parts %s: not configured.", parts)
        return
    cmd = ["run-parts", "--", parts_dir]
    failure = LaunchpadScriptFailure(
        "Failure while executing run-parts %s." % parts_dir)
    full_env = dict(os.environ)
    if env is not None:
        full_env.update(env)
    scripts_dir = os.path.join(config.root, "cronscripts", "publishing")
    path_elements = full_env.get("PATH", "").split(os.pathsep)
    path_elements.append(scripts_dir)
    full_env["PATH"] = os.pathsep.join(path_elements)
    execute_subprocess(cmd, log=None, failure=failure, env=full_env)
Exemple #9
0
    def main(self):
        """See `LaunchpadScript`."""
        self._setDistroDetails()
        self._setPackage()

        if self.options.dryrun:
            self.logger.info("Dry run.  Not really uploading anything.")

        queue = getUtility(ITranslationImportQueue)
        rosetta_team = getUtility(ILaunchpadCelebrities).rosetta_experts

        for filename in self.args:
            if not os.access(filename, os.R_OK):
                raise LaunchpadScriptFailure("File not readable: %s" %
                                             filename)
            self.logger.info("Uploading: %s." % filename)
            content = open(filename).read()
            queue.addOrUpdateEntry(filename,
                                   content,
                                   True,
                                   rosetta_team,
                                   sourcepackagename=self.sourcepackagename,
                                   distroseries=self.distroseries)
            self._commit()

        self.logger.info("Done.")
Exemple #10
0
    def supported(self):
        """Return the names of the distroseries currently supported.

        'supported' means not EXPERIMENTAL or OBSOLETE.

        It is restricted for the context distribution.

        It may raise `LaunchpadScriptFailure` if a suite was passed on the
        command-line or if there is not supported distroseries for the
        distribution given.

        Return a space-separated list of distroseries names.
        """
        self.checkNoSuiteDefined()
        supported_series = []
        unsupported_status = (SeriesStatus.EXPERIMENTAL,
                              SeriesStatus.OBSOLETE)
        for distroseries in self.location.distribution:
            if distroseries.status not in unsupported_status:
                supported_series.append(distroseries.name)

        if not supported_series:
            raise LaunchpadScriptFailure(
                'There is no supported distroseries for %s' %
                self.location.distribution.name)

        return " ".join(supported_series)
    def main(self):
        """See `LaunchpadScript`."""
        process_options(self.options)
        (result, message) = self._check_constraints_safety()
        if not result:
            raise LaunchpadScriptFailure(message)
        if message is not None:
            self.logger.warn(message)

        if self.options.dry_run:
            self.logger.info("Dry run only.  Not really deleting.")

        remove_translations(
            logger=self.logger,
            submitter=self.options.submitter,
            reject_license=self.options.reject_license,
            reviewer=self.options.reviewer,
            ids=self.options.ids,
            potemplate=self.options.potemplate,
            language_code=self.options.language,
            not_language=self.options.not_language,
            is_current_ubuntu=self.options.is_current_ubuntu,
            is_current_upstream=self.options.is_current_upstream,
            msgid_singular=self.options.msgid,
            origin=self.options.origin)

        if self.options.dry_run:
            if self.txn is not None:
                self.txn.abort()
        else:
            self.txn.commit()
Exemple #12
0
    def main(self):
        emailaddress = unicode(self.options.email)
        if not emailaddress:
            raise LaunchpadScriptFailure('--email is required')

        person = getUtility(IPersonSet).getByEmail(emailaddress)
        if person is None:
            raise LaunchpadScriptFailure(
                'Account with email address {} does not exist'.format(
                    emailaddress))

        person.account.setStatus(AccountStatus.SUSPENDED, None,
                                 'Suspended by suspend-bot-account.py')

        self.logger.info('Suspended {}'.format(canonical_url(person)))
        self.txn.commit()
 def main(self):
     """Flag expired team memberships."""
     if self.args:
         raise LaunchpadScriptFailure(
             "Unhandled arguments %s" % repr(self.args))
     self.logger.info("Flagging expired team memberships.")
     self.flag_expired_memberships_and_send_warnings()
     self.logger.info("Finished flagging expired team memberships.")
Exemple #14
0
 def getCopyArchives(self, distribution):
     """Find copy archives for the selected distribution."""
     copy_archives = list(
         getUtility(IArchiveSet).getArchivesForDistribution(
             distribution, purposes=[ArchivePurpose.COPY]))
     if copy_archives == []:
         raise LaunchpadScriptFailure("Could not find any COPY archives")
     return copy_archives
Exemple #15
0
    def _setPackage(self):
        """Find `SourcePackage` of given name."""
        if not self.options.package:
            raise LaunchpadScriptFailure("No package specified.")

        nameset = getUtility(ISourcePackageNameSet)

        self.sourcepackagename = nameset.queryByName(self.options.package)
Exemple #16
0
 def findNamedDistro(self, distro_name):
     """Find the `Distribution` called `distro_name`."""
     self.logger.debug("Finding distribution %s.", distro_name)
     distro = getUtility(IDistributionSet).getByName(distro_name)
     if distro is None:
         raise LaunchpadScriptFailure("Distribution '%s' not found." %
                                      distro_name)
     return distro
    def _setargs(self, args):
        """Set distribution_name and series_name from the args."""
        if len(args) != 2:
            raise LaunchpadScriptFailure(
                'Wrong number of arguments: should include distribution '
                'and series name.')

        self._args = args
        self.distribution_name, self.series_name = self._args
    def main(self):
        """Upload file, commit the transaction and prints the file URL."""
        if self.options.filepath is None:
            raise LaunchpadScriptFailure('File not provided.')

        library_file = self.upload_file(self.options.filepath)

        self.txn.commit()
        self.logger.info(library_file.http_url)
 def main(self):
     try:
         handleMail(self.txn)
     except ComponentLookupError as lookup_error:
         if lookup_error.args[0] != IMailBox:
             raise
         raise LaunchpadScriptFailure(
             "No mail box is configured. "
             "Please see mailbox.txt for info on how to configure one.")
Exemple #20
0
 def getConfig(self):
     """Set up a configuration object for this archive."""
     archive = self.distribution.main_archive
     if archive:
         return getPubConfig(archive)
     else:
         raise LaunchpadScriptFailure(
             "There is no PRIMARY archive for %s." %
             self.options.distribution)
Exemple #21
0
    def checkNoSuiteDefined(self):
        """Raises LaunchpadScriptError if a suite location was passed.

        It is re-used in action properties to avoid conflicting contexts,
        i.e, passing an arbitrary 'suite' and asking for the CURRENT suite
        in the context distribution.
        """
        if self.options.suite is not None:
            raise LaunchpadScriptFailure(
                "Action does not accept defined suite.")
Exemple #22
0
    def _setDistroDetails(self):
        """Figure out the `Distribution`/`DistroSeries` to act upon."""
        distroset = getUtility(IDistributionSet)
        self.distro = distroset.getByName(self.options.distro)

        if not self.options.distroseries:
            raise LaunchpadScriptFailure(
                "Specify a distribution release series.")

        self.distroseries = self.distro.getSeries(self.options.distroseries)
Exemple #23
0
    def main(self):
        self.logger.info('Initializing...')
        if self.options.cvefile is not None:
            try:
                cve_db = open(self.options.cvefile, 'r').read()
            except IOError:
                raise LaunchpadScriptFailure(
                    'Unable to open CVE database in %s'
                    % self.options.cvefile)
        elif self.options.cveurl is not None:
            cve_db = self.fetchCVEURL(self.options.cveurl)
        else:
            raise LaunchpadScriptFailure('No CVE database file or URL given.')

        # Start analysing the data.
        start_time = time.time()
        self.logger.info("Processing CVE XML...")
        self.processCVEXML(cve_db)
        finish_time = time.time()
        self.logger.info('%d seconds to update database.'
                % (finish_time - start_time))
    def main(self):
        """LaunchpadScript entry point.

        Can only raise LaunchpadScriptFailure - other exceptions are
        absorbed into that.
        """
        try:
            self.setupLocation()
            self.mainTask()
        except SoyuzScriptError as err:
            raise LaunchpadScriptFailure(err)

        self.finishProcedure()
    def main(self):
        if len(self.args) != 2:
            raise LaunchpadScriptFailure(
                "You must specify the name of the person to be converted "
                "and the person/team who should be its teamowner.")

        person_set = getUtility(IPersonSet)
        person_name, owner_name = self.args
        person = person_set.getByName(person_name)
        if person is None:
            raise LaunchpadScriptFailure(
                "There's no person named '%s'." % person_name)
        if person.account_status != AccountStatus.NOACCOUNT:
            raise LaunchpadScriptFailure(
                "Only people which have no account can be turned into teams.")
        owner = person_set.getByName(owner_name)
        if owner is None:
            raise LaunchpadScriptFailure(
                "There's no person named '%s'." % owner_name)

        person.convertToTeam(owner)
        self.txn.commit()
    def _setDistroDetails(self):
        """Figure out the `Distribution`/`DistroSeries` to act upon."""
        # Avoid circular imports.
        from lp.registry.interfaces.distribution import IDistributionSet

        distroset = getUtility(IDistributionSet)
        self.distro = distroset.getByName(self.options.distro)

        if not self.options.distroseries:
            raise LaunchpadScriptFailure(
                "Specify a distribution release series.")

        self.distroseries = self.distro.getSeries(self.options.distroseries)
Exemple #27
0
    def get_last_modified_epoch(self):
        """Return the timezone aware datetime for the last modified epoch. """
        if (self.options.last_hours is not None
                and self.options.since is not None):
            raise LaunchpadScriptFailure(
                "Only one of --since or --last-hours can be specified.")
        last_modified = None
        if self.options.last_hours is not None:
            last_modified = (self.now_timestamp -
                             timedelta(hours=self.options.last_hours))
        elif self.options.since is not None:
            try:
                parsed_time = strptime(self.options.since, '%Y-%m-%d')
                last_modified = datetime(*(parsed_time[:3]))
            except ValueError as e:
                raise LaunchpadScriptFailure(str(e))
        else:
            raise LaunchpadScriptFailure(
                "One of --since or --last-hours needs to be specified.")

        # Make the datetime timezone aware.
        return last_modified.replace(tzinfo=pytz.UTC)
    def main(self):
        """Generate signing keys for the selected PPAs."""
        if self.options.archive is not None:
            archive = getUtility(IArchiveSet).getByReference(
                self.options.archive)
            if archive is None:
                raise LaunchpadScriptFailure(
                    "No archive named '%s' could be found." %
                    self.options.archive)
            if archive.signing_key is not None:
                raise LaunchpadScriptFailure(
                    "%s (%s) already has a signing_key (%s)" %
                    (archive.reference, archive.displayname,
                     archive.signing_key.fingerprint))
            archives = [archive]
        else:
            archive_set = getUtility(IArchiveSet)
            archives = list(archive_set.getPPAsPendingSigningKey())

        for archive in archives:
            self.generateKey(archive)
            self.txn.commit()
Exemple #29
0
    def _buildLocation(self):
        """Build a PackageLocation object

        The location will correspond to the given 'distribution' and 'suite',
        Any PackageLocationError occurring at this point will be masked into
        LaunchpadScriptFailure.
        """
        try:
            self.location = build_package_location(
                distribution_name=self.options.distribution_name,
                suite=self.options.suite)
        except PackageLocationError as err:
            raise LaunchpadScriptFailure(err)
    def processOptions(self):
        """Handle command-line options.

        Sets `self.distributions` to the `Distribution`s to publish.
        """
        if self.options.distribution is None and not self.options.all_derived:
            raise LaunchpadScriptFailure(
                "Specify a distribution, or --all-derived.")
        if self.options.distribution is not None and self.options.all_derived:
            raise LaunchpadScriptFailure(
                "Can't combine the --distribution and --all-derived options.")

        if self.options.all_derived:
            distro_set = getUtility(IDistributionSet)
            self.distributions = distro_set.getDerivedDistributions()
        else:
            distro = getUtility(IDistributionSet).getByName(
                self.options.distribution)
            if distro is None:
                raise LaunchpadScriptFailure("Distribution %s not found." %
                                             self.options.distribution)
            self.distributions = [distro]