def _generate_matching_machines(register, hostname): """ Yield all registered machines that match the current hostname. """ for (registered_machine_id, machine_data) in register.items(): if hostname == machine_data['hostname']: yield (registered_machine_id, machine_data)
def regex_table(dirpath_lwc_root): """ Build table of regular expressions to detect controlled item identifiers. """ register = da.register.load(register_name = 'idclass', dirpath_lwc_root = dirpath_lwc_root) tab = {} for (idclass, spec) in register.items(): pfix = spec['pfix'] dgts = spec['dgts'] expr = r"\b{pfx}[0-9]{{{dgt}}}_[a-z0-9_]{{2,100}}".format(pfx = pfix, dgt = dgts) tab[idclass] = expr tab = {key: re.compile(val) for key, val in tab.items()} return tab
def regex_table(dirpath_lwc_root): """ Build table of regular expressions to detect controlled item identifiers. """ register = da.register.load(register_name='idclass', dirpath_lwc_root=dirpath_lwc_root) tab = {} for (idclass, spec) in register.items(): if 'expr' in spec: expr = spec['expr'] else: expr = r"\b{pfx}[0-9]{{{dgt}}}_[a-z0-9_]{{2,100}}".format( pfx=spec['pfix'], dgt=spec['dgts']) tab[idclass] = expr tab = {key: re.compile(val) for key, val in tab.items()} return tab
def dependencies_register(dirpath_lwc_root = None): """ Return information about the location of dependencies. """ # Add some calculated file-paths to the dependency map. dirpath_curr_env = da.lwc.discover.path('current_env', dirpath_lwc_root) rootpath_env = da.lwc.discover.path('env', dirpath_lwc_root) rootpath_env_src = os.path.join(rootpath_env, 'src') register = da.register.load('dependencies') for (key, dep) in register.items(): dirname_dep = dep['dirname'] dirname_pol = dep['policy'] dirpath_src = os.path.join(rootpath_env_src, dirname_dep, dirname_pol) dirpath_dep = os.path.join(dirpath_curr_env, dirname_dep, dirname_pol) register[key]['name'] = key register[key]['dirpath_src'] = dirpath_src register[key]['dirpath_dep'] = dirpath_dep return register
def python_import_path(iface_name = None, # pylint: disable=R0912 dirpath_lwc_root = None): """ Return a list of Python import paths configured for the local working copy. Dependency information for the current local working copy is stored in the dependency map file. Different directories are used to store python slibraries for python2 and python3. """ if iface_name is None: iface_name = _iface_for_current_python_rt() dirpath_env = da.lwc.discover.path( 'current_env', dirpath_lwc_root = dirpath_lwc_root) register = dependencies_register( dirpath_lwc_root = dirpath_lwc_root) # python_path for the specified iface. # Replicates some of the logic in function # addpackage in site.py # python_path = [] for (_, dependency_data) in register.items(): try: relpath_iface = dependency_data['api'][iface_name] except KeyError: continue dirpath_package = os.path.normpath( os.path.join( dirpath_env, dependency_data['dirname'], dependency_data['policy'], relpath_iface)) if not os.path.isdir(dirpath_package): continue eggs = [os.path.join(dirpath_package, name) for name in os.listdir(dirpath_package) if name.endswith('.egg')] if eggs: python_path.extend(eggs) else: python_path.append(dirpath_package) # All top level directories from src are added to the python_path dirpath_src = da.lwc.discover.path( key = 'src', dirpath_lwc_root = dirpath_lwc_root) for (_, dir_list, _) in os.walk(dirpath_src): for name in dir_list: if name.startswith('.'): continue python_path.append(os.path.join(dirpath_src, name)) break # # Add system python as well. !WARNING! !DANGEROUS! !REMOVE WHEN POSSIBLE! if iface_name == 'lib_python3': python_path.append('/usr/lib/python3.4') python_path.append('/usr/lib/python3.4/plat-x86_64-linux-gnu') python_path.append('/usr/lib/python3.4/lib-dynload') python_path.append('/usr/local/lib/python3.4/dist-packages') python_path.append('/usr/lib/python3/dist-packages') return python_path