def __init__(self, configpaths, valid_versions=None, repository_modules=False): '''Module init @param configpaths: ordered list of filepaths to load ''' if repository_modules: self.configpaths = [os.path.join(path, 'repository.yaml') for path in configpaths] elif _not_installed: self.configpaths = [os.path.realpath(os.path.join(os.path.dirname( os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname( os.path.dirname(__file__)))))), 'repoman/cnf/repository/repository.yaml'))] else: self.configpaths = [os.path.join(portage.const.EPREFIX or '/', 'usr/share/repoman/repository/repository.yaml')] logging.debug("ModuleConfig; configpaths: %s", self.configpaths) self.controller = Modules(path=MODULES_PATH, namepath="repoman.modules.scan") logging.debug("ModuleConfig; module_names: %s", self.controller.module_names) self._configs = None self.enabled = [] self.pkgs_loop = [] self.ebuilds_loop = [] self.final_loop = [] self.modules_forced = ['ebuild', 'mtime'] self.load_configs(valid_versions=valid_versions) for loop in ['pkgs', 'ebuilds', 'final']: logging.debug("ModuleConfig; Processing loop %s", loop) setattr(self, '%s_loop' % loop, self._determine_list(loop)) self.linechecks = stack_lists(c['linechecks_modules'].split() for c in self._configs)
def __init__(self, configpaths, valid_versions=None, repository_modules=False): """Module init @param configpaths: ordered list of filepaths to load """ if repository_modules: self.configpaths = [ os.path.join(path, "repository.yaml") for path in configpaths ] elif _not_installed: self.configpaths = [ os.path.realpath( os.path.join( os.path.dirname( os.path.dirname( os.path.dirname( os.path.dirname( os.path.dirname(__file__))))), "cnf/repository/repository.yaml", )) ] else: self.configpaths = [ os.path.join( portage.const.EPREFIX or "/", "usr/share/repoman/repository/repository.yaml", ) ] logging.debug("ModuleConfig; configpaths: %s", self.configpaths) self.controller = Modules(path=MODULES_PATH, namepath="repoman.modules.scan") logging.debug("ModuleConfig; module_names: %s", self.controller.module_names) self._configs = None self.enabled = [] self.pkgs_loop = [] self.ebuilds_loop = [] self.final_loop = [] self.modules_forced = ["ebuild", "mtime"] self.load_configs(valid_versions=valid_versions) for loop in ["pkgs", "ebuilds", "final"]: logging.debug("ModuleConfig; Processing loop %s", loop) setattr(self, "%s_loop" % loop, self._determine_list(loop)) self.linechecks = stack_lists(c["linechecks_modules"].split() for c in self._configs)
class ModuleConfig: '''Holds the scan modules configuration information and creates the ordered list of modulles to run''' def __init__(self, configpaths, valid_versions=None, repository_modules=False): '''Module init @param configpaths: ordered list of filepaths to load ''' if repository_modules: self.configpaths = [ os.path.join(path, 'repository.yaml') for path in configpaths ] elif _not_installed: self.configpaths = [ os.path.realpath( os.path.join( os.path.dirname( os.path.dirname( os.path.dirname( os.path.dirname( os.path.dirname( os.path.dirname(__file__)))))), 'repoman/cnf/repository/repository.yaml')) ] else: self.configpaths = [ os.path.join(portage.const.EPREFIX or '/', 'usr/share/repoman/repository/repository.yaml') ] logging.debug("ModuleConfig; configpaths: %s", self.configpaths) self.controller = Modules(path=MODULES_PATH, namepath="repoman.modules.scan") logging.debug("ModuleConfig; module_names: %s", self.controller.module_names) self._configs = None self.enabled = [] self.pkgs_loop = [] self.ebuilds_loop = [] self.final_loop = [] self.modules_forced = ['ebuild', 'mtime'] self.load_configs(valid_versions=valid_versions) for loop in ['pkgs', 'ebuilds', 'final']: logging.debug("ModuleConfig; Processing loop %s", loop) setattr(self, '%s_loop' % loop, self._determine_list(loop)) self.linechecks = stack_lists(c['linechecks_modules'].split() for c in self._configs) def load_configs(self, configpaths=None, valid_versions=None): '''load the config files in order @param configpaths: ordered list of filepaths to load ''' if configpaths: self.configpaths = configpaths elif not self.configpaths: logging.error( "ModuleConfig; Error: No repository.yaml files defined") configs = [] for path in self.configpaths: logging.debug("ModuleConfig; Processing: %s", path) if os.path.exists(path): try: with open(path, 'r') as inputfile: configs.append(yaml.safe_load(inputfile)) except IOError as error: logging, error("Failed to load file: %s", inputfile) logging.exception(error) else: if configs[-1]['version'] not in valid_versions: raise ConfigError( "Invalid file version: %s in: %s\nPlease upgrade repoman" % (configs['version'], path)) logging.debug("ModuleConfig; completed : %s", path) logging.debug("ModuleConfig; new _configs: %s", configs) self._configs = configs def _determine_list(self, loop): '''Determine the ordered list from the config data and the moule_runsIn value in the module_spec @returns: list of modules ''' lists = [c['scan_modules'].split() for c in self._configs] stacked = self.modules_forced + stack_lists(lists) mlist = [] try: for mod in stacked: logging.debug( "ModuleConfig; checking loop %s, module: %s, in: %s", loop, mod, self.controller.get_spec(mod, 'module_runsIn')) if loop in self.controller.get_spec(mod, 'module_runsIn'): mlist.append(mod) except InvalidModuleName: logging.error("ModuleConfig; unknown module: %s, skipping", mod) logging.debug("ModuleConfig; mlist: %s", mlist) return mlist
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_path = os.path.join( (os.path.dirname( os.path.realpath(__file__))), "modules" ) module_controller = Modules( path=module_path, 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])) desc = module_controller.get_opt_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 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__ task_opts['return-messages'] = True taskmaster = TaskHandler(callback=print_results, module_output=sys.stdout) taskmaster.run_tasks(tasks, func, status, options=task_opts)
import os from portage.module import Modules path = os.path.dirname(__file__) # initial development debug info #print("module path:", path) module_controller = Modules(path=path, namepath="repoman.modules.vcs") # initial development debug info #print(module_controller.module_names) module_names = module_controller.module_names[:]
from portage.util.futures.extendedfutures import ExtendedFuture from repoman.metadata import get_metadata_xsd from repoman.modules.commit import repochecks from repoman.modules.commit import manifest from repoman.profile import check_profiles, dev_profile_keywords, setup_profile from repoman.repos import repo_metadata from repoman.modules.scan.scan import scan from repoman.modules.vcs.vcs import vcs_files_to_cps from portage.module import Modules MODULES_PATH = os.path.join(os.path.dirname(__file__), "modules", "scan") # initial development debug info logging.debug("module path: %s", MODULES_PATH) MODULE_CONTROLLER = Modules(path=MODULES_PATH, namepath="repoman.modules.scan") MODULE_NAMES = MODULE_CONTROLLER.module_names[:] # initial development debug info logging.debug("module_names: %s", MODULE_NAMES) DATA_TYPES = {'dict': dict, 'Future': ExtendedFuture, 'list': list, 'set': set} class Scanner(object): '''Primary scan class. Operates all the small Q/A tests and checks''' def __init__(self, repo_settings, myreporoot, config_root, options, vcs_settings, mydir, env): '''Class __init__''' self.repo_settings = repo_settings self.config_root = config_root
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_path = os.path.join((os.path.dirname(os.path.realpath(__file__))), "modules") module_controller = Modules(path=module_path, namepath="portage.emaint.modules") module_names = module_controller.module_names[:] module_names.insert(0, "all") parser = argparse.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])) desc = module_controller.get_opt_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 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__ task_opts['return-messages'] = True taskmaster = TaskHandler(callback=print_results, module_output=sys.stdout) returncodes = taskmaster.run_tasks(tasks, func, status, options=task_opts) sys.exit(False in returncodes)
from portage.module import Modules from portage.sync.controller import SyncManager from portage.sync.config_checks import check_type _SUBMODULE_PATH_MAP = OrderedDict([ ('glsa', ('metadata/glsa', )), ('news', ('metadata/news', )), ('profiles', ('metadata/layout.conf', 'profiles')), ]) path = os.path.join(os.path.dirname(__file__), "modules") # initial development debug info #print("module path:", path) module_controller = Modules(path=path, namepath="portage.sync.modules") # initial development debug info #print(module_controller.module_names) module_names = module_controller.module_names[:] def module_specific_options(repo): '''Get the authorized module specific options set for the repos.conf settings for the repo''' global module_controller if repo.sync_type: try: return frozenset(module_controller.modules[repo.sync_type] ['module_specific_options'])
class ModuleConfig(object): '''Holds the scan modules configuration information and creates the ordered list of modulles to run''' def __init__(self, configpaths, valid_versions=None, repository_modules=False): '''Module init @param configpaths: ordered list of filepaths to load ''' if repository_modules: self.configpaths = [os.path.join(path, 'repository.yaml') for path in configpaths] elif _not_installed: self.configpaths = [os.path.realpath(os.path.join(os.path.dirname( os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname( os.path.dirname(__file__)))))), 'repoman/cnf/repository/repository.yaml'))] else: self.configpaths = [os.path.join(portage.const.EPREFIX or '/', 'usr/share/repoman/repository/repository.yaml')] logging.debug("ModuleConfig; configpaths: %s", self.configpaths) self.controller = Modules(path=MODULES_PATH, namepath="repoman.modules.scan") logging.debug("ModuleConfig; module_names: %s", self.controller.module_names) self._configs = None self.enabled = [] self.pkgs_loop = [] self.ebuilds_loop = [] self.final_loop = [] self.modules_forced = ['ebuild', 'mtime'] self.load_configs(valid_versions=valid_versions) for loop in ['pkgs', 'ebuilds', 'final']: logging.debug("ModuleConfig; Processing loop %s", loop) setattr(self, '%s_loop' % loop, self._determine_list(loop)) self.linechecks = stack_lists(c['linechecks_modules'].split() for c in self._configs) def load_configs(self, configpaths=None, valid_versions=None): '''load the config files in order @param configpaths: ordered list of filepaths to load ''' if configpaths: self.configpaths = configpaths elif not self.configpaths: logging.error("ModuleConfig; Error: No repository.yaml files defined") configs = [] for path in self.configpaths: logging.debug("ModuleConfig; Processing: %s", path) if os.path.exists(path): try: with open(path, 'r') as inputfile: configs.append(yaml.safe_load(inputfile)) except IOError as error: logging,error("Failed to load file: %s", inputfile) logging.exception(error) else: if configs[-1]['version'] not in valid_versions: raise ConfigError("Invalid file version: %s in: %s\nPlease upgrade repoman" % (configs['version'], path)) logging.debug("ModuleConfig; completed : %s", path) logging.debug("ModuleConfig; new _configs: %s", configs) self._configs = configs def _determine_list(self, loop): '''Determine the ordered list from the config data and the moule_runsIn value in the module_spec @returns: list of modules ''' lists = [c['scan_modules'].split() for c in self._configs] stacked = self.modules_forced + stack_lists(lists) mlist = [] try: for mod in stacked: logging.debug("ModuleConfig; checking loop %s, module: %s, in: %s", loop, mod, self.controller.get_spec(mod, 'module_runsIn')) if loop in self.controller.get_spec(mod, 'module_runsIn'): mlist.append(mod) except InvalidModuleName: logging.error("ModuleConfig; unknown module: %s, skipping", mod) logging.debug("ModuleConfig; mlist: %s", mlist) return mlist