idx int64 0 63k | question stringlengths 53 5.28k | target stringlengths 5 805 |
|---|---|---|
44,100 | def hashify_files ( files : list ) -> dict : return { filepath . replace ( '\\' , '/' ) : hash_tree ( filepath ) for filepath in listify ( files ) } | Return mapping from file path to file hash . |
44,101 | def process_prop ( prop_type : PT , value , build_context ) : if prop_type in ( PT . Target , PT . TargetList ) : return hashify_targets ( value , build_context ) elif prop_type in ( PT . File , PT . FileList ) : return hashify_files ( value ) return value | Return a cachable representation of the prop value given its type . |
44,102 | def compute_json ( self , build_context ) : props = { } test_props = { } for prop in self . props : if prop in self . _prop_json_blacklist : continue sig_spec = Plugin . builders [ self . builder_name ] . sig . get ( prop ) if sig_spec is None : continue if prop in self . _prop_json_testlist : test_props [ prop ] = pro... | Compute and store a JSON serialization of this target for caching purposes . |
44,103 | def json ( self , build_context ) -> str : if self . _json is None : self . compute_json ( build_context ) return self . _json | Return JSON serialization of this target for caching purposes . |
44,104 | def compute_hash ( self , build_context ) : m = md5 ( ) m . update ( self . json ( build_context ) . encode ( 'utf8' ) ) self . _hash = m . hexdigest ( ) m = md5 ( ) m . update ( self . test_json ( build_context ) . encode ( 'utf8' ) ) self . _test_hash = m . hexdigest ( ) | Compute and store the hash of this target for caching purposes . |
44,105 | def hash ( self , build_context ) -> str : if self . _hash is None : self . compute_hash ( build_context ) return self . _hash | Return the hash of this target for caching purposes . |
44,106 | def handle_build_cache ( conf : Config , name : str , tag : str , icb : ImageCachingBehavior ) : if icb . pull_if_cached or ( icb . pull_if_not_cached and get_cached_image_id ( icb . remote_image ) is None ) : try : pull_docker_image ( icb . remote_image , conf . docker_pull_cmd ) except CalledProcessError : pass local... | Handle Docker image build cache . |
44,107 | def add_stream_handler ( logger , stream ) : handler = logging . StreamHandler ( stream = stream ) formatter = logging . Formatter ( '{asctime} {name:24s} {levelname:8s} {message}' , style = '{' ) handler . setFormatter ( formatter ) logger . addHandler ( handler ) | Add a brace - handler stream - handler using stream to logger . |
44,108 | def configure_logging ( conf ) : root_logger = logging . getLogger ( ) root_logger . setLevel ( getattr ( logging , conf . loglevel . upper ( ) ) ) if conf . logtostderr : add_stream_handler ( root_logger , sys . stderr ) if conf . logtostdout : add_stream_handler ( root_logger , sys . stdout ) | Initialize and configure logging . |
44,109 | def register_sig ( self , builder_name : str , sig : list , docstring : str , cachable : bool = True , attempts = 1 ) : if self . sig is not None : raise KeyError ( '{} already registered a signature!' . format ( builder_name ) ) self . sig = OrderedDict ( name = ArgSpec ( PropType . TargetName , Empty ) ) self . docst... | Register a builder signature & docstring for builder_name . |
44,110 | def remove_builder ( cls , builder_name : str ) : cls . builders . pop ( builder_name , None ) for hook_spec in cls . hooks . values ( ) : hook_spec . pop ( builder_name , None ) | Remove a registered builder builder_name . |
44,111 | def to_build_module ( build_file_path : str , conf : Config ) -> str : build_file = Path ( build_file_path ) root = Path ( conf . project_root ) return build_file . resolve ( ) . relative_to ( root ) . parent . as_posix ( ) . strip ( '.' ) | Return a normalized build module name for build_file_path . |
44,112 | def cmd_version ( unused_conf ) : import pkg_resources print ( 'This is {} version {}, imported from {}' . format ( __oneliner__ , __version__ , __file__ ) ) if len ( Plugin . builders ) > 0 : print ( 'setuptools registered builders:' ) for entry_point in pkg_resources . iter_entry_points ( 'yabt.builders' ) : print ( ... | Print out version information about YABT and detected builders . |
44,113 | def cmd_list ( unused_conf : Config ) : for name , builder in sorted ( Plugin . builders . items ( ) ) : if builder . func : print ( '+- {0:16s} implemented in {1.__module__}.{1.__name__}()' . format ( name , builder . func ) ) else : print ( '+- {0:16s} loaded with no builder function' . format ( name ) ) for hook_nam... | Print out information on loaded builders and hooks . |
44,114 | def cmd_build ( conf : Config , run_tests : bool = False ) : build_context = BuildContext ( conf ) populate_targets_graph ( build_context , conf ) build_context . build_graph ( run_tests = run_tests ) build_context . write_artifacts_metadata ( ) | Build requested targets and their dependencies . |
44,115 | def main ( ) : conf = init_and_get_conf ( ) logger = make_logger ( __name__ ) logger . info ( 'YaBT version {}' , __version__ ) handlers = { 'build' : YabtCommand ( func = cmd_build , requires_project = True ) , 'dot' : YabtCommand ( func = cmd_dot , requires_project = True ) , 'test' : YabtCommand ( func = cmd_test , ... | Main ybt console script entry point - run YABT from command - line . |
44,116 | def cpp_app_builder ( build_context , target ) : yprint ( build_context . conf , 'Build CppApp' , target ) if target . props . executable and target . props . main : raise KeyError ( '`main` and `executable` arguments are mutually exclusive' ) if target . props . executable : if target . props . executable not in targe... | Pack a C ++ binary as a Docker image with its runtime dependencies . |
44,117 | def make_pre_build_hook ( extra_compiler_config_params ) : def pre_build_hook ( build_context , target ) : target . compiler_config = CompilerConfig ( build_context , target , extra_compiler_config_params ) target . props . _internal_dict_ [ 'compiler_config' ] = ( target . compiler_config . as_dict ( ) ) return pre_bu... | Return a pre - build hook function for C ++ builders . |
44,118 | def compile_cc ( build_context , compiler_config , buildenv , sources , workspace_dir , buildenv_workspace , cmd_env ) : objects = [ ] for src in sources : obj_rel_path = '{}.o' . format ( splitext ( src ) [ 0 ] ) obj_file = join ( buildenv_workspace , obj_rel_path ) include_paths = [ buildenv_workspace ] + compiler_co... | Compile list of C ++ source files in a buildenv image and return list of generated object file . |
44,119 | def get_source_files ( target , build_context ) -> list : all_sources = list ( target . props . sources ) for proto_dep_name in target . props . protos : proto_dep = build_context . targets [ proto_dep_name ] all_sources . extend ( proto_dep . artifacts . get ( AT . gen_cc ) . keys ( ) ) return all_sources | Return list of source files for target . |
44,120 | def build_cpp ( build_context , target , compiler_config , workspace_dir ) : rmtree ( workspace_dir ) binary = join ( * split ( target . name ) ) objects = link_cpp_artifacts ( build_context , target , workspace_dir , True ) buildenv_workspace = build_context . conf . host_to_buildenv_path ( workspace_dir ) objects . e... | Compile and link a C ++ binary for target . |
44,121 | def cpp_prog_builder ( build_context , target ) : yprint ( build_context . conf , 'Build CppProg' , target ) workspace_dir = build_context . get_workspace ( 'CppProg' , target . name ) build_cpp ( build_context , target , target . compiler_config , workspace_dir ) | Build a C ++ binary executable |
44,122 | def cpp_lib_builder ( build_context , target ) : yprint ( build_context . conf , 'Build CppLib' , target ) workspace_dir = build_context . get_workspace ( 'CppLib' , target . name ) workspace_src_dir = join ( workspace_dir , 'src' ) rmtree ( workspace_src_dir ) link_cpp_artifacts ( build_context , target , workspace_sr... | Build C ++ object files |
44,123 | def standard_licenses_only ( build_context , target ) -> str : for license_name in target . props . license : if license_name not in KNOWN_LICENSES : return 'Unknown license: {}' . format ( license_name ) return None | A policy function for allowing specifying only known licenses . |
44,124 | def whitelist_licenses_policy ( policy_name : str , allowed_licenses : set ) : def policy_func ( build_context , target ) : if policy_name in target . props . policies : licenses = set ( target . props . license ) for dep in build_context . generate_all_deps ( target ) : licenses . update ( dep . props . license ) lice... | A policy factory for making license - based whitelist policies . |
44,125 | def find_project_config_file ( project_root : str ) -> str : if project_root : project_config_file = os . path . join ( project_root , YCONFIG_FILE ) if os . path . isfile ( project_config_file ) : return project_config_file | Return absolute path to project - specific config file if it exists . |
44,126 | def get_user_settings_module ( project_root : str ) : if project_root : project_settings_file = os . path . join ( project_root , YSETTINGS_FILE ) if os . path . isfile ( project_settings_file ) : settings_loader = SourceFileLoader ( 'settings' , project_settings_file ) return settings_loader . load_module ( ) | Return project - specific user settings module if it exists . |
44,127 | def call_user_func ( settings_module , func_name , * args , ** kwargs ) : if settings_module : if hasattr ( settings_module , func_name ) : func = getattr ( settings_module , func_name ) try : return func ( * args , ** kwargs ) finally : delattr ( settings_module , func_name ) | Call a user - supplied settings function and clean it up afterwards . |
44,128 | def get_build_flavor ( settings_module , args ) : known_flavors = listify ( call_user_func ( settings_module , 'known_flavors' ) ) if args . flavor : if args . flavor not in known_flavors : raise ValueError ( 'Unknown build flavor: {}' . format ( args . flavor ) ) else : args . flavor = call_user_func ( settings_module... | Update the flavor arg based on the settings API |
44,129 | def init_and_get_conf ( argv : list = None ) -> Config : colorama . init ( ) work_dir = os . path . abspath ( os . curdir ) project_root = search_for_parent_dir ( work_dir , with_files = set ( [ BUILD_PROJ_FILE ] ) ) parser = make_parser ( find_project_config_file ( project_root ) ) settings_module = get_user_settings_... | Initialize a YABT CLI environment and return a Config instance . |
44,130 | def stable_reverse_topological_sort ( graph ) : if not graph . is_directed ( ) : raise networkx . NetworkXError ( 'Topological sort not defined on undirected graphs.' ) seen = set ( ) explored = set ( ) for v in sorted ( graph . nodes ( ) ) : if v in explored : continue fringe = [ v ] while fringe : w = fringe [ - 1 ] ... | Return a list of nodes in topological sort order . |
44,131 | def raise_unresolved_targets ( build_context , conf , unknown_seeds , seed_refs ) : def format_target ( target_name ) : build_module = split_build_module ( target_name ) return '{} (in {})' . format ( target_name , conf . get_build_file_path ( build_module ) ) def format_unresolved ( seed ) : if seed not in seed_refs :... | Raise error about unresolved targets during graph parsing . |
44,132 | def register_scm_provider ( scm_name : str ) : def register_decorator ( scm_class : SourceControl ) : if scm_name in ScmManager . providers : raise KeyError ( '{} already registered!' . format ( scm_name ) ) ScmManager . providers [ scm_name ] = scm_class SourceControl . register ( scm_class ) logger . debug ( 'Registe... | Return a decorator for registering a SCM provider named scm_name . |
44,133 | def get_provider ( cls , scm_name : str , conf ) -> SourceControl : for entry_point in pkg_resources . iter_entry_points ( 'yabt.scm' , scm_name ) : entry_point . load ( ) logger . debug ( 'Loaded SCM provider {0.name} from {0.module_name} ' '(dist {0.dist})' , entry_point ) logger . debug ( 'Loaded {} SCM providers' ,... | Load and return named SCM provider instance . |
44,134 | def write_dot ( build_context , conf : Config , out_f ) : not_buildenv_targets = get_not_buildenv_targets ( build_context ) prebuilt_targets = get_prebuilt_targets ( build_context ) out_f . write ( 'strict digraph {\n' ) for node in build_context . target_graph . nodes : if conf . show_buildenv_deps or node in not_bui... | Write build graph in dot format to out_f file - like object . |
44,135 | def get_workspace ( self , * parts ) -> str : workspace_dir = os . path . join ( self . conf . get_workspace_path ( ) , * ( get_safe_path ( part ) for part in parts ) ) if not os . path . isdir ( workspace_dir ) : os . makedirs ( workspace_dir , exist_ok = True ) return workspace_dir | Return a path to a private workspace dir . Create sub - tree of dirs using strings from parts inside workspace and return full path to innermost directory . |
44,136 | def get_bin_dir ( self , build_module : str ) -> str : bin_dir = os . path . join ( self . conf . get_bin_path ( ) , build_module ) if not os . path . isdir ( bin_dir ) : os . makedirs ( bin_dir , exist_ok = True ) return bin_dir | Return a path to the binaries dir for a build module dir . Create sub - tree of missing dirs as needed and return full path to innermost directory . |
44,137 | def walk_target_deps_topological_order ( self , target : Target ) : all_deps = get_descendants ( self . target_graph , target . name ) for dep_name in topological_sort ( self . target_graph ) : if dep_name in all_deps : yield self . targets [ dep_name ] | Generate all dependencies of target by topological sort order . |
44,138 | def generate_direct_deps ( self , target : Target ) : yield from ( self . targets [ dep_name ] for dep_name in sorted ( target . deps ) ) | Generate only direct dependencies of target . |
44,139 | def register_target ( self , target : Target ) : if target . name in self . targets : first = self . targets [ target . name ] raise NameError ( 'Target with name "{0.name}" ({0.builder_name} from module ' '"{1}") already exists - defined first as ' '{2.builder_name} in module "{3}"' . format ( target , split_build_mod... | Register a target instance in this build context . |
44,140 | def get_target_extraction_context ( self , build_file_path : str ) -> dict : extraction_context = { } for name , builder in Plugin . builders . items ( ) : extraction_context [ name ] = extractor ( name , builder , build_file_path , self ) return extraction_context | Return a build file parser target extraction context . |
44,141 | def get_buildenv_graph ( self ) : buildenvs = set ( target . buildenv for target in self . targets . values ( ) if target . buildenv ) return nx . DiGraph ( self . target_graph . subgraph ( reduce ( lambda x , y : x | set ( y ) , ( get_descendants ( self . target_graph , buildenv ) for buildenv in buildenvs ) , builden... | Return a graph induced by buildenv nodes |
44,142 | def ready_nodes_iter ( self , graph_copy ) : def is_ready ( target_name ) : try : next ( graph_copy . successors ( target_name ) ) except StopIteration : return True return False ready_nodes = deque ( sorted ( target_name for target_name in graph_copy . nodes if is_ready ( target_name ) ) ) produced_event = threading .... | Generate ready targets from the graph graph_copy . |
44,143 | def run_in_buildenv ( self , buildenv_target_name : str , cmd : list , cmd_env : dict = None , work_dir : str = None , auto_uid : bool = True , runtime : str = None , ** kwargs ) : buildenv_target = self . targets [ buildenv_target_name ] redirection = any ( stream_key in kwargs for stream_key in ( 'stdin' , 'stdout' ,... | Run a command in a named BuildEnv Docker image . |
44,144 | def build_target ( self , target : Target ) : builder = Plugin . builders [ target . builder_name ] if builder . func : logger . debug ( 'About to invoke the {} builder function for {}' , target . builder_name , target . name ) builder . func ( self , target ) else : logger . debug ( 'Skipping {} builder function for t... | Invoke the builder function for a target . |
44,145 | def register_target_artifact_metadata ( self , target : str , metadata : dict ) : with self . context_lock : self . artifacts_metadata [ target . name ] = metadata | Register the artifact metadata dictionary for a built target . |
44,146 | def write_artifacts_metadata ( self ) : if self . conf . artifacts_metadata_file : logger . info ( 'Writing artifacts metadata to file "%s"' , self . conf . artifacts_metadata_file ) with open ( self . conf . artifacts_metadata_file , 'w' ) as fp : json . dump ( self . artifacts_metadata , fp ) | Write out a JSON file with all built targets artifact metadata if such output file is specified . |
44,147 | def get_build_file_path ( self , build_module ) -> str : project_root = Path ( self . project_root ) build_module = norm_proj_path ( build_module , '' ) return str ( project_root / build_module / ( BUILD_PROJ_FILE if '' == build_module else self . build_file_name ) ) | Return a full path to the build file of build_module . |
44,148 | def guess_uri_type ( uri : str , hint : str = None ) : if hint : return hint norm_uri = uri . lower ( ) parsed_uri = urlparse ( norm_uri ) if parsed_uri . path . endswith ( '.git' ) : return 'git' if parsed_uri . scheme in ( 'http' , 'https' ) : ext = splitext ( parsed_uri . path ) [ - 1 ] if ext in KNOWN_ARCHIVES : re... | Return a guess for the URI type based on the URI string uri . |
44,149 | def git_handler ( unused_build_context , target , fetch , package_dir , tar ) : target_name = split_name ( target . name ) repo_dir = join ( package_dir , fetch . name ) if fetch . name else package_dir try : repo = git . Repo ( repo_dir ) except ( InvalidGitRepositoryError , NoSuchPathError ) : repo = git . Repo . clo... | Handle remote Git repository URI . |
44,150 | def fetch_url ( url , dest , parent_to_remove_before_fetch ) : logger . debug ( 'Downloading file {} from {}' , dest , url ) try : shutil . rmtree ( parent_to_remove_before_fetch ) except FileNotFoundError : pass os . makedirs ( parent_to_remove_before_fetch ) resp = requests . get ( url , stream = True ) with open ( d... | Helper function to fetch a file from a URL . |
44,151 | def archive_handler ( unused_build_context , target , fetch , package_dir , tar ) : package_dest = join ( package_dir , basename ( urlparse ( fetch . uri ) . path ) ) package_content_dir = join ( package_dir , 'content' ) extract_dir = ( join ( package_content_dir , fetch . name ) if fetch . name else package_content_d... | Handle remote downloadable archive URI . |
44,152 | def fetch_file_handler ( unused_build_context , target , fetch , package_dir , tar ) : dl_dir = join ( package_dir , fetch . name ) if fetch . name else package_dir fetch_url ( fetch . uri , join ( dl_dir , basename ( urlparse ( fetch . uri ) . path ) ) , dl_dir ) tar . add ( package_dir , arcname = split_name ( target... | Handle remote downloadable file URI . |
44,153 | def get_installer_desc ( build_context , target ) -> tuple : workspace_dir = build_context . get_workspace ( 'CustomInstaller' , target . name ) target_name = split_name ( target . name ) script_name = basename ( target . props . script ) package_tarball = '{}.tar.gz' . format ( join ( workspace_dir , target_name ) ) r... | Return a target_name script_name package_tarball tuple for target |
44,154 | def get_prebuilt_targets ( build_context ) : logger . info ( 'Scanning for cached base images' ) contained_deps = set ( ) required_deps = set ( ) cached_descendants = CachedDescendants ( build_context . target_graph ) for target_name , target in build_context . targets . items ( ) : if 'image_caching_behavior' not in t... | Return set of target names that are contained within cached base images |
44,155 | def write_summary ( summary : dict , cache_dir : str ) : summary [ 'accessed' ] = time ( ) with open ( join ( cache_dir , 'summary.json' ) , 'w' ) as summary_file : summary_file . write ( json . dumps ( summary , indent = 4 , sort_keys = True ) ) | Write the summary JSON to cache_dir . |
44,156 | def copy_artifact ( src_path : str , artifact_hash : str , conf : Config ) : cache_dir = conf . get_artifacts_cache_dir ( ) if not isdir ( cache_dir ) : makedirs ( cache_dir ) cached_artifact_path = join ( cache_dir , artifact_hash ) if isfile ( cached_artifact_path ) or isdir ( cached_artifact_path ) : logger . debug ... | Copy the artifact at src_path with hash artifact_hash to artifacts cache dir . |
44,157 | def restore_artifact ( src_path : str , artifact_hash : str , conf : Config ) : cache_dir = conf . get_artifacts_cache_dir ( ) if not isdir ( cache_dir ) : return False cached_artifact_path = join ( cache_dir , artifact_hash ) if isfile ( cached_artifact_path ) or isdir ( cached_artifact_path ) : actual_hash = hash_tre... | Restore the artifact whose hash is artifact_hash to src_path . |
44,158 | def save_target_in_cache ( target : Target , build_context ) : cache_dir = build_context . conf . get_cache_dir ( target , build_context ) if isdir ( cache_dir ) : rmtree ( cache_dir ) makedirs ( cache_dir ) logger . debug ( 'Saving target metadata in cache under {}' , cache_dir ) with open ( join ( cache_dir , 'target... | Save target to build cache for future reuse . |
44,159 | def get ( self , key ) : if key not in self : self [ key ] = set ( get_descendants ( self . _target_graph , key ) ) return self [ key ] | Return set of descendants of node named key in target_graph . |
44,160 | def fatal ( msg , * args , ** kwargs ) : exc_str = format_exc ( ) if exc_str . strip ( ) != 'NoneType: None' : logger . info ( '{}' , format_exc ( ) ) fatal_noexc ( msg , * args , ** kwargs ) | Print a red msg to STDERR and exit . To be used in a context of an exception also prints out the exception . The message is formatted with args & kwargs . |
44,161 | def fatal_noexc ( msg , * args , ** kwargs ) : print ( Fore . RED + 'Fatal: ' + msg . format ( * args , ** kwargs ) + Style . RESET_ALL , file = sys . stderr ) sys . exit ( 1 ) | Print a red msg to STDERR and exit . |
44,162 | def rmnode ( path : str ) : if isdir ( path ) : rmtree ( path ) elif isfile ( path ) : os . remove ( path ) | Forcibly remove file or directory tree at path . Fail silently if base dir doesn t exist . |
44,163 | def link_files ( files : set , workspace_src_dir : str , common_parent : str , conf ) : norm_dir = normpath ( workspace_src_dir ) base_dir = '' if common_parent : common_parent = normpath ( common_parent ) base_dir = commonpath ( list ( files ) + [ common_parent ] ) if base_dir != common_parent : raise ValueError ( '{}... | Sync the list of files and directories in files to destination directory specified by workspace_src_dir . |
44,164 | def norm_proj_path ( path , build_module ) : if path == '//' : return '' if path . startswith ( '//' ) : norm = normpath ( path [ 2 : ] ) if norm [ 0 ] in ( '.' , '/' , '\\' ) : raise ValueError ( "Invalid path: `{}'" . format ( path ) ) return norm if path . startswith ( '/' ) : raise ValueError ( "Invalid path: `{}' ... | Return a normalized path for the path observed in build_module . |
44,165 | def acc_hash ( filepath : str , hasher ) : with open ( filepath , 'rb' ) as f : while True : chunk = f . read ( _BUF_SIZE ) if not chunk : break hasher . update ( chunk ) | Accumulate content of file at filepath in hasher . |
44,166 | def hash_file ( filepath : str ) -> str : md5 = hashlib . md5 ( ) acc_hash ( filepath , md5 ) return md5 . hexdigest ( ) | Return the hexdigest MD5 hash of content of file at filepath . |
44,167 | def hash_tree ( filepath : str ) -> str : if isfile ( filepath ) : return hash_file ( filepath ) if isdir ( filepath ) : base_dir = filepath md5 = hashlib . md5 ( ) for root , dirs , files in walk ( base_dir ) : dirs . sort ( ) for fname in sorted ( files ) : filepath = join ( root , fname ) md5 . update ( relpath ( fi... | Return the hexdigest MD5 hash of file or directory at filepath . |
44,168 | def add ( self , artifact_type : ArtifactType , src_path : str , dst_path : str = None ) : if dst_path is None : dst_path = src_path other_src_path = self . _artifacts [ artifact_type ] . setdefault ( dst_path , src_path ) if src_path != other_src_path : raise RuntimeError ( '{} artifact with dest path {} exists with d... | Add an artifact of type artifact_type at src_path . |
44,169 | def extend ( self , artifact_type : ArtifactType , src_paths : list ) : for src_path in src_paths : self . add ( artifact_type , src_path , src_path ) | Add all src_paths as artifact of type artifact_type . |
44,170 | def link_types ( self , base_dir : str , types : list , conf : Config ) -> int : num_linked = 0 for kind in types : artifact_map = self . _artifacts . get ( kind ) if not artifact_map : continue num_linked += self . _link ( join ( base_dir , self . type_to_dir [ kind ] ) , artifact_map , conf ) return num_linked | Link all artifacts with types types under base_dir and return the number of linked artifacts . |
44,171 | def link_for_image ( self , base_dir : str , conf : Config ) -> int : return self . link_types ( base_dir , [ ArtifactType . app , ArtifactType . binary , ArtifactType . gen_py ] , conf ) | Link all artifacts required for a Docker image under base_dir and return the number of linked artifacts . |
44,172 | def _link ( self , base_dir : str , artifact_map : dict , conf : Config ) : num_linked = 0 for dst , src in artifact_map . items ( ) : abs_src = join ( conf . project_root , src ) abs_dest = join ( conf . project_root , base_dir , dst ) link_node ( abs_src , abs_dest ) num_linked += 1 return num_linked | Link all artifacts in artifact_map under base_dir and return the number of artifacts linked . |
44,173 | def get_readme ( ) : base_dir = path . abspath ( path . dirname ( __file__ ) ) with open ( path . join ( base_dir , 'README.md' ) , encoding = 'utf-8' ) as readme_f : return readme_f . read ( ) | Read and return the content of the project README file . |
44,174 | def args_to_props ( target : Target , builder : Builder , args : list , kwargs : dict ) : if len ( args ) > len ( builder . sig ) : raise TypeError ( '{}() takes {}, but {} were given' . format ( target . builder_name , format_num_positional_arguments ( builder ) , len ( args ) ) ) for arg_name , value in zip ( builder... | Convert build file args and kwargs to target props . |
44,175 | def extractor ( builder_name : str , builder : Builder , build_file_path : str , build_context ) -> types . FunctionType : build_module = to_build_module ( build_file_path , build_context . conf ) def extract_target ( * args , ** kwargs ) : target = Target ( builder_name = builder_name ) args_to_props ( target , builde... | Return a target extraction function for a specific builder and a specific build file . |
44,176 | def rdopkg_runner ( ) : aman = ActionManager ( ) aman . add_actions_modules ( actions ) aman . fill_aliases ( ) return ActionRunner ( action_manager = aman ) | default rdopkg action runner including rdopkg action modules |
44,177 | def rdopkg ( * cargs ) : runner = rdopkg_runner ( ) return shell . run ( runner , cargs = cargs , prog = 'rdopkg' , version = __version__ ) | rdopkg CLI interface |
44,178 | def getDynDnsClientForConfig ( config , plugins = None ) : initparams = { } if "interval" in config : initparams [ "detect_interval" ] = config [ "interval" ] if plugins is not None : initparams [ "plugins" ] = plugins if "updater" in config : for updater_name , updater_options in config [ "updater" ] : initparams [ "u... | Instantiate and return a complete and working dyndns client . |
44,179 | def has_state_changed ( self ) : self . lastcheck = time . time ( ) if self . detector . can_detect_offline ( ) : self . detector . detect ( ) elif not self . dns . detect ( ) == self . detector . get_current_value ( ) : self . detector . detect ( ) if self . detector . has_changed ( ) : LOG . debug ( "detector changed... | Detect changes in offline detector and real DNS value . |
44,180 | def detect ( self ) : if self . opts_url and self . opts_parser : url = self . opts_url parser = self . opts_parser else : url , parser = choice ( self . urls ) parser = globals ( ) . get ( "_parser_" + parser ) theip = _get_ip_from_url ( url , parser ) if theip is None : LOG . info ( "Could not detect IP using webchec... | Try to contact a remote webservice and parse the returned output . |
44,181 | def add_plugin ( self , plugin , call ) : meth = getattr ( plugin , call , None ) if meth is not None : self . plugins . append ( ( plugin , meth ) ) | Add plugin to list of plugins . |
44,182 | def listcall ( self , * arg , ** kw ) : final_result = None for _ , meth in self . plugins : result = meth ( * arg , ** kw ) if final_result is None and result is not None : final_result = result return final_result | Call each plugin sequentially . |
44,183 | def add_plugin ( self , plugin ) : new_name = self . plugin_name ( plugin ) self . _plugins [ : ] = [ p for p in self . _plugins if self . plugin_name ( p ) != new_name ] self . _plugins . append ( plugin ) | Add the given plugin . |
44,184 | def configure ( self , args ) : for plug in self . _plugins : plug_name = self . plugin_name ( plug ) plug . enabled = getattr ( args , "plugin_%s" % plug_name , False ) if plug . enabled and getattr ( plug , "configure" , None ) : if callable ( getattr ( plug , "configure" , None ) ) : plug . configure ( args ) LOG . ... | Configure the set of plugins with the given args . |
44,185 | def options ( self , parser , env ) : def get_help ( plug ) : import textwrap if plug . __class__ . __doc__ : return textwrap . dedent ( plug . __class__ . __doc__ ) return "(no help available)" for plug in self . _plugins : env_opt = ENV_PREFIX + self . plugin_name ( plug ) . upper ( ) env_opt = env_opt . replace ( "-... | Register commandline options with the given parser . |
44,186 | def load_plugins ( self ) : from dyndnsc . plugins . builtin import PLUGINS for plugin in PLUGINS : self . add_plugin ( plugin ( ) ) super ( BuiltinPluginManager , self ) . load_plugins ( ) | Load plugins from dyndnsc . plugins . builtin . |
44,187 | def keys ( self , section = None ) : if not section and self . section : section = self . section config = self . config . get ( section , { } ) if section else self . config return config . keys ( ) | Provide dict like keys method |
44,188 | def items ( self , section = None ) : if not section and self . section : section = self . section config = self . config . get ( section , { } ) if section else self . config return config . items ( ) | Provide dict like items method |
44,189 | def values ( self , section = None ) : if not section and self . section : section = self . section config = self . config . get ( section , { } ) if section else self . config return config . values ( ) | Provide dict like values method |
44,190 | def _get_filepath ( self , filename = None , config_dir = None ) : config_file = None config_dir_env_var = self . env_prefix + '_DIR' if not filename : filename = os . getenv ( self . env_prefix , default = self . default_file ) if os . path . dirname ( filename ) and os . path . exists ( filename ) : config_file = fil... | Get config file . |
44,191 | def resolve ( hostname , family = AF_UNSPEC ) : af_ok = ( AF_INET , AF_INET6 ) if family != AF_UNSPEC and family not in af_ok : raise ValueError ( "Invalid family '%s'" % family ) ips = ( ) try : addrinfo = socket . getaddrinfo ( hostname , None , family ) except socket . gaierror as exc : if exc . errno not in ( socke... | Resolve hostname to one or more IP addresses through the operating system . |
44,192 | def detect ( self ) : theip = next ( iter ( resolve ( self . opts_hostname , self . opts_family ) ) , None ) self . set_current_value ( theip ) return theip | Resolve the hostname to an IP address through the operating system . |
44,193 | def list_presets ( cfg , out = sys . stdout ) : for section in cfg . sections ( ) : if section . startswith ( "preset:" ) : out . write ( ( section . replace ( "preset:" , "" ) ) + os . linesep ) for k , v in cfg . items ( section ) : out . write ( "\t%s = %s" % ( k , v ) + os . linesep ) | Write a human readable list of available presets to out . |
44,194 | def create_argparser ( ) : parser = argparse . ArgumentParser ( ) arg_defaults = { "daemon" : False , "loop" : False , "listpresets" : False , "config" : None , "debug" : False , "sleeptime" : 300 , "version" : False , "verbose_count" : 0 } parser . add_argument ( "-c" , "--config" , dest = "config" , help = "config fi... | Instantiate an argparse . ArgumentParser . |
44,195 | def run_forever ( dyndnsclients ) : while True : try : time . sleep ( 15 ) for dyndnsclient in dyndnsclients : dyndnsclient . check ( ) except ( KeyboardInterrupt , ) : break except ( Exception , ) as exc : LOG . critical ( "An exception occurred in the dyndns loop" , exc_info = exc ) return 0 | Run an endless loop accross the give dynamic dns clients . |
44,196 | def main ( ) : plugins = DefaultPluginManager ( ) plugins . load_plugins ( ) parser , _ = create_argparser ( ) for kls in updater_classes ( ) : kls . register_arguments ( parser ) for kls in detector_classes ( ) : kls . register_arguments ( parser ) from os import environ plugins . options ( parser , environ ) args = p... | Run the main CLI program . |
44,197 | def get_configuration ( config_file = None ) : parser = configparser . ConfigParser ( ) if config_file is None : config_file = os . path . join ( os . getenv ( "HOME" ) , DEFAULT_USER_INI ) if not os . path . isfile ( config_file ) : config_file = None else : if not os . path . isfile ( config_file ) : raise ValueError... | Return an initialized ConfigParser . |
44,198 | def collect_config ( cfg ) : collected_configs = { } _updater_str = "updater" _detector_str = "detector" _dash = "-" for client_name , client_cfg_dict in _iraw_client_configs ( cfg ) : detector_name = None detector_options = { } updater_name = None updater_options = { } collected_config = { } for k in client_cfg_dict :... | Construct configuration dictionary from configparser . |
44,199 | def detect ( self ) : if PY3 : import subprocess else : import commands as subprocess try : theip = subprocess . getoutput ( self . opts_command ) except Exception : theip = None self . set_current_value ( theip ) return theip | Detect and return the IP address . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.