Пример #1
0
def main():
    global Options, Logger

    cnf = Config()
    session = DBConn().session()

    Arguments = [('h', "help", "Archive-Dedup-Pool::Options::Help")]

    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)

    for i in ["help"]:
        key = "Archive-Dedup-Pool::Options::%s" % i
        if key not in cnf:
            cnf[key] = ""

    Options = cnf.subtree("Archive-Dedup-Pool::Options")

    if Options["Help"]:
        usage()

    Logger = daklog.Logger("archive-dedup-pool")

    dedup(session)

    Logger.close()
Пример #2
0
def main():
    global Options, Logger
    cnf = Config()
    Arguments = [('h', "help",      "Obsolete::Options::Help"),
                 ('s', "suite",     "Obsolete::Options::Suite", "HasArg"),
                 ('n', "no-action", "Obsolete::Options::No-Action"),
                 ('f', "force",     "Obsolete::Options::Force")]
    cnf['Obsolete::Options::Help'] = ''
    cnf['Obsolete::Options::No-Action'] = ''
    cnf['Obsolete::Options::Force'] = ''
    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Obsolete::Options")
    if Options['Help']:
        usage()
    if 'Suite' not in Options:
        query_suites = DBConn().session().query(Suite)
        suites = [suite.suite_name for suite in query_suites.all()]
        cnf['Obsolete::Options::Suite'] = ','.join(suites)
    Logger = daklog.Logger("dominate")
    session = DBConn().session()
    for suite_name in utils.split_args(Options['Suite']):
        suite = session.query(Suite).filter_by(suite_name = suite_name).one()
        if not suite.untouchable or Options['Force']:
            doDaDoDa(suite.suite_id, session)
    if Options['No-Action']:
        session.rollback()
    else:
        session.commit()
    Logger.close()
Пример #3
0
def main():
    global Options, Logger

    cnf = Config()
    session = DBConn().session()

    Arguments = [('h', "help", "Archive-Dedup-Pool::Options::Help")]

    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)

    for i in ["help"]:
        key = "Archive-Dedup-Pool::Options::%s" % i
        if key not in cnf:
            cnf[key] = ""

    Options = cnf.subtree("Archive-Dedup-Pool::Options")

    if Options["Help"]:
        usage()

    Logger = daklog.Logger("archive-dedup-pool")

    dedup(session)

    Logger.close()
Пример #4
0
def main():
    global Cnf

    Cnf = utils.get_conf()
    Arguments = [('h',"help","Queue-Report::Options::Help"),
                 ('n',"new","Queue-Report::Options::New"),
                 ('8','822',"Queue-Report::Options::822"),
                 ('s',"sort","Queue-Report::Options::Sort", "HasArg"),
                 ('a',"age","Queue-Report::Options::Age", "HasArg"),
                 ('r',"rrd","Queue-Report::Options::Rrd", "HasArg"),
                 ('d',"directories","Queue-Report::Options::Directories", "HasArg")]
    for i in [ "help" ]:
        if not Cnf.has_key("Queue-Report::Options::%s" % (i)):
            Cnf["Queue-Report::Options::%s" % (i)] = ""

    apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)

    Options = Cnf.subtree("Queue-Report::Options")
    if Options["Help"]:
        usage()

    if Cnf.has_key("Queue-Report::Options::New"):
        header()

    queue_names = []

    if Cnf.has_key("Queue-Report::Options::Directories"):
        for i in Cnf["Queue-Report::Options::Directories"].split(","):
            queue_names.append(i)
    elif Cnf.has_key("Queue-Report::Directories"):
        queue_names = Cnf.value_list("Queue-Report::Directories")
    else:
        queue_names = [ "byhand", "new" ]

    if Cnf.has_key("Queue-Report::Options::Rrd"):
        rrd_dir = Cnf["Queue-Report::Options::Rrd"]
    elif Cnf.has_key("Dir::Rrd"):
        rrd_dir = Cnf["Dir::Rrd"]
    else:
        rrd_dir = None

    f = None
    if Cnf.has_key("Queue-Report::Options::822"):
        # Open the report file
        f = open(Cnf["Queue-Report::ReportLocations::822Location"], "w")

    session = DBConn().session()

    for queue_name in queue_names:
        queue = session.query(PolicyQueue).filter_by(queue_name=queue_name).first()
        if queue is not None:
            process_queue(queue, f, rrd_dir)
        else:
            utils.warn("Cannot find queue %s" % queue_name)

    if Cnf.has_key("Queue-Report::Options::822"):
        f.close()

    if Cnf.has_key("Queue-Report::Options::New"):
        footer()
Пример #5
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    arguments = [('h', 'help', 'Export::Options::Help'),
                 ('c', 'copy', 'Export::Options::Copy'),
                 ('d', 'directory', 'Export::Options::Directory', 'HasArg'),
                 ('r', 'relative', 'Export::Options::Relative'),
                 ('s', 'suite', 'Export::Options::Suite', 'HasArg')]

    cnf = Config()
    apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
    options = cnf.subtree('Export::Options')

    if 'Help' in options or 'Suite' not in options:
        usage()
        sys.exit(0)

    session = DBConn().session()

    suite = session.query(Suite).filter_by(suite_name=options['Suite']).first()
    if suite is None:
        print("Unknown suite '{0}'".format(options['Suite']))
        sys.exit(1)

    directory = options.get('Directory')
    if not directory:
        print("No target directory.")
        sys.exit(1)

    symlink = 'Copy' not in options
    relative = 'Relative' in options

    if relative and not symlink:
        print("E: --relative and --copy cannot be used together.")
        sys.exit(1)

    binaries = suite.binaries
    sources = suite.sources

    files = []
    files.extend([b.poolfile for b in binaries])
    for s in sources:
        files.extend([ds.poolfile for ds in s.srcfiles])

    with FilesystemTransaction() as fs:
        for f in files:
            af = session.query(ArchiveFile) \
                        .join(ArchiveFile.component).join(ArchiveFile.file) \
                        .filter(ArchiveFile.archive == suite.archive) \
                        .filter(ArchiveFile.file == f).first()
            src = af.path
            if relative:
                src = os.path.relpath(src, directory)
            dst = os.path.join(directory, f.basename)
            if not os.path.exists(dst):
                fs.copy(src, dst, symlink=symlink)
        fs.commit()
Пример #6
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    arguments = [('h', 'help', 'Export::Options::Help'),
                 ('c', 'copy', 'Export::Options::Copy'),
                 ('d', 'directory', 'Export::Options::Directory', 'HasArg'),
                 ('r', 'relative', 'Export::Options::Relative'),
                 ('s', 'suite', 'Export::Options::Suite', 'HasArg')]

    cnf = Config()
    apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
    options = cnf.subtree('Export::Options')

    if 'Help' in options or 'Suite' not in options:
        usage()
        sys.exit(0)

    session = DBConn().session()

    suite = session.query(Suite).filter_by(suite_name=options['Suite']).first()
    if suite is None:
        print "Unknown suite '{0}'".format(options['Suite'])
        sys.exit(1)

    directory = options.get('Directory')
    if not directory:
        print "No target directory."
        sys.exit(1)

    symlink = 'Copy' not in options
    relative = 'Relative' in options

    if relative and not symlink:
        print "E: --relative and --copy cannot be used together."
        sys.exit(1)

    binaries = suite.binaries
    sources = suite.sources

    files = []
    files.extend([ b.poolfile for b in binaries ])
    for s in sources:
        files.extend([ ds.poolfile for ds in s.srcfiles ])

    with FilesystemTransaction() as fs:
        for f in files:
            af = session.query(ArchiveFile) \
                        .join(ArchiveFile.component).join(ArchiveFile.file) \
                        .filter(ArchiveFile.archive == suite.archive) \
                        .filter(ArchiveFile.file == f).first()
            src = af.path
            if relative:
                src = os.path.relpath(src, directory)
            dst = os.path.join(directory, f.basename)
            if not os.path.exists(dst):
                fs.copy(src, dst, symlink=symlink)
        fs.commit()
Пример #7
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    arguments = [('h', 'help', 'Export::Options::Help'),
                 ('c', 'copy', 'Export::Options::Copy'),
                 ('d', 'directory', 'Export::Options::Directory', 'HasArg'),
                 ('s', 'suite', 'Export::Options::Suite', 'HasArg')]

    cnf = Config()
    apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
    options = cnf.subtree('Export::Options')

    if 'Help' in options or 'Suite' not in options:
        usage()
        sys.exit(0)

    session = DBConn().session()

    suite = session.query(Suite).filter_by(suite_name=options['Suite']).first()
    if suite is None:
        print "Unknown suite '{0}'".format(options['Suite'])
        sys.exit(1)

    directory = options.get('Directory')
    if not directory:
        print "No target directory."
        sys.exit(1)

    symlink = 'Copy' not in options

    binaries = suite.binaries
    sources = suite.sources

    files = []
    files.extend([ b.poolfile for b in binaries ])
    for s in sources:
        files.extend([ ds.poolfile for ds in s.srcfiles ])

    with FilesystemTransaction() as fs:
        for f in files:
            af = session.query(ArchiveFile) \
                        .join(ArchiveFile.component).join(ArchiveFile.file) \
                        .filter(ArchiveFile.archive == suite.archive) \
                        .filter(ArchiveFile.file == f).first()
            # XXX: Remove later. There was a bug that caused only the *.dsc to
            # be installed in build queues and we do not want to break them.
            # The bug was fixed in 55d2c7e6e2418518704623246021021e05b90e58
            # on 2012-11-04
            if af is None:
                af = session.query(ArchiveFile) \
                            .join(ArchiveFile.component).join(ArchiveFile.file) \
                            .filter(ArchiveFile.file == f).first()
            dst = os.path.join(directory, f.basename)
            if not os.path.exists(dst):
                fs.copy(af.path, dst, symlink=symlink)
        fs.commit()
Пример #8
0
def main():
    global Options
    cnf = Config()

    Arguments = [
        ('h', "help", "Auto-Decruft::Options::Help"),
        ('n', "dry-run", "Auto-Decruft::Options::Dry-Run"),
        ('d', "debug", "Auto-Decruft::Options::Debug"),
        ('s', "suite", "Auto-Decruft::Options::Suite", "HasArg"),
        # The "\0" seems to be the only way to disable short options.
        ("\0", 'if-newer-version-in', "Auto-Decruft::Options::OtherSuite",
         "HasArg"),
        ("\0", 'if-newer-version-in-rm-msg',
         "Auto-Decruft::Options::OtherSuiteRMMsg", "HasArg")
    ]
    for i in ["help", "Dry-Run", "Debug", "OtherSuite", "OtherSuiteRMMsg"]:
        if not cnf.has_key("Auto-Decruft::Options::%s" % (i)):
            cnf["Auto-Decruft::Options::%s" % (i)] = ""

    cnf["Auto-Decruft::Options::Suite"] = cnf.get("Dinstall::DefaultSuite",
                                                  "unstable")

    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)

    Options = cnf.subtree("Auto-Decruft::Options")
    if Options["Help"]:
        usage()

    debug = False
    dryrun = False
    if Options["Dry-Run"]:
        dryrun = True
    if Options["Debug"]:
        debug = True

    if Options["OtherSuite"] and not Options["OtherSuiteRMMsg"]:
        utils.fubar(
            "--if-newer-version-in requires --if-newer-version-in-rm-msg")

    session = DBConn().session()

    suite = get_suite(Options["Suite"].lower(), session)
    if not suite:
        utils.fubar("Cannot find suite %s" % Options["Suite"].lower())

    suite_id = suite.suite_id
    suite_name = suite.suite_name.lower()

    auto_decruft_suite(suite_name, suite_id, session, dryrun, debug)

    if Options["OtherSuite"]:
        osuite = get_suite(Options["OtherSuite"].lower(), session).suite_name
        decruft_newer_version_in(osuite, suite_name, suite_id,
                                 Options["OtherSuiteRMMsg"], session, dryrun)

    if not dryrun:
        session.commit()
Пример #9
0
def main():
    global Options
    cnf = Config()

    Arguments = [('h', "help", "Auto-Decruft::Options::Help"),
                 ('n', "dry-run", "Auto-Decruft::Options::Dry-Run"),
                 ('d', "debug", "Auto-Decruft::Options::Debug"),
                 ('s', "suite", "Auto-Decruft::Options::Suite", "HasArg"),
                 # The "\0" seems to be the only way to disable short options.
                 ("\0", 'if-newer-version-in', "Auto-Decruft::Options::OtherSuite", "HasArg"),
                 ("\0", 'if-newer-version-in-rm-msg', "Auto-Decruft::Options::OtherSuiteRMMsg", "HasArg"),
                 ("\0", 'decruft-equal-versions', "Auto-Decruft::Options::OtherSuiteDecruftEqual")
                ]
    for i in ["help", "Dry-Run", "Debug", "OtherSuite", "OtherSuiteRMMsg", "OtherSuiteDecruftEqual"]:
        key = "Auto-Decruft::Options::%s" % i
        if key not in cnf:
            cnf[key] = ""

    cnf["Auto-Decruft::Options::Suite"] = cnf.get("Dinstall::DefaultSuite", "unstable")

    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)

    Options = cnf.subtree("Auto-Decruft::Options")
    if Options["Help"]:
        usage()

    debug = False
    dryrun = False
    decruft_equal_versions = False
    if Options["Dry-Run"]:
        dryrun = True
    if Options["Debug"]:
        debug = True
    if Options["OtherSuiteDecruftEqual"]:
        decruft_equal_versions = True

    if Options["OtherSuite"] and not Options["OtherSuiteRMMsg"]:
        utils.fubar("--if-newer-version-in requires --if-newer-version-in-rm-msg")

    session = DBConn().session()

    suite = get_suite(Options["Suite"].lower(), session)
    if not suite:
        utils.fubar("Cannot find suite %s" % Options["Suite"].lower())

    suite_id = suite.suite_id
    suite_name = suite.suite_name.lower()

    auto_decruft_suite(suite_name, suite_id, session, dryrun, debug)

    if Options["OtherSuite"]:
        osuite = get_suite(Options["OtherSuite"].lower(), session).suite_name
        decruft_newer_version_in(osuite, suite_name, suite_id, Options["OtherSuiteRMMsg"], session, dryrun, decruft_equal_versions)

    if not dryrun:
        session.commit()
Пример #10
0
def main():
    global Options, Logger

    cnf = Config()

    for i in ["Help", "No-Action", "Maximum" ]:
        if not cnf.has_key("Clean-Suites::Options::%s" % (i)):
            cnf["Clean-Suites::Options::%s" % (i)] = ""

    Arguments = [('h',"help","Clean-Suites::Options::Help"),
                 ('n',"no-action","Clean-Suites::Options::No-Action"),
                 ('m',"maximum","Clean-Suites::Options::Maximum", "HasArg")]

    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Clean-Suites::Options")

    if cnf["Clean-Suites::Options::Maximum"] != "":
        try:
            # Only use Maximum if it's an integer
            max_delete = int(cnf["Clean-Suites::Options::Maximum"])
            if max_delete < 1:
                utils.fubar("If given, Maximum must be at least 1")
        except ValueError as e:
            utils.fubar("If given, Maximum must be an integer")
    else:
        max_delete = None

    if Options["Help"]:
        usage()

    Logger = daklog.Logger("clean-suites", debug=Options["No-Action"])

    session = DBConn().session()

    now_date = datetime.now()

    # Stay of execution; default to 1.5 days
    soe = int(cnf.get('Clean-Suites::StayOfExecution', '129600'))

    delete_date = now_date - timedelta(seconds=soe)

    check_binaries(now_date, delete_date, max_delete, session)
    clean_binaries(now_date, delete_date, max_delete, session)
    check_sources(now_date, delete_date, max_delete, session)
    check_files(now_date, delete_date, max_delete, session)
    clean(now_date, delete_date, max_delete, session)
    clean_maintainers(now_date, delete_date, max_delete, session)
    clean_fingerprints(now_date, delete_date, max_delete, session)
    clean_empty_directories(session)

    Logger.close()
Пример #11
0
def main():
    cnf = Config()
    Arguments = [('h', "help", "Make-Overrides::Options::Help")]
    for i in ["help"]:
        key = "Make-Overrides::Options::%s" % i
        if key not in cnf:
            cnf[key] = ""
    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Make-Overrides::Options")
    if Options["Help"]:
        usage()

    d = DBConn()
    session = d.session()

    for suite in session.query(Suite).filter(
            Suite.overrideprocess == True):  # noqa:E712
        if suite.untouchable:
            print("Skipping %s as it is marked as untouchable" %
                  suite.suite_name)
            continue

        sys.stderr.write("Processing %s...\n" % (suite.suite_name))
        override_suite = suite.overridecodename or suite.codename

        for component in session.query(Component).all():
            for otype in session.query(OverrideType).all():
                otype_name = otype.overridetype
                cname = component.component_name

                # TODO: Stick suffix info in database (or get rid of it)
                if otype_name == "deb":
                    suffix = ""
                elif otype_name == "udeb":
                    if cname == "contrib":
                        continue  # Ick2
                    suffix = ".debian-installer"
                elif otype_name == "dsc":
                    suffix = ".src"
                else:
                    utils.fubar("Don't understand OverrideType %s" %
                                otype.overridetype)

                cname = cname.replace('/', '_')
                filename = os.path.join(
                    cnf["Dir::Override"],
                    "override.%s.%s%s" % (override_suite, cname, suffix))

                output_file = utils.open_file(filename, 'w')
                do_list(output_file, suite, component, otype, session)
                output_file.close()
Пример #12
0
def main():
    Cnf = utils.get_conf()
    Arguments = [
        ('h', 'help', 'Make-Changelog::Options::Help'),
        ('a', 'archive', 'Make-Changelog::Options::Archive', 'HasArg'),
        ('s', 'suite', 'Make-Changelog::Options::Suite', 'HasArg'),
        ('b', 'base-suite', 'Make-Changelog::Options::Base-Suite', 'HasArg'),
        ('n', 'binnmu', 'Make-Changelog::Options::binNMU'),
        ('e', 'export', 'Make-Changelog::Options::export'),
        ('p', 'progress', 'Make-Changelog::Options::progress')
    ]

    for i in ['help', 'suite', 'base-suite', 'binnmu', 'export', 'progress']:
        key = 'Make-Changelog::Options::%s' % i
        if key not in Cnf:
            Cnf[key] = ''

    apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
    Options = Cnf.subtree('Make-Changelog::Options')
    suite = Cnf['Make-Changelog::Options::Suite']
    base_suite = Cnf['Make-Changelog::Options::Base-Suite']
    binnmu = Cnf['Make-Changelog::Options::binNMU']
    export = Cnf['Make-Changelog::Options::export']
    progress = Cnf['Make-Changelog::Options::progress']

    if Options['help'] or not (suite and base_suite) and not export:
        usage()

    for s in suite, base_suite:
        if not export and not get_suite(s):
            utils.fubar('Invalid suite "%s"' % s)

    session = DBConn().session()

    if export:
        archive = session.query(Archive).filter_by(
            archive_name=Options['Archive']).one()
        exportpath = archive.changelog
        if exportpath:
            export_files(session, archive, exportpath, progress)
            generate_export_filelist(exportpath)
        else:
            utils.fubar('No changelog export path defined')
    elif binnmu:
        display_changes(get_binary_uploads(suite, base_suite, session), 3)
    else:
        display_changes(get_source_uploads(suite, base_suite, session), 2)

    session.commit()
Пример #13
0
def init(session):
    global cnf, Options

    cnf = Config()

    Arguments = [
        ("h", "help", "Show-New::Options::Help"),
        ("p", "html-path", "Show-New::HTMLPath", "HasArg"),
        ("q", "queue", "Show-New::Options::Queue", "HasArg"),
    ]

    for i in ["help"]:
        if not cnf.has_key("Show-New::Options::%s" % (i)):
            cnf["Show-New::Options::%s" % (i)] = ""

    changesnames = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Show-New::Options")

    if Options["help"]:
        usage()

    queue_names = Options.find("Queue", "new").split(",")
    uploads = (
        session.query(PolicyQueueUpload)
        .join(PolicyQueueUpload.policy_queue)
        .filter(PolicyQueue.queue_name.in_(queue_names))
        .join(PolicyQueueUpload.changes)
        .order_by(DBChange.source)
    )

    if len(changesnames) > 0:
        uploads = uploads.filter(DBChange.changesname.in_(changesnames))

    return uploads
Пример #14
0
    def init(self):
        cnf = Config()
        arguments = [('h', "help", "Update-DB::Options::Help"),
                     ("y", "yes", "Update-DB::Options::Yes")]
        for i in ["help"]:
            if not cnf.has_key("Update-DB::Options::%s" % (i)):
                cnf["Update-DB::Options::%s" % (i)] = ""

        arguments = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv)

        options = cnf.subtree("Update-DB::Options")
        if options["Help"]:
            self.usage()
        elif arguments:
            utils.warn("dak update-db takes no arguments.")
            self.usage(exit_code=1)

        try:
            if os.path.isdir(cnf["Dir::Lock"]):
                lock_fd = os.open(
                    os.path.join(cnf["Dir::Lock"], 'dinstall.lock'),
                    os.O_RDWR | os.O_CREAT)
                fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
            else:
                utils.warn("Lock directory doesn't exist yet - not locking")
        except IOError as e:
            if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[
                    e.errno] == 'EAGAIN':
                utils.fubar(
                    "Couldn't obtain lock; assuming another 'dak process-unchecked' is already running."
                )

        self.update_db()
Пример #15
0
def main():
    cnf = Config()

    arguments = [('h',"help", "%s::%s" % (options_prefix,"Help")),
                 ('j',"concurrency", "%s::%s" % (options_prefix,"Concurrency"),"HasArg"),
                 ('q',"quiet", "%s::%s" % (options_prefix,"Quiet")),
                 ('v',"verbose", "%s::%s" % (options_prefix,"Verbose")),
                ]

    args = apt_pkg.parse_commandline(cnf.Cnf, arguments,sys.argv)

    num_threads = 1

    if len(args) > 0:
        usage()

    if cnf.has_key("%s::%s" % (options_prefix,"Help")):
        usage()

    level=logging.INFO
    if cnf.has_key("%s::%s" % (options_prefix,"Quiet")):
        level=logging.ERROR

    elif cnf.has_key("%s::%s" % (options_prefix,"Verbose")):
        level=logging.DEBUG


    logging.basicConfig( level=level,
                         format='%(asctime)s %(levelname)s %(message)s',
                         stream = sys.stderr )

    if Config().has_key( "%s::%s" %(options_prefix,"Concurrency")):
        num_threads = int(Config()[ "%s::%s" %(options_prefix,"Concurrency")])

    ImportKnownChanges(num_threads)
Пример #16
0
def main ():
    global Cnf, db_files, waste, excluded

#    Cnf = utils.get_conf()

    Arguments = [('h',"help","Examine-Package::Options::Help"),
                 ('H',"html-output","Examine-Package::Options::Html-Output"),
                ]
    for i in [ "Help", "Html-Output", "partial-html" ]:
        if not Cnf.has_key("Examine-Package::Options::%s" % (i)):
            Cnf["Examine-Package::Options::%s" % (i)] = ""

    args = apt_pkg.parse_commandline(Cnf,Arguments,sys.argv)
    Options = Cnf.subtree("Examine-Package::Options")

    if Options["Help"]:
        usage()

    if Options["Html-Output"]:
        global use_html
        use_html = True

    stdout_fd = sys.stdout

    for f in args:
        try:
            if not Options["Html-Output"]:
                # Pipe output for each argument through less
                less_cmd = ("less", "-R", "-")
                less_process = daklib.daksubprocess.Popen(less_cmd, stdin=subprocess.PIPE, bufsize=0)
                less_fd = less_process.stdin
                # -R added to display raw control chars for colour
                sys.stdout = less_fd
            try:
                if f.endswith(".changes"):
                    check_changes(f)
                elif f.endswith(".deb") or f.endswith(".udeb"):
                    # default to unstable when we don't have a .changes file
                    # perhaps this should be a command line option?
                    print check_deb('unstable', f)
                elif f.endswith(".dsc"):
                    print check_dsc('unstable', f)
                else:
                    utils.fubar("Unrecognised file type: '%s'." % (f))
            finally:
                print output_package_relations()
                if not Options["Html-Output"]:
                    # Reset stdout here so future less invocations aren't FUBAR
                    less_fd.close()
                    less_process.wait()
                    sys.stdout = stdout_fd
        except IOError as e:
            if errno.errorcode[e.errno] == 'EPIPE':
                utils.warn("[examine-package] Caught EPIPE; skipping.")
                pass
            else:
                raise
        except KeyboardInterrupt:
            utils.warn("[examine-package] Caught C-c; skipping.")
            pass
Пример #17
0
def main():
    cnf = Config()

    Arguments = [('h', "help", "External-Overrides::Options::Help"),
                 ('f', 'force', 'External-Overrides::Options::Force')]

    args = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    try:
        Options = cnf.subtree("External-Overrides::Options")
    except KeyError:
        Options = {}

    if Options.has_key("Help"):
        usage()

    force = False
    if Options.has_key("Force") and Options["Force"]:
        force = True

    logger = daklog.Logger('external-overrides')

    command = args[0]
    if command in ('import', 'i'):
        external_overrides_import(args[1], args[2], args[3], sys.stdin, force)
    elif command in ('copy', 'c'):
        external_overrides_copy(args[1], args[2], force)
    else:
        print "E: Unknown commands."
Пример #18
0
def main():
    cnf = Config()

    arguments = [('h',"help", "%s::%s" % (options_prefix,"Help")),
                 ('q',"quiet", "%s::%s" % (options_prefix,"Quiet")),
                 ('v',"verbose", "%s::%s" % (options_prefix,"Verbose")),
                ]

    args = apt_pkg.parse_commandline(cnf.Cnf, arguments,sys.argv)

    num_threads = 1

    if len(args) > 0:
        usage(1)

    if cnf.has_key("%s::%s" % (options_prefix,"Help")):
        usage(0)

    level=logging.INFO
    if cnf.has_key("%s::%s" % (options_prefix,"Quiet")):
        level=logging.ERROR

    elif cnf.has_key("%s::%s" % (options_prefix,"Verbose")):
        level=logging.DEBUG


    logging.basicConfig( level=level,
                         format='%(asctime)s %(levelname)s %(message)s',
                         stream = sys.stderr )

    ImportNewFiles()
Пример #19
0
    def init(self):
        cnf = Config()
        arguments = [('h', "help", "Update-DB::Options::Help"),
                     ("y", "yes", "Update-DB::Options::Yes")]
        for i in ["help"]:
            key = "Update-DB::Options::%s" % i
            if key not in cnf:
                cnf[key] = ""

        arguments = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv)

        options = cnf.subtree("Update-DB::Options")
        if options["Help"]:
            self.usage()
        elif arguments:
            utils.warn("dak update-db takes no arguments.")
            self.usage(exit_code=1)

        try:
            if os.path.isdir(cnf["Dir::Lock"]):
                lock_fd = os.open(os.path.join(cnf["Dir::Lock"], 'daily.lock'),
                                  os.O_RDONLY | os.O_CREAT)
                fcntl.flock(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
            else:
                utils.warn("Lock directory doesn't exist yet - not locking")
        except IOError as e:
            if e.errno in (errno.EACCES, errno.EAGAIN):
                utils.fubar(
                    "Couldn't obtain lock, looks like archive is doing something, try again later."
                )

        self.update_db()
Пример #20
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    arguments = [('h', 'help', 'Export::Options::Help'),
                 ('a', 'all', 'Export::Options::All'),
                 ('c', 'copy', 'Export::Options::Copy'),
                 ('d', 'directory', 'Export::Options::Directory', 'HasArg'),
                 ('q', 'queue', 'Export::Options::Queue', 'HasArg')]

    cnf = Config()
    source_names = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
    options = cnf.subtree('Export::Options')

    if 'Help' in options or 'Queue' not in options:
        usage()
        sys.exit(0)

    session = DBConn().session()

    queue = session.query(PolicyQueue).filter_by(queue_name=options['Queue']).first()
    if queue is None:
        print("Unknown queue '{0}'".format(options['Queue']))
        sys.exit(1)
    uploads = session.query(PolicyQueueUpload).filter_by(policy_queue=queue)
    if 'All' not in options:
        uploads = uploads.filter(DBChange.source.in_(source_names))
    directory = options.get('Directory', '.')
    symlink = 'Copy' not in options

    for u in uploads:
        UploadCopy(u).export(directory, symlink=symlink, ignore_existing=True)
Пример #21
0
def main(argv=sys.argv):
    """Orchestrate a command-line invocation.

    This will run all the steps for a command-line invocation of
    apt-install-docs.
    """
    arguments = apt_pkg.parse_commandline(
        apt_pkg.config, [('h', "help", "help"), ('v', "version", "version"),
                         ('n', "dry-run", "APT::InstallDocs::DryRun"),
                         ('c', "config-file", "", "ConfigFile"),
                         ('o', "option", "", "ArbItem")], argv)

    if arguments or apt_pkg.config.find_b("help"):
        print("TODO(joelh)")
        return 0
    elif apt_pkg.config.find_b("version"):
        print("apt-install-docs " + __version__ + """
Copyright (C) 2021  Joel Ray Holveck

License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.""")
        return 0

    # Check to see whether we're just printing these, or also installing them.
    dry_run = apt_pkg.config.find_b("APT::InstallDocs::DryRun")

    cache = apt.cache.Cache(apt.progress.text.OpProgress())
    cache.open()
    find(cache)
    should_install = describe(cache, prompt=not dry_run)
    if should_install:
        install(cache)

    return 0
Пример #22
0
    def init(self):
        cnf = Config()
        arguments = [('h', "help", "Update-DB::Options::Help"),
                     ("y", "yes", "Update-DB::Options::Yes")]
        for i in ["help"]:
            key = "Update-DB::Options::%s" % i
            if key not in cnf:
                cnf[key] = ""

        arguments = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv)

        options = cnf.subtree("Update-DB::Options")
        if options["Help"]:
            self.usage()
        elif arguments:
            utils.warn("dak update-db takes no arguments.")
            self.usage(exit_code=1)

        try:
            if os.path.isdir(cnf["Dir::Lock"]):
                lock_fd = os.open(os.path.join(cnf["Dir::Lock"], 'daily.lock'), os.O_RDONLY | os.O_CREAT)
                fcntl.flock(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
            else:
                utils.warn("Lock directory doesn't exist yet - not locking")
        except IOError as e:
            if e.errno in (errno.EACCES, errno.EAGAIN):
                utils.fubar("Couldn't obtain lock, looks like archive is doing something, try again later.")

        self.update_db()
Пример #23
0
    def init (self):
        cnf = Config()
        arguments = [('h', "help", "Update-DB::Options::Help")]
        for i in [ "help" ]:
            if not cnf.has_key("Update-DB::Options::%s" % (i)):
                cnf["Update-DB::Options::%s" % (i)] = ""

        arguments = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv)

        options = cnf.subtree("Update-DB::Options")
        if options["Help"]:
            self.usage()
        elif arguments:
            utils.warn("dak update-db takes no arguments.")
            self.usage(exit_code=1)

        try:
            if os.path.isdir(cnf["Dir::Lock"]):
                lock_fd = os.open(os.path.join(cnf["Dir::Lock"], 'dinstall.lock'), os.O_RDWR | os.O_CREAT)
                fcntl.lockf(lock_fd, fcntl.LOCK_EX | fcntl.LOCK_NB)
            else:
                utils.warn("Lock directory doesn't exist yet - not locking")
        except IOError as e:
            if errno.errorcode[e.errno] == 'EACCES' or errno.errorcode[e.errno] == 'EAGAIN':
                utils.fubar("Couldn't obtain lock; assuming another 'dak process-unchecked' is already running.")

        self.update_db()
Пример #24
0
def main ():
    global Cnf

    Cnf = utils.get_conf()
    Arguments = [('h',"help","Stats::Options::Help")]
    for i in [ "help" ]:
        if not Cnf.has_key("Stats::Options::%s" % (i)):
            Cnf["Stats::Options::%s" % (i)] = ""

    args = apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)

    Options = Cnf.subtree("Stats::Options")
    if Options["Help"]:
        usage()

    if len(args) < 1:
        utils.warn("dak stats requires a MODE argument")
        usage(1)
    elif len(args) > 1:
        utils.warn("dak stats accepts only one MODE argument")
        usage(1)
    mode = args[0].lower()

    if mode == "arch-space":
        per_arch_space_use()
    elif mode == "pkg-nums":
        number_of_packages()
    elif mode == "daily-install":
        daily_install_stats()
    else:
        utils.warn("unknown mode '%s'" % (mode))
        usage(1)
Пример #25
0
def main(args):
    arguments = apt_pkg.parse_commandline(
        apt_pkg.config, [('h', "help", "help"), ('v', "version", "version"),
                         ('d', "cdrom", "Acquire::cdrom::mount", "HasArg"),
                         ('r', "rename", "APT::CDROM::Rename"),
                         ('m', "no-mount", "APT::CDROM::NoMount"),
                         ('f', "fast", "APT::CDROM::Fast"),
                         ('n', "just-print", "APT::CDROM::NoAct"),
                         ('n', "recon", "APT::CDROM::NoAct"),
                         ('n', "no-act", "APT::CDROM::NoAct"),
                         ('a', "thorough", "APT::CDROM::Thorough"),
                         ('c', "config-file", "", "ConfigFile"),
                         ('o', "option", "", "ArbItem")], args)

    if apt_pkg.config.find_b("help") or apt_pkg.config.find_b("version"):
        return show_help()

    progress = apt.progress.text.CdromProgress()
    cdrom = apt_pkg.Cdrom()

    if not arguments:
        return show_help()
    elif arguments[0] == 'add':
        cdrom.add(progress)
    elif arguments[0] == 'ident':
        cdrom.ident(progress)
    else:
        sys.stderr.write('E: Invalid operation %s\n' % arguments[0])
        return 1
Пример #26
0
def main():
    cnf = Config()
    Arguments = [
            ('h', "help",        "Copy-Installer::Options::Help"),
            ('s', "source",      "Copy-Installer::Options::Source",      "HasArg"),
            ('d', "destination", "Copy-Installer::Options::Destination", "HasArg"),
            ('n', "no-action",   "Copy-Installer::Options::No-Action"),
            ]
    for option in ["help", "source", "destination", "no-action"]:
        key = "Copy-Installer::Options::%s" % option
        if key not in cnf:
            cnf[key] = ""
    extra_arguments = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Copy-Installer::Options")

    if Options["Help"]:
        usage()
    if len(extra_arguments) != 1:
        usage(1)

    initializer = {"version": extra_arguments[0]}
    if Options["Source"] != "":
        initializer["source"] = Options["Source"]
    if Options["Destination"] != "":
        initializer["dest"] = Options["Destination"]

    copier = InstallerCopier(**initializer)
    print(copier.get_message())
    if Options["No-Action"]:
        print('Do nothing because --no-action has been set.')
    else:
        copier.do_copy()
        print('Installer has been copied successfully.')
Пример #27
0
def main():
    cnf = Config()

    Arguments = [('h', "help", "External-Overrides::Options::Help"),
                 ('f', 'force', 'External-Overrides::Options::Force')]

    args = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    try:
        Options = cnf.subtree("External-Overrides::Options")
    except KeyError:
        Options = {}

    if "Help" in Options:
        usage()

    force = False
    if "Force" in Options and Options["Force"]:
        force = True

    logger = daklog.Logger('external-overrides')

    command = args[0]
    if command in ('import', 'i'):
        external_overrides_import(args[1], args[2], args[3], sys.stdin, force)
    elif command in ('copy', 'c'):
        external_overrides_copy(args[1], args[2], force)
    else:
        print("E: Unknown commands.")
Пример #28
0
def main():
    global Options, Logger, Sections, Priorities

    cnf = Config()
    session = DBConn().session()

    Arguments = [('a', "automatic", "Process-New::Options::Automatic"),
                 ('b', "no-binaries", "Process-New::Options::No-Binaries"),
                 ('c', "comments", "Process-New::Options::Comments"),
                 ('h', "help", "Process-New::Options::Help"),
                 ('m', "manual-reject", "Process-New::Options::Manual-Reject",
                  "HasArg"), ('t', "trainee", "Process-New::Options::Trainee"),
                 ('q', 'queue', 'Process-New::Options::Queue', 'HasArg'),
                 ('n', "no-action", "Process-New::Options::No-Action")]

    changes_files = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)

    for i in [
            "automatic", "no-binaries", "comments", "help", "manual-reject",
            "no-action", "version", "trainee"
    ]:
        if not cnf.has_key("Process-New::Options::%s" % (i)):
            cnf["Process-New::Options::%s" % (i)] = ""

    queue_name = cnf.get('Process-New::Options::Queue', 'new')
    new_queue = session.query(PolicyQueue).filter_by(
        queue_name=queue_name).one()
    if len(changes_files) == 0:
        uploads = new_queue.uploads
    else:
        uploads = session.query(PolicyQueueUpload).filter_by(policy_queue=new_queue) \
            .join(DBChange).filter(DBChange.changesname.in_(changes_files)).all()

    Options = cnf.subtree("Process-New::Options")

    if Options["Help"]:
        usage()

    if not Options["No-Action"]:
        try:
            Logger = daklog.Logger("process-new")
        except CantOpenError as e:
            Options["Trainee"] = "True"

    Sections = Section_Completer(session)
    Priorities = Priority_Completer(session)
    readline.parse_and_bind("tab: complete")

    if len(uploads) > 1:
        sys.stderr.write("Sorting changes...\n")
        uploads = sort_uploads(new_queue, uploads, session,
                               Options["No-Binaries"])

    if Options["Comments"]:
        show_new_comments(uploads, session)
    else:
        for upload in uploads:
            do_pkg(upload, session)

    end()
Пример #29
0
def init():
    global Cnf, Options
    Cnf = utils.get_conf()
    Arguments = [('h', "help", "Show-Deferred::Options::Help"),
                 ("p", "link-path", "Show-Deferred::LinkPath", "HasArg"),
                 ("d", "deferred-queue", "Show-Deferred::DeferredQueue", "HasArg"),
                 ('r', "rrd", "Show-Deferred::Options::Rrd", "HasArg")]
    args = apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
    for i in ["help"]:
        key = "Show-Deferred::Options::%s" % i
        if key not in Cnf:
            Cnf[key] = ""
    for i, j in [("DeferredQueue", "--deferred-queue")]:
        key = "Show-Deferred::%s" % i
        if key not in Cnf:
            print("""%s is mandatory.
  set via config file or command-line option %s""" % (key, j), file=sys.stderr)

    Options = Cnf.subtree("Show-Deferred::Options")
    if Options["help"]:
        usage()

    # Initialise database connection
    DBConn()

    return args
Пример #30
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    arguments = [('h', 'help', 'Export::Options::Help'),
                 ('a', 'all', 'Export::Options::All'),
                 ('c', 'copy', 'Export::Options::Copy'),
                 ('d', 'directory', 'Export::Options::Directory', 'HasArg'),
                 ('q', 'queue', 'Export::Options::Queue', 'HasArg')]

    cnf = Config()
    source_names = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
    options = cnf.subtree('Export::Options')

    if 'Help' in options or 'Queue' not in options:
        usage()
        sys.exit(0)

    session = DBConn().session()

    queue = session.query(PolicyQueue).filter_by(queue_name=options['Queue']).first()
    if queue is None:
        print("Unknown queue '{0}'".format(options['Queue']))
        sys.exit(1)
    uploads = session.query(PolicyQueueUpload).filter_by(policy_queue=queue)
    if 'All' not in options:
        uploads = uploads.filter(DBChange.source.in_(source_names))
    directory = options.get('Directory', '.')
    symlink = 'Copy' not in options

    for u in uploads:
        UploadCopy(u).export(directory, symlink=symlink, ignore_existing=True)
Пример #31
0
def init():
    global Cnf, Options
    Cnf = utils.get_conf()
    Arguments = [('h', "help", "Show-Deferred::Options::Help"),
                 ("p", "link-path", "Show-Deferred::LinkPath", "HasArg"),
                 ("d", "deferred-queue", "Show-Deferred::DeferredQueue",
                  "HasArg"),
                 ('r', "rrd", "Show-Deferred::Options::Rrd", "HasArg")]
    args = apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
    for i in ["help"]:
        if not Cnf.has_key("Show-Deferred::Options::%s" % (i)):
            Cnf["Show-Deferred::Options::%s" % (i)] = ""
    for i, j in [("DeferredQueue", "--deferred-queue")]:
        if not Cnf.has_key("Show-Deferred::%s" % (i)):
            print >> sys.stderr, """Show-Deferred::%s is mandatory.
  set via config file or command-line option %s""" % (i, j)

    Options = Cnf.subtree("Show-Deferred::Options")
    if Options["help"]:
        usage()

    # Initialise database connection
    DBConn()

    return args
Пример #32
0
def init(session):
    global cnf, Options

    cnf = Config()

    Arguments = [('h', "help", "Show-New::Options::Help"),
                 ("p", "html-path", "Show-New::HTMLPath", "HasArg"),
                 ('q', 'queue', 'Show-New::Options::Queue', 'HasArg')]

    for i in ["help"]:
        key = "Show-New::Options::%s" % i
        if key not in cnf:
            cnf[key] = ""

    changesnames = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Show-New::Options")

    if Options["help"]:
        usage()

    queue_names = Options.find('Queue', 'new').split(',')
    uploads = session.query(PolicyQueueUpload) \
        .join(PolicyQueueUpload.policy_queue).filter(PolicyQueue.queue_name.in_(queue_names)) \
        .join(PolicyQueueUpload.changes).order_by(DBChange.source)

    if len(changesnames) > 0:
        uploads = uploads.filter(DBChange.changesname.in_(changesnames))

    return uploads
Пример #33
0
def main(args):
    arguments = apt_pkg.parse_commandline(apt_pkg.config,
                    [('h', "help", "help"),
                     ('v', "version", "version"),
                     ('d', "cdrom", "Acquire::cdrom::mount", "HasArg"),
                     ('r', "rename", "APT::CDROM::Rename"),
                     ('m', "no-mount", "APT::CDROM::NoMount"),
                     ('f', "fast", "APT::CDROM::Fast"),
                     ('n', "just-print", "APT::CDROM::NoAct"),
                     ('n', "recon", "APT::CDROM::NoAct"),
                     ('n', "no-act", "APT::CDROM::NoAct"),
                     ('a', "thorough", "APT::CDROM::Thorough"),
                     ('c', "config-file", "", "ConfigFile"),
                     ('o', "option", "", "ArbItem")], args)

    if apt_pkg.config.find_b("help") or apt_pkg.config.find_b("version"):
        return show_help()

    progress = apt.progress.text.CdromProgress()
    cdrom = apt_pkg.Cdrom()

    if not arguments:
        return show_help()
    elif arguments[0] == 'add':
        cdrom.add(progress)
    elif arguments[0] == 'ident':
        cdrom.ident(progress)
    else:
        sys.stderr.write('E: Invalid operation %s\n' % arguments[0])
        return 1
Пример #34
0
def main():
    cnf = Config()
    Arguments = [
            ('h', "help",        "Copy-Installer::Options::Help"),
            ('s', "source",      "Copy-Installer::Options::Source",      "HasArg"),
            ('d', "destination", "Copy-Installer::Options::Destination", "HasArg"),
            ('n', "no-action",   "Copy-Installer::Options::No-Action"),
            ]
    for option in ["help", "source", "destination", "no-action"]:
        key = "Copy-Installer::Options::%s" % option
        if key not in cnf:
            cnf[key] = ""
    extra_arguments = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Copy-Installer::Options")

    if Options["Help"]:
        usage()
    if len(extra_arguments) != 1:
        usage(1)

    initializer = {"version": extra_arguments[0]}
    if Options["Source"] != "":
        initializer["source"] = Options["Source"]
    if Options["Destination"] != "":
        initializer["dest"] = Options["Destination"]

    copier = InstallerCopier(**initializer)
    print(copier.get_message())
    if Options["No-Action"]:
        print('Do nothing because --no-action has been set.')
    else:
        copier.do_copy()
        print('Installer has been copied successfully.')
Пример #35
0
def main():
    """Perform administrative work on the dak database"""
    global dryrun
    Cnf = utils.get_conf()
    arguments = [('h', "help", "Admin::Options::Help"),
                 ('n', "dry-run", "Admin::Options::Dry-Run")]
    for i in ["help", "dry-run"]:
        key = "Admin::Options::%s" % i
        if key not in Cnf:
            Cnf[key] = ""

    arguments = apt_pkg.parse_commandline(Cnf, arguments, sys.argv)

    options = Cnf.subtree("Admin::Options")
    if options["Help"] or len(arguments) < 1:
        usage()
    if options["Dry-Run"]:
        dryrun = True

    subcommand = str(arguments[0])

    if subcommand in dispatch:
        dispatch[subcommand](arguments)
    else:
        die("E: Unknown command")
Пример #36
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    arguments = [
        ('h', 'help', 'Import::Options::Help'),
        ('a', 'add-overrides', 'Import::Options::AddOverrides'),
        ('c', 'changed-by', 'Import::Options::ChangedBy', 'HasArg'),
        ('D', 'dump', 'Import::Options::Dump', 'HasArg'),
        ('E', 'export-dump', 'Import::Options::Export'),
        ('s', 'ignore-signature', 'Import::Options::IgnoreSignature'),
        ]

    cnf = daklib.config.Config()
    cnf['Import::Options::Dummy'] = ''
    argv = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
    options = cnf.subtree('Import::Options')

    if 'Help' in options or len(argv) < 2:
        usage()
        sys.exit(0)

    suite_name = argv[0]
    component_name = argv[1]

    add_overrides = options.find_b('AddOverrides')
    require_signature = not options.find_b('IgnoreSignature')
    changed_by = options.find('ChangedBy') or None

    log = daklib.daklog.Logger('import')

    with daklib.archive.ArchiveTransaction() as transaction:
        session = transaction.session
        suite = session.query(Suite).filter_by(suite_name=suite_name).one()
        component = session.query(Component).filter_by(component_name=component_name).one()
        keyrings = session.query(Keyring).filter_by(active=True).order_by(Keyring.priority)
        keyring_files = [ k.keyring_name for k in keyrings ]

        dump = options.find('Dump') or None
        if options.find_b('Export'):
            export_dump(transaction, suite, component)
            transaction.rollback()
        elif dump is not None:
            with open(dump, 'r') as fh:
                import_dump(log, transaction, suite, component, fh, keyring_files,
                            require_signature=require_signature, add_overrides=add_overrides)
            transaction.commit()
        else:
            files = argv[2:]
            for f in files:
                directory, filename = os.path.split(os.path.abspath(f))
                hashed_file = daklib.upload.HashedFile.from_file(directory, filename)
                import_file(log, transaction, suite, component, directory, hashed_file,
                            changed_by=changed_by,
                            keyrings=keyring_files, require_signature=require_signature,
                            add_overrides=add_overrides)
            transaction.commit()

    log.close()
Пример #37
0
Файл: ls.py Проект: Debian/dak
def main():
    cnf = Config()

    Arguments = [('a', "architecture", "Ls::Options::Architecture", "HasArg"),
                 ('b', "binarytype", "Ls::Options::BinaryType", "HasArg"),
                 ('c', "component", "Ls::Options::Component", "HasArg"),
                 ('f', "format", "Ls::Options::Format", "HasArg"),
                 ('g', "greaterorequal", "Ls::Options::GreaterOrEqual"),
                 ('G', "greaterthan", "Ls::Options::GreaterThan"),
                 ('r', "regex", "Ls::Options::Regex"),
                 ('s', "suite", "Ls::Options::Suite", "HasArg"),
                 ('S', "source-and-binary", "Ls::Options::Source-And-Binary"),
                 ('h', "help", "Ls::Options::Help")]
    for i in ["architecture", "binarytype", "component", "format",
               "greaterorequal", "greaterthan", "regex", "suite",
               "source-and-binary", "help"]:
        key = "Ls::Options::%s" % i
        if key not in cnf:
            cnf[key] = ""

    packages = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Ls::Options")

    if Options["Help"]:
        usage()
    if not packages:
        utils.fubar("need at least one package name as an argument.")

    # Handle buildd maintenance helper options
    if Options["GreaterOrEqual"] or Options["GreaterThan"]:
        if Options["GreaterOrEqual"] and Options["GreaterThan"]:
            utils.fubar("-g/--greaterorequal and -G/--greaterthan are mutually exclusive.")
        if not Options["Suite"]:
            Options["Suite"] = "unstable"

    kwargs = dict()

    if Options["Regex"]:
        kwargs['regex'] = True
    if Options["Source-And-Binary"]:
        kwargs['source_and_binary'] = True
    if Options["Suite"]:
        kwargs['suites'] = utils.split_args(Options['Suite'])
    if Options["Architecture"]:
        kwargs['architectures'] = utils.split_args(Options['Architecture'])
    if Options['BinaryType']:
        kwargs['binary_types'] = utils.split_args(Options['BinaryType'])
    if Options['Component']:
        kwargs['components'] = utils.split_args(Options['Component'])

    if Options['Format']:
        kwargs['format'] = Options['Format']
    if Options['GreaterOrEqual']:
        kwargs['highest'] = '>='
    elif Options['GreaterThan']:
        kwargs['highest'] = '>>'

    for line in list_packages(packages, **kwargs):
        print(line)
Пример #38
0
def main():
    global Options, Logger

    cnf = Config()

    for i in ["Help"]:
        key = "Manage-External-Signature-Requests::Options::{}".format(i)
        if key not in cnf:
            cnf[key] = ""

    Arguments = [('h', "help",
                  "Manage-External-Signature-Requests::Options::Help")]

    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Manage-External-Signature-Requests::Options")

    if Options["Help"]:
        usage()

    Logger = daklog.Logger('manage-external-signature-requests')

    if 'External-Signature-Requests' not in cnf:
        print("DAK not configured to handle external signature requests")
        return

    config = cnf.subtree('External-Signature-Requests')

    session = DBConn().session()

    export_external_signature_requests(session, config['Export'])

    if 'ExportSigningKeys' in config:
        args = {
            'pubring': cnf.get('Dinstall::SigningPubKeyring') or None,
            'secring': cnf.get('Dinstall::SigningKeyring') or None,
            'homedir': cnf.get('Dinstall::SigningHomedir') or None,
            'passphrase_file': cnf.get('Dinstall::SigningPassphraseFile')
            or None,
        }
        sign_external_signature_requests(
            session, config['Export'], config.value_list('ExportSigningKeys'),
            args)

    session.close()

    Logger.close()
Пример #39
0
def main():
    cnf = Config()
    Arguments = [('h', "help", "Make-Overrides::Options::Help")]
    for i in ["help"]:
        key = "Make-Overrides::Options::%s" % i
        if key not in cnf:
            cnf[key] = ""
    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Make-Overrides::Options")
    if Options["Help"]:
        usage()

    d = DBConn()
    session = d.session()

    for suite in session.query(Suite).filter(Suite.overrideprocess == True):  # noqa:E712
        if suite.untouchable:
            print("Skipping %s as it is marked as untouchable" % suite.suite_name)
            continue

        print("Processing %s..." % (suite.suite_name), file=sys.stderr)
        override_suite = suite.overridecodename or suite.codename

        for component in session.query(Component).all():
            for otype in session.query(OverrideType).all():
                otype_name = otype.overridetype
                cname = component.component_name

                # TODO: Stick suffix info in database (or get rid of it)
                if otype_name == "deb":
                    suffix = ""
                elif otype_name == "udeb":
                    if cname == "contrib":
                        continue # Ick2
                    suffix = ".debian-installer"
                elif otype_name == "dsc":
                    suffix = ".src"
                else:
                    utils.fubar("Don't understand OverrideType %s" % otype.overridetype)

                cname = cname.replace('/', '_')
                filename = os.path.join(cnf["Dir::Override"], "override.%s.%s%s" % (override_suite, cname, suffix))

                output_file = utils.open_file(filename, 'w')
                do_list(output_file, suite, component, otype, session)
                output_file.close()
Пример #40
0
def main():
    Cnf = utils.get_conf()
    Arguments = [('h','help','Make-Changelog::Options::Help'),
                 ('a','archive','Make-Changelog::Options::Archive','HasArg'),
                 ('s','suite','Make-Changelog::Options::Suite','HasArg'),
                 ('b','base-suite','Make-Changelog::Options::Base-Suite','HasArg'),
                 ('n','binnmu','Make-Changelog::Options::binNMU'),
                 ('e','export','Make-Changelog::Options::export'),
                 ('p','progress','Make-Changelog::Options::progress')]

    for i in ['help', 'suite', 'base-suite', 'binnmu', 'export', 'progress']:
        if not Cnf.has_key('Make-Changelog::Options::%s' % (i)):
            Cnf['Make-Changelog::Options::%s' % (i)] = ''

    apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
    Options = Cnf.subtree('Make-Changelog::Options')
    suite = Cnf['Make-Changelog::Options::Suite']
    base_suite = Cnf['Make-Changelog::Options::Base-Suite']
    binnmu = Cnf['Make-Changelog::Options::binNMU']
    export = Cnf['Make-Changelog::Options::export']
    progress = Cnf['Make-Changelog::Options::progress']

    if Options['help'] or not (suite and base_suite) and not export:
        usage()

    for s in suite, base_suite:
        if not export and not get_suite(s):
            utils.fubar('Invalid suite "%s"' % s)

    session = DBConn().session()

    if export:
        archive = session.query(Archive).filter_by(archive_name=Options['Archive']).one()
        exportpath = archive.changelog
        if exportpath:
            export_files(session, archive, exportpath, progress)
            generate_export_filelist(exportpath)
        else:
            utils.fubar('No changelog export path defined')
    elif binnmu:
        display_changes(get_binary_uploads(suite, base_suite, session), 3)
    else:
        display_changes(get_source_uploads(suite, base_suite, session), 2)

    session.commit()
Пример #41
0
def main():
    global Options, Logger, Sections, Priorities

    cnf = Config()
    session = DBConn().session()

    Arguments = [('a', "automatic", "Process-New::Options::Automatic"),
                 ('b', "no-binaries", "Process-New::Options::No-Binaries"),
                 ('c', "comments", "Process-New::Options::Comments"),
                 ('h', "help", "Process-New::Options::Help"),
                 ('m', "manual-reject", "Process-New::Options::Manual-Reject", "HasArg"),
                 ('t', "trainee", "Process-New::Options::Trainee"),
                 ('q', 'queue', 'Process-New::Options::Queue', 'HasArg'),
                 ('n', "no-action", "Process-New::Options::No-Action")]

    changes_files = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)

    for i in ["automatic", "no-binaries", "comments", "help", "manual-reject", "no-action", "version", "trainee"]:
        key = "Process-New::Options::%s" % i
        if key not in cnf:
            cnf[key] = ""

    queue_name = cnf.get('Process-New::Options::Queue', 'new')
    new_queue = session.query(PolicyQueue).filter_by(queue_name=queue_name).one()
    if len(changes_files) == 0:
        uploads = new_queue.uploads
    else:
        uploads = session.query(PolicyQueueUpload).filter_by(policy_queue=new_queue) \
            .join(DBChange).filter(DBChange.changesname.in_(changes_files)).all()

    Options = cnf.subtree("Process-New::Options")

    if Options["Help"]:
        usage()

    if not Options["No-Action"]:
        try:
            Logger = daklog.Logger("process-new")
        except CantOpenError as e:
            Options["Trainee"] = "True"

    Sections = Section_Completer(session)
    Priorities = Priority_Completer(session)
    readline.parse_and_bind("tab: complete")

    if len(uploads) > 1:
        print("Sorting changes...", file=sys.stderr)
        uploads = sort_uploads(new_queue, uploads, session, Options["No-Binaries"])

    if Options["Comments"]:
        show_new_comments(uploads, session)
    else:
        for upload in uploads:
            do_pkg(upload, session)

    end()
Пример #42
0
def main():
    cnf = Config()

    Arguments = [('h',"help","DEP11::Options::Help"),
                 ('s',"suite","DEP11::Options::Suite", "HasArg"),
                 ('e',"expire","DEP11::Options::ExpireCache"),
                 ('h',"write-hints","DEP11::Options::WriteHints"),
                 ]
    for i in ["help", "suite", "ExpireCache"]:
        if not cnf.has_key("DEP11::Options::%s" % (i)):
            cnf["DEP11::Options::%s" % (i)] = ""

    arguments = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("DEP11::Options")

    if Options["Help"]:
        usage()
        return

    suitename = Options["Suite"]
    if not suitename:
        print("You need to specify a suite!")
        sys.exit(1)

    # check if we have some important config options set
    if not cnf.has_key("Dir::MetaInfo"):
        print("You need to specify a metadata export directory (Dir::MetaInfo)")
        sys.exit(1)
    if not cnf.has_key("DEP11::Url"):
        print("You need to specify a metadata public web URL (DEP11::Url)")
        sys.exit(1)
    if not cnf.has_key("DEP11::IconSizes"):
        print("You need to specify a list of allowed icon-sizes (DEP11::IconSizes)")
        sys.exit(1)
    if Options["WriteHints"] and not cnf.has_key("Dir::MetaInfoHints"):
        print("You need to specify an export directory for DEP-11 hints files (Dir::MetaInfoHints)")
        sys.exit(1)

    logger = daklog.Logger('generate-metadata')

    from daklib.dbconn import Component, DBConn, get_suite, Suite
    session = DBConn().session()
    suite = get_suite(suitename.lower(), session)

    if Options["ExpireCache"]:
        expire_dep11_data_cache(session, suitename, logger)

    process_suite(session, suite, logger)
    # export database content as Components-<arch>.xz YAML documents
    write_component_files(session, suite, logger)

    if Options["WriteHints"]:
        write_hints_files(session, suite, logger)

    # we're done
    logger.close()
Пример #43
0
def main():
    global Options, Logger

    cnf = Config()
    session = DBConn().session()

    Arguments = [('h', "help", "Process-Policy::Options::Help"),
                 ('n', "no-action", "Process-Policy::Options::No-Action")]

    for i in ["help", "no-action"]:
        key = "Process-Policy::Options::%s" % i
        if key not in cnf:
            cnf[key] = ""

    queue_name = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)

    if len(queue_name) != 1:
        print("E: Specify exactly one policy queue")
        sys.exit(1)

    queue_name = queue_name[0]

    Options = cnf.subtree("Process-Policy::Options")

    if Options["Help"]:
        usage()

    Logger = daklog.Logger("process-policy")
    if not Options["No-Action"]:
        urgencylog = UrgencyLog()

    with ArchiveTransaction() as transaction:
        session = transaction.session
        try:
            pq = session.query(PolicyQueue).filter_by(
                queue_name=queue_name).one()
        except NoResultFound:
            print("E: Cannot find policy queue %s" % queue_name)
            sys.exit(1)

        commentsdir = os.path.join(pq.path, 'COMMENTS')
        # The comments stuff relies on being in the right directory
        os.chdir(pq.path)

        do_comments(commentsdir, pq, "REJECT.", "REJECTED.", "NOTOK",
                    comment_reject, transaction)
        do_comments(commentsdir, pq, "ACCEPT.", "ACCEPTED.", "OK",
                    comment_accept, transaction)
        do_comments(commentsdir, pq, "ACCEPTED.", "ACCEPTED.", "OK",
                    comment_accept, transaction)

        remove_unreferenced_binaries(pq, transaction)
        remove_unreferenced_sources(pq, transaction)

    if not Options['No-Action']:
        urgencylog.close()
Пример #44
0
def main():
    global Options, Logger, Sections, Priorities

    cnf = Config()
    session = DBConn().session()

    Arguments = [('a',"automatic","Process-New::Options::Automatic"),
                 ('b',"no-binaries","Process-New::Options::No-Binaries"),
                 ('c',"comments","Process-New::Options::Comments"),
                 ('h',"help","Process-New::Options::Help"),
                 ('m',"manual-reject","Process-New::Options::Manual-Reject", "HasArg"),
                 ('t',"trainee","Process-New::Options::Trainee"),
                 ('n',"no-action","Process-New::Options::No-Action")]

    for i in ["automatic", "no-binaries", "comments", "help", "manual-reject", "no-action", "version", "trainee"]:
        if not cnf.has_key("Process-New::Options::%s" % (i)):
            cnf["Process-New::Options::%s" % (i)] = ""

    changes_files = apt_pkg.parse_commandline(cnf.Cnf,Arguments,sys.argv)
    if len(changes_files) == 0:
        new_queue = get_policy_queue('new', session );
        changes_paths = [ os.path.join(new_queue.path, j) for j in utils.get_changes_files(new_queue.path) ]
    else:
        changes_paths = [ os.path.abspath(j) for j in changes_files ]

    Options = cnf.subtree("Process-New::Options")

    if Options["Help"]:
        usage()

    if not Options["No-Action"]:
        try:
            Logger = daklog.Logger("process-new")
        except CantOpenError as e:
            Options["Trainee"] = "True"

    Sections = Section_Completer(session)
    Priorities = Priority_Completer(session)
    readline.parse_and_bind("tab: complete")

    if len(changes_paths) > 1:
        sys.stderr.write("Sorting changes...\n")
    changes_files = sort_changes(changes_paths, session, Options["No-Binaries"])

    if Options["Comments"]:
        show_new_comments(changes_files, session)
    else:
        for changes_file in changes_files:
            changes_file = utils.validate_changes_file_arg(changes_file, 0)
            if not changes_file:
                continue
            print "\n" + os.path.basename(changes_file)

            do_pkg (changes_file, session)

    end()
Пример #45
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    arguments = [('h', 'help', 'Process-Commands::Options::Help'),
                 ('d', 'directory', 'Process-Commands::Options::Directory', 'HasArg')]

    cnf = Config()
    cnf['Process-Commands::Options::Dummy'] = ''
    filenames = apt_pkg.parse_commandline(cnf.Cnf, arguments, argv)
    options = cnf.subtree('Process-Commands::Options')

    if 'Help' in options or (len(filenames) == 0 and 'Directory' not in options):
        usage()
        sys.exit(0)

    log = Logger('command')

    now = datetime.datetime.now()
    donedir = os.path.join(cnf['Dir::Done'], now.strftime('%Y/%m/%d'))
    rejectdir = cnf['Dir::Reject']

    if len(filenames) == 0:
        filenames = [ fn for fn in os.listdir(options['Directory']) if fn.endswith('.dak-commands') ]

    for fn in filenames:
        basename = os.path.basename(fn)
        if not fn.endswith('.dak-commands'):
            log.log(['unexpected filename', basename])
            continue

        with open(fn, 'r') as fh:
            data = fh.read()

        try:
            command = CommandFile(basename, data, log)
            command.evaluate()
        except:
            created = os.stat(fn).st_mtime
            now = time.time()
            too_new = (now - created < int(cnf.get('Dinstall::SkipTime', '60')))
            if too_new:
                log.log(['skipped (too new)'])
                continue
            log.log(['reject', basename])
            dst = find_next_free(os.path.join(rejectdir, basename))
        else:
            log.log(['done', basename])
            dst = find_next_free(os.path.join(donedir, basename))

        with FilesystemTransaction() as fs:
            fs.unlink(fn)
            fs.create(dst, mode=0o644).write(data)
            fs.commit()

    log.close()
Пример #46
0
def main():
    global Options, Logger
    cnf = Config()
    Arguments = [('h', "help", "Obsolete::Options::Help"),
                 ('s', "suite", "Obsolete::Options::Suite", "HasArg"),
                 ('n', "no-action", "Obsolete::Options::No-Action"),
                 ('f', "force", "Obsolete::Options::Force")]
    cnf['Obsolete::Options::Help'] = ''
    cnf['Obsolete::Options::No-Action'] = ''
    cnf['Obsolete::Options::Force'] = ''
    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Obsolete::Options")
    if Options['Help']:
        usage()

    if not Options['No-Action']:
        Logger = daklog.Logger("dominate")
    session = DBConn().session()

    suites_query = (session.query(Suite).order_by(
        Suite.suite_name).filter(~exists().where(
            Suite.suite_id == PolicyQueue.suite_id)))
    if 'Suite' in Options:
        suites_query = suites_query.filter(
            Suite.suite_name.in_(utils.split_args(Options['Suite'])))
    if not Options['Force']:
        suites_query = suites_query.filter_by(untouchable=False)
    suites = suites_query.all()

    assocs = list(retrieve_associations(suites, session))

    if Options['No-Action']:
        headers = ('source package', 'source version', 'package', 'version',
                   'arch', 'suite', 'id')
        print(tabulate(assocs, headers, tablefmt="orgtbl"))
        session.rollback()

    else:
        delete_associations(assocs, session)
        session.commit()

    if Logger:
        Logger.close()
Пример #47
0
def init():
    """
    Initialize. Sets up database connection, parses commandline arguments.

    @attention: This function may run B{within sudo}

    """
    global Cnf, Options

    apt_pkg.init()

    Cnf = utils.get_conf()

    Arguments = [('a', "automatic", "Edit-Transitions::Options::Automatic"),
                 ('h', "help", "Edit-Transitions::Options::Help"),
                 ('e', "edit", "Edit-Transitions::Options::Edit"),
                 ('i', "import",
                  "Edit-Transitions::Options::Import", "HasArg"),
                 ('c', "check", "Edit-Transitions::Options::Check"),
                 ('s', "sudo", "Edit-Transitions::Options::Sudo"),
                 ('n', "no-action", "Edit-Transitions::Options::No-Action")]

    for i in [
            "automatic", "help", "no-action", "edit", "import", "check", "sudo"
    ]:
        key = "Edit-Transitions::Options::%s" % i
        if key not in Cnf:
            Cnf[key] = ""

    apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)

    Options = Cnf.subtree("Edit-Transitions::Options")

    if Options["help"]:
        usage()

    username = utils.getusername()
    if username != "dak":
        print "Non-dak user: %s" % username
        Options["sudo"] = "y"

    # Initialise DB connection
    DBConn()
Пример #48
0
def main():
    global Options, Logger
    cnf = Config()
    Arguments = [('h', "help",      "Obsolete::Options::Help"),
                 ('s', "suite",     "Obsolete::Options::Suite", "HasArg"),
                 ('n', "no-action", "Obsolete::Options::No-Action"),
                 ('f', "force",     "Obsolete::Options::Force")]
    cnf['Obsolete::Options::Help'] = ''
    cnf['Obsolete::Options::No-Action'] = ''
    cnf['Obsolete::Options::Force'] = ''
    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Obsolete::Options")
    if Options['Help']:
        usage()

    if not Options['No-Action']:
        Logger = daklog.Logger("dominate")
    session = DBConn().session()

    suites_query = (session
            .query(Suite)
            .order_by(Suite.suite_name)
            .filter(~exists().where(Suite.suite_id == PolicyQueue.suite_id)))
    if 'Suite' in Options:
        suites_query = suites_query.filter(Suite.suite_name.in_(utils.split_args(Options['Suite'])))
    if not Options['Force']:
        suites_query = suites_query.filter_by(untouchable=False)
    suites = suites_query.all()

    assocs = list(retrieve_associations(suites, session))

    if Options['No-Action']:
        headers = ('source package', 'source version', 'package', 'version', 'arch', 'suite', 'id')
        print((tabulate(assocs, headers, tablefmt="orgtbl")))
        session.rollback()

    else:
        delete_associations(assocs, session)
        session.commit()

    if Logger:
        Logger.close()
def main():
    global Options, Logger

    cnf = Config()

    for i in ["Help"]:
        key = "Manage-External-Signature-Requests::Options::{}".format(i)
        if key not in cnf:
            cnf[key] = ""

    Arguments = [('h', "help", "Manage-External-Signature-Requests::Options::Help")]

    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Manage-External-Signature-Requests::Options")

    if Options["Help"]:
        usage()

    Logger = daklog.Logger('manage-external-signature-requests')

    if 'External-Signature-Requests' not in cnf:
        print("DAK not configured to handle external signature requests")
        return

    config = cnf.subtree('External-Signature-Requests')

    session = DBConn().session()

    export_external_signature_requests(session, config['Export'])

    if 'ExportSigningKeys' in config:
        args = {
            'pubring': cnf.get('Dinstall::SigningPubKeyring') or None,
            'secring': cnf.get('Dinstall::SigningKeyring') or None,
            'homedir': cnf.get('Dinstall::SigningHomedir') or None,
            'passphrase_file': cnf.get('Dinstall::SigningPassphraseFile') or None,
        }
        sign_external_signature_requests(session, config['Export'], config.value_list('ExportSigningKeys'), args)

    session.close()

    Logger.close()
Пример #50
0
def main ():
    global db_files, waste, excluded

    cnf = Config()

    Arguments = [('h',"help","Check-Archive::Options::Help")]
    for i in [ "help" ]:
        if not cnf.has_key("Check-Archive::Options::%s" % (i)):
            cnf["Check-Archive::Options::%s" % (i)] = ""

    args = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)

    Options = cnf.subtree("Check-Archive::Options")
    if Options["Help"]:
        usage()

    if len(args) < 1:
        utils.warn("dak check-archive requires at least one argument")
        usage(1)
    elif len(args) > 1:
        utils.warn("dak check-archive accepts only one argument")
        usage(1)
    mode = args[0].lower()

    # Initialize DB
    DBConn()

    if mode == "checksums":
        check_checksums()
    elif mode == "files":
        check_files()
    elif mode == "dsc-syntax":
        check_dscs()
    elif mode == "missing-overrides":
        check_override()
    elif mode == "source-in-one-dir":
        check_source_in_one_dir()
    elif mode == "timestamps":
        check_timestamps()
    elif mode == "files-in-dsc":
        check_files_in_dsc()
    elif mode == "validate-indices":
        check_indices_files_exist()
    elif mode == "files-not-symlinks":
        check_files_not_symlinks()
    elif mode == "validate-builddeps":
        check_build_depends()
    elif mode == "add-missing-source-checksums":
        add_missing_source_checksums()
    elif mode == "fix-checksums":
        fix_checksums()
    else:
        utils.warn("unknown mode '%s'" % (mode))
        usage(1)
Пример #51
0
def main():
    global db_files, waste, excluded

    cnf = Config()

    Arguments = [('h', "help", "Check-Archive::Options::Help")]
    for i in ["help"]:
        if not cnf.has_key("Check-Archive::Options::%s" % (i)):
            cnf["Check-Archive::Options::%s" % (i)] = ""

    args = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)

    Options = cnf.subtree("Check-Archive::Options")
    if Options["Help"]:
        usage()

    if len(args) < 1:
        utils.warn("dak check-archive requires at least one argument")
        usage(1)
    elif len(args) > 1:
        utils.warn("dak check-archive accepts only one argument")
        usage(1)
    mode = args[0].lower()

    # Initialize DB
    DBConn()

    if mode == "checksums":
        check_checksums()
    elif mode == "files":
        check_files()
    elif mode == "dsc-syntax":
        check_dscs()
    elif mode == "missing-overrides":
        check_override()
    elif mode == "source-in-one-dir":
        check_source_in_one_dir()
    elif mode == "timestamps":
        check_timestamps()
    elif mode == "files-in-dsc":
        check_files_in_dsc()
    elif mode == "validate-indices":
        check_indices_files_exist()
    elif mode == "files-not-symlinks":
        check_files_not_symlinks()
    elif mode == "validate-builddeps":
        check_build_depends()
    elif mode == "add-missing-source-checksums":
        add_missing_source_checksums()
    elif mode == "fix-checksums":
        fix_checksums()
    else:
        utils.warn("unknown mode '%s'" % (mode))
        usage(1)
Пример #52
0
def main():
    Cnf = utils.get_conf()
    cnf = Config()
    Arguments = [('h','help','Make-Changelog::Options::Help'),
                 ('s','suite','Make-Changelog::Options::Suite','HasArg'),
                 ('b','base-suite','Make-Changelog::Options::Base-Suite','HasArg'),
                 ('n','binnmu','Make-Changelog::Options::binNMU'),
                 ('e','export','Make-Changelog::Options::export')]

    for i in ['help', 'suite', 'base-suite', 'binnmu', 'export']:
        if not Cnf.has_key('Make-Changelog::Options::%s' % (i)):
            Cnf['Make-Changelog::Options::%s' % (i)] = ''

    apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)
    Options = Cnf.subtree('Make-Changelog::Options')
    suite = Cnf['Make-Changelog::Options::Suite']
    base_suite = Cnf['Make-Changelog::Options::Base-Suite']
    binnmu = Cnf['Make-Changelog::Options::binNMU']
    export = Cnf['Make-Changelog::Options::export']

    if Options['help'] or not (suite and base_suite) and not export:
        usage()

    for s in suite, base_suite:
        if not export and not get_suite(s):
            utils.fubar('Invalid suite "%s"' % s)

    session = DBConn().session()

    if export:
        if cnf.exportpath:
            exportpath = os.path.join(Cnf['Dir::Export'], cnf.exportpath)
            export_files(session, Cnf['Dir::Pool'], exportpath)
        else:
            utils.fubar('No changelog export path defined')
    elif binnmu:
        display_changes(get_binary_uploads(suite, base_suite, session), 3)
    else:
        display_changes(get_source_uploads(suite, base_suite, session), 2)

    session.commit()
Пример #53
0
def main():
    global Options, Logger

    cnf = Config()

    for i in ["Help", "Incoming", "No-Action", "Verbose"]:
        key = "Clean-Queues::Options::%s" % i
        if key not in cnf:
            cnf[key] = ""
    if "Clean-Queues::Options::Days" not in cnf:
        cnf["Clean-Queues::Options::Days"] = "14"

    Arguments = [('h', "help", "Clean-Queues::Options::Help"),
                 ('d', "days", "Clean-Queues::Options::Days", "IntLevel"),
                 ('i', "incoming", "Clean-Queues::Options::Incoming",
                  "HasArg"),
                 ('n', "no-action", "Clean-Queues::Options::No-Action"),
                 ('v', "verbose", "Clean-Queues::Options::Verbose")]

    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Clean-Queues::Options")

    if Options["Help"]:
        usage()

    Logger = daklog.Logger('clean-queues', Options['No-Action'])

    init(cnf)

    if Options["Verbose"]:
        print("Processing incoming...")
    flush_orphans()

    reject = cnf["Dir::Reject"]
    if os.path.exists(reject) and os.path.isdir(reject):
        if Options["Verbose"]:
            print("Processing reject directory...")
        os.chdir(reject)
        flush_old()

    Logger.close()
Пример #54
0
def main():
    global Options, Logger
    cnf = Config()
    Arguments = [('h', "help",      "Obsolete::Options::Help"),
                 ('s', "suite",     "Obsolete::Options::Suite", "HasArg"),
                 ('n', "no-action", "Obsolete::Options::No-Action"),
                 ('f', "force",     "Obsolete::Options::Force")]
    cnf['Obsolete::Options::Help'] = ''
    cnf['Obsolete::Options::No-Action'] = ''
    cnf['Obsolete::Options::Force'] = ''
    apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Obsolete::Options")
    if Options['Help']:
        usage()
    if 'Suite' not in Options:
        query_suites = DBConn().session().query(Suite)
        suites = [suite.suite_name for suite in query_suites]
        cnf['Obsolete::Options::Suite'] = str(','.join(suites))

    if not Options['No-Action']:
       Logger = daklog.Logger("dominate")
    session = DBConn().session()
    for suite_name in utils.split_args(Options['Suite']):
        suite = session.query(Suite).filter_by(suite_name = suite_name).one()

        # Skip policy queues. We don't want to remove obsolete packages from those.
        policy_queue = session.query(PolicyQueue).filter_by(suite=suite).first()
        if policy_queue is not None:
            continue

        if not suite.untouchable or Options['Force']:
            doDaDoDa(suite.suite_id, session)
    if Options['No-Action']:
        session.rollback()
    else:
        session.commit()
    if Logger:
        Logger.close()
Пример #55
0
def main():
    global Options, Logger

    cnf = Config()

    for i in ["Help", "No-Action", "All"]:
        if not cnf.has_key("Manage-Build-Queues::Options::%s" % (i)):
            cnf["Manage-Build-Queues::Options::%s" % (i)] = ""

    Arguments = [('h', "help", "Manage-Build-Queues::Options::Help"),
                 ('n', "no-action", "Manage-Build-Queues::Options::No-Action"),
                 ('a', "all", "Manage-Build-Queues::Options::All")]

    queue_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Manage-Build-Queues::Options")

    if Options["Help"]:
        usage()

    Logger = daklog.Logger('manage-build-queues', Options['No-Action'])

    starttime = datetime.now()

    session = DBConn().session()

    with ArchiveTransaction() as transaction:
        session = transaction.session
        if Options['All']:
            if len(queue_names) != 0:
                print "E: Cannot use both -a and a queue name"
                sys.exit(1)
            queues = session.query(BuildQueue)
        else:
            queues = session.query(BuildQueue).filter(
                BuildQueue.queue_name.in_(queue_names))

        for q in queues:
            Logger.log([
                'cleaning queue %s using datetime %s' %
                (q.queue_name, starttime)
            ])
            clean(q, transaction, now=starttime)
        if not Options['No-Action']:
            transaction.commit()
        else:
            transaction.rollback()

    Logger.close()
Пример #56
0
def main():
    from daklib.config import Config
    config = Config()

    import apt_pkg
    arguments = [
        ('h', 'help', 'Update-Suite::Options::Help'),
        ('n', 'no-act', 'Update-Suite::options::NoAct'),
    ]
    argv = apt_pkg.parse_commandline(config.Cnf, arguments, sys.argv)
    try:
        options = config.subtree("Update-Suite::Options")
    except KeyError:
        options = {}

    if 'Help' in options or len(argv) != 2:
        usage()

    origin_name = argv[0]
    target_name = argv[1]
    dry_run = True if 'NoAct' in options else False

    with ArchiveTransaction() as transaction:
        session = transaction.session

        try:
            origin = session.query(Suite).filter_by(
                suite_name=origin_name).one()
        except NoResultFound:
            daklib.utils.fubar(
                "Origin suite '{0}' is unknown.".format(origin_name))
        try:
            target = session.query(Suite).filter_by(
                suite_name=target_name).one()
        except NoResultFound:
            daklib.utils.fubar(
                "Target suite '{0}' is unknown.".format(target_name))

        su = SuiteUpdater(transaction, origin, target, dry_run=dry_run)
        su.update_suite()

        if dry_run:
            transaction.rollback()
        else:
            transaction.commit()
Пример #57
0
def main():
    cnf = Config()
    cnf['Contents::Options::Help'] = ''
    cnf['Contents::Options::Suite'] = ''
    cnf['Contents::Options::Component'] = ''
    cnf['Contents::Options::Limit'] = ''
    cnf['Contents::Options::Force'] = ''
    arguments = [
        ('h', "help", 'Contents::Options::Help'),
        ('a', 'archive', 'Contents::Options::Archive', 'HasArg'),
        ('s', "suite", 'Contents::Options::Suite', "HasArg"),
        ('c', "component", 'Contents::Options::Component', "HasArg"),
        ('l', "limit", 'Contents::Options::Limit', "HasArg"),
        ('f', "force", 'Contents::Options::Force'),
    ]
    args = apt_pkg.parse_commandline(cnf.Cnf, arguments, sys.argv)
    options = cnf.subtree('Contents::Options')

    if (len(args) != 1) or options['Help']:
        usage()

    limit = None
    if len(options['Limit']) > 0:
        limit = int(options['Limit'])

    if args[0] == 'scan-source':
        source_scan_all(cnf, limit)
        return

    if args[0] == 'scan-binary':
        binary_scan_all(cnf, limit)
        return

    archive_names = utils.split_args(options['Archive'])
    suite_names = utils.split_args(options['Suite'])
    component_names = utils.split_args(options['Component'])

    force = bool(options['Force'])

    if args[0] == 'generate':
        write_all(cnf, archive_names, suite_names, component_names, force)
        return

    usage()
Пример #58
0
def main():
    global Options, Logger

    cnf = Config()

    for i in ["Help", "No-Action", "All"]:
        key = "Manage-Debug-Suites::Options::%s" % i
        if key not in cnf:
            cnf[key] = ""

    Arguments = [('h', "help", "Manage-Debug-Suites::Options::Help"),
                 ('n', "no-action", "Manage-Debug-Suites::Options::No-Action"),
                 ('a', "all", "Manage-Debug-Suites::Options::All")]

    debug_suite_names = apt_pkg.parse_commandline(cnf.Cnf, Arguments, sys.argv)
    Options = cnf.subtree("Manage-Debug-Suites::Options")

    if Options["Help"]:
        usage()

    Logger = daklog.Logger('manage-debug-suites', Options['No-Action'])

    with ArchiveTransaction() as transaction:
        session = transaction.session
        if Options['All']:
            if len(debug_suite_names) != 0:
                print("E: Cannot use both -a and a queue name")
                sys.exit(1)
            raise Exception("Not yet implemented.")
        else:
            debug_suites = session.query(Suite).filter(
                Suite.suite_name.in_(debug_suite_names))

        for debug_suite in debug_suites:
            Logger.log(
                ['cleaning debug suite {0}'.format(debug_suite.suite_name)])
            clean(debug_suite, transaction)
        if not Options['No-Action']:
            transaction.commit()
        else:
            transaction.rollback()

    Logger.close()
Пример #59
0
def main():
    global Cnf
    global users

    Cnf = utils.get_conf()
    Arguments = [('h', "help", "Stats::Options::Help")]
    for i in ["help"]:
        key = "Stats::Options::%s" % i
        if key not in Cnf:
            Cnf[key] = ""

    args = apt_pkg.parse_commandline(Cnf, Arguments, sys.argv)

    Options = Cnf.subtree("Stats::Options")
    if Options["Help"]:
        usage()

    if len(args) < 1:
        utils.warn("dak stats requires a MODE argument")
        usage(1)
    elif len(args) > 1:
        if args[0].lower() != "new":
            utils.warn("dak stats accepts only one MODE argument")
            usage(1)
    elif args[0].lower() == "new":
        utils.warn("new MODE requires an output file")
        usage(1)
    mode = args[0].lower()

    if mode == "arch-space":
        per_arch_space_use()
    elif mode == "pkg-nums":
        number_of_packages()
    elif mode == "daily-install":
        daily_install_stats()
    elif mode == "new":
        users = utils.get_users_from_ldap()
        new_stats(Cnf["Dir::Log"], args[1])
    else:
        utils.warn("unknown mode '%s'" % (mode))
        usage(1)