Пример #1
0
def emaint_main(myargv):

	# Similar to emerge, emaint needs a default umask so that created
	# files (such as the world file) have sane permissions.
	os.umask(0o22)

	module_controller = Modules(namepath="portage.emaint.modules")
	module_names = module_controller.module_names[:]
	module_names.insert(0, "all")


	parser = OptionParser(usage=usage(module_controller), version=portage.VERSION)
	# add default options
	parser_options = []
	for opt in DEFAULT_OPTIONS:
		parser_options.append(OptionItem(DEFAULT_OPTIONS[opt], parser))
	for mod in module_names[1:]:
		desc = module_controller.get_func_descriptions(mod)
		if desc:
			for opt in desc:
				parser_options.append(OptionItem(desc[opt], parser))
	for opt in parser_options:
		parser.add_option(opt.short, opt.long, help=opt.help, action=opt.action,
		type=opt.type, dest=opt.dest,
			callback=opt.callback, callback_kwargs=opt.callback_kwargs)

	parser.action = None

	(options, args) = parser.parse_args(args=myargv)
	#print('options', options, '\nargs', args, '\naction', parser.action)
	if len(args) != 1:
		parser.error("Incorrect number of arguments")
	if args[0] not in module_names:
		parser.error("%s target is not a known target" % args[0])

	if parser.action:
		action = parser.action
	else:
		action = "-c/--check"
	long_action = action.split('/')[1].lstrip('-')
	#print("DEBUG: action = ", action, long_action)

	if args[0] == "all":
		tasks = []
		for m in module_names[1:]:
			#print("DEBUG: module: %s, functions: " %(m, str(module_controller.get_functions(m))))
			if long_action in module_controller.get_functions(m):
				tasks.append(module_controller.get_class(m))
	elif long_action in module_controller.get_functions(args[0]):
		tasks = [module_controller.get_class(args[0] )]
	else:
		print("\nERROR: module '%s' does not have option '%s'\n" %(args[0], action))
		print(module_opts(module_controller, args[0]))
		sys.exit(1)
	func = status = None
	for opt in parser_options:
		if opt.check_action(action):
			status = opt.status
			func = opt.func
			break

	# need to pass the parser options dict to the modules
	# so they are available if needed.
	task_opts = options.__dict__
	taskmaster = TaskHandler(callback=print_results)
	taskmaster.run_tasks(tasks, func, status, options=task_opts)
Пример #2
0
def emaint_main(myargv):

    # Similar to emerge, emaint needs a default umask so that created
    # files (such as the world file) have sane permissions.
    os.umask(0o22)

    module_controller = Modules(namepath="portage.emaint.modules")
    module_names = module_controller.module_names[:]
    module_names.insert(0, "all")

    parser = OptionParser(usage=usage(module_controller), version=portage.VERSION)
    # add default options
    parser_options = []
    for opt in DEFAULT_OPTIONS:
        parser_options.append(OptionItem(DEFAULT_OPTIONS[opt], parser))
    for mod in module_names[1:]:
        desc = module_controller.get_func_descriptions(mod)
        if desc:
            for opt in desc:
                parser_options.append(OptionItem(desc[opt], parser))
    for opt in parser_options:
        parser.add_option(
            opt.short,
            opt.long,
            help=opt.help,
            action=opt.action,
            type=opt.type,
            dest=opt.dest,
            callback=opt.callback,
            callback_kwargs=opt.callback_kwargs,
        )

    parser.action = None

    (options, args) = parser.parse_args(args=myargv)
    # print('options', options, '\nargs', args, '\naction', parser.action)
    if len(args) != 1:
        parser.error("Incorrect number of arguments")
    if args[0] not in module_names:
        parser.error("%s target is not a known target" % args[0])

    if parser.action:
        action = parser.action
    else:
        action = "-c/--check"
    long_action = action.split("/")[1].lstrip("-")
    # print("DEBUG: action = ", action, long_action)

    if args[0] == "all":
        tasks = []
        for m in module_names[1:]:
            # print("DEBUG: module: %s, functions: " %(m, str(module_controller.get_functions(m))))
            if long_action in module_controller.get_functions(m):
                tasks.append(module_controller.get_class(m))
    elif long_action in module_controller.get_functions(args[0]):
        tasks = [module_controller.get_class(args[0])]
    else:
        print("\nERROR: module '%s' does not have option '%s'\n" % (args[0], action))
        print(module_opts(module_controller, args[0]))
        sys.exit(1)
    func = status = None
    for opt in parser_options:
        if opt.check_action(action):
            status = opt.status
            func = opt.func
            break

            # need to pass the parser options dict to the modules
            # so they are available if needed.
    task_opts = options.__dict__
    taskmaster = TaskHandler(callback=print_results)
    taskmaster.run_tasks(tasks, func, status, options=task_opts)