Example #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 = ArgumentParser(usage=usage(module_controller))
	# add default options
	parser_options = []
	for opt in DEFAULT_OPTIONS:
		parser_options.append(OptionItem(DEFAULT_OPTIONS[opt]))
	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]))
	for opt in parser_options:
		parser.add_argument(*opt.pargs, **opt.kwargs)

	options, args = parser.parse_known_args(args=myargv)

	if options.version:
		print(portage.VERSION)
		return os.EX_OK

	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])

	check_opt = None
	func = status = long_action = None
	for opt in parser_options:
		if opt.long == '--check':
			# Default action
			check_opt = opt
		if opt.status and getattr(options, opt.target, False):
			if long_action is not None:
				parser.error("--%s and %s are exclusive options" %
					(long_action, opt.long))
			status = opt.status
			func = opt.func
			long_action = opt.long.lstrip('-')

	if long_action is None:
		#print("DEBUG: long_action is None: setting to 'check'")
		long_action = 'check'
		func = check_opt.func
		status = check_opt.status

	if args[0] == "all":
		tasks = []
		for m in module_names[1:]:
			#print("DEBUG: module: %s, functions: " % (m, str(module_controller.get_functions(m))))
			if func in module_controller.get_functions(m):
				tasks.append(module_controller.get_class(m))
	elif func in module_controller.get_functions(args[0]):
		tasks = [module_controller.get_class(args[0] )]
	else:
		portage.util.writemsg(
			"\nERROR: module '%s' does not have option '--%s'\n\n" %
			(args[0], long_action), noiselevel=-1)
		portage.util.writemsg(module_opts(module_controller, args[0]),
			noiselevel=-1)
		sys.exit(1)

	# 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, module_output=sys.stdout)
	taskmaster.run_tasks(tasks, func, status, options=task_opts)
Example #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 = ArgumentParser(usage=usage(module_controller))
	# add default options
	parser_options = []
	for opt in DEFAULT_OPTIONS:
		parser_options.append(OptionItem(DEFAULT_OPTIONS[opt]))
	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]))
	for opt in parser_options:
		parser.add_argument(*opt.pargs, **opt.kwargs)

	options, args = parser.parse_known_args(args=myargv)

	if options.version:
		print(portage.VERSION)
		return os.EX_OK

	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])

	check_opt = None
	func = status = long_action = None
	for opt in parser_options:
		if opt.long == '--check':
			# Default action
			check_opt = opt
		if opt.status and getattr(options, opt.long.lstrip("-"), False):
			if long_action is not None:
				parser.error("--%s and %s are exclusive options" %
					(long_action, opt.long))
			status = opt.status
			func = opt.func
			long_action = opt.long.lstrip('-')

	if long_action is None:
		long_action = 'check'
		func = check_opt.func
		status = check_opt.status

	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:
		portage.util.writemsg(
			"\nERROR: module '%s' does not have option '--%s'\n\n" %
			(args[0], long_action), noiselevel=-1)
		portage.util.writemsg(module_opts(module_controller, args[0]),
			noiselevel=-1)
		sys.exit(1)

	# 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)
Example #3
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)
Example #4
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)