예제 #1
0
파일: transitions.py 프로젝트: evgeni/dak
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"]:
        if not Cnf.has_key("Edit-Transitions::Options::%s" % (i)):
            Cnf["Edit-Transitions::Options::%s" % (i)] = ""

    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()
예제 #2
0
파일: transitions.py 프로젝트: Debian/dak
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()
예제 #3
0
def main():
    global Options, Logger, Queue, changes
    cnf = Config()

    Arguments = [('h', "Help",      "Security::Options::Help"),
                 ('n', "No-Action", "Security::Options::No-Action"),
                 ('c', 'Changesfile', "Security::Options::Changesfile"),
                 ('s', "Sudo", "Security::Options::Sudo"),
                 ('A', "Approve", "Security::Options::Approve")
                 ]

    for i in ["Help", "No-Action", "Changesfile", "Sudo", "Approve"]:
        key = "Security::Options::%s" % i
        if key not in cnf:
            cnf[key] = ""

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

    Options = cnf.subtree("Security::Options")
    if Options['Help']:
        usage()

    changesfiles = {}
    for a in changes_files:
        if not a.endswith(".changes"):
            utils.fubar("not a .changes file: %s" % (a))
        changesfiles[a] = 1
    changes = changesfiles.keys()

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

    if Options["No-Action"]:
        Options["Sudo"] = ""

    if not Options["Sudo"] and not Options["No-Action"]:
        Logger = daklog.Logger("security-install")

    session = DBConn().session()

    # If we call ourselve to approve, we do just that and exit
    if Options["Approve"]:
        do_Approve()
        sys.exit()

    if len(changes) == 0:
        utils.fubar("Need changes files as arguments")

    # Yes, we could do this inside do_Approve too. But this way we see who exactly
    # called it (ownership of the file)

    acceptfiles = {}
    for change in changes:
        dbchange = get_dbchange(os.path.basename(change), session)
        # strip epoch from version
        version = dbchange.version
        version = version[(version.find(':') + 1):]
        # strip possible version from source (binNMUs)
        source = dbchange.source.split(None, 1)[0]
        acceptfilename = "%s/COMMENTS/ACCEPT.%s_%s" % (os.path.dirname(os.path.abspath(changes[0])), source, version)
        acceptfiles[acceptfilename] = 1

    print("Would create %s now and then go on to accept this package, if you allow me to." % (acceptfiles.keys()))
    if Options["No-Action"]:
        sys.exit(0)
    else:
        raw_input("Press Enter to continue")

    for acceptfilename in acceptfiles.keys():
        accept_file = file(acceptfilename, "w")
        accept_file.write("OK\n")
        accept_file.close()

    do_Approve()
예제 #4
0
def main():
    global Options, Logger, Queue, changes
    cnf = Config()

    Arguments = [('h', "Help",      "Security::Options::Help"),
                 ('n', "No-Action", "Security::Options::No-Action"),
                 ('c', 'Changesfile', "Security::Options::Changesfile"),
                 ('s', "Sudo", "Security::Options::Sudo"),
                 ('A', "Approve", "Security::Options::Approve")
                 ]

    for i in ["Help", "No-Action", "Changesfile", "Sudo", "Approve"]:
        key = "Security::Options::%s" % i
        if key not in cnf:
            cnf[key] = ""

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

    Options = cnf.subtree("Security::Options")
    if Options['Help']:
        usage()

    changesfiles = {}
    for a in changes_files:
        if not a.endswith(".changes"):
            utils.fubar("not a .changes file: %s" % (a))
        changesfiles[a] = 1
    changes = list(changesfiles.keys())

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

    if Options["No-Action"]:
        Options["Sudo"] = ""

    if not Options["Sudo"] and not Options["No-Action"]:
        Logger = daklog.Logger("security-install")

    session = DBConn().session()

    # If we call ourselve to approve, we do just that and exit
    if Options["Approve"]:
        do_Approve()
        sys.exit()

    if len(changes) == 0:
        utils.fubar("Need changes files as arguments")

    # Yes, we could do this inside do_Approve too. But this way we see who exactly
    # called it (ownership of the file)

    acceptfiles = {}
    for change in changes:
        dbchange = get_dbchange(os.path.basename(change), session)
        # strip epoch from version
        version = dbchange.version
        version = version[(version.find(':') + 1):]
        # strip possible version from source (binNMUs)
        source = dbchange.source.split(None, 1)[0]
        acceptfilename = "%s/COMMENTS/ACCEPT.%s_%s" % (os.path.dirname(os.path.abspath(changes[0])), source, version)
        acceptfiles[acceptfilename] = 1

    print("Would create %s now and then go on to accept this package, if you allow me to." % (list(acceptfiles.keys())))
    if Options["No-Action"]:
        sys.exit(0)
    else:
        input("Press Enter to continue")

    for acceptfilename in acceptfiles:
        with open(acceptfilename, "w") as accept_file:
            accept_file.write("OK\n")

    do_Approve()