idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
23,500 | def get_cookbook_dirs ( self , base_dir = None ) : if base_dir is None : base_dir = self . env_root cookbook_dirs = [ ] dirs_to_skip = set ( [ '.git' ] ) for root , dirs , files in os . walk ( base_dir ) : dirs [ : ] = [ d for d in dirs if d not in dirs_to_skip ] for name in files : if name == 'metadata.rb' : if 'cookb... | Find cookbook directories . |
23,501 | def path_only_contains_dirs ( self , path ) : pathlistdir = os . listdir ( path ) if pathlistdir == [ ] : return True if any ( os . path . isfile ( os . path . join ( path , i ) ) for i in pathlistdir ) : return False return all ( self . path_only_contains_dirs ( os . path . join ( path , i ) ) for i in pathlistdir ) | Return boolean on whether a path only contains directories . |
23,502 | def get_empty_dirs ( self , path ) : empty_dirs = [ ] for i in os . listdir ( path ) : child_path = os . path . join ( path , i ) if i == '.git' or os . path . isfile ( child_path ) or os . path . islink ( child_path ) : continue if self . path_only_contains_dirs ( child_path ) : empty_dirs . append ( i ) return empty_... | Return a list of empty directories in path . |
23,503 | def parse_runway_config ( self ) : if not os . path . isfile ( self . runway_config_path ) : LOGGER . error ( "Runway config file was not found (looking for " "%s)" , self . runway_config_path ) sys . exit ( 1 ) with open ( self . runway_config_path ) as data_file : return yaml . safe_load ( data_file ) | Read and parse runway . yml . |
23,504 | def runway_config ( self ) : if not self . _runway_config : self . _runway_config = self . parse_runway_config ( ) return self . _runway_config | Return parsed runway . yml . |
23,505 | def purge_bucket ( context , provider , ** kwargs ) : session = get_session ( provider . region ) if kwargs . get ( 'bucket_name' ) : bucket_name = kwargs [ 'bucket_name' ] else : if kwargs . get ( 'bucket_output_lookup' ) : value = kwargs [ 'bucket_output_lookup' ] handler = OutputLookup . handle elif kwargs . get ( '... | Delete objects in bucket . |
23,506 | def execute ( self ) : logging . getLogger ( 'runway' ) . setLevel ( logging . ERROR ) if not os . path . isfile ( 'runway.yml' ) : self . env_root = os . path . dirname ( os . getcwd ( ) ) self . runway_config_path = os . path . join ( self . env_root , 'runway.yml' ) print ( get_env ( self . env_root , self . runway_... | Output environment name . |
23,507 | def update_api_endpoint ( ) : environment = subprocess . check_output ( [ 'pipenv' , 'run' , 'runway' , 'whichenv' ] ) . decode ( ) . strip ( ) environment_file = os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , 'src' , 'environments' , 'environment.prod.ts' if environment == 'prod' else '... | Update app environment file with backend endpoint . |
23,508 | def change_dir ( newdir ) : prevdir = os . getcwd ( ) os . chdir ( os . path . expanduser ( newdir ) ) try : yield finally : os . chdir ( prevdir ) | Change directory . |
23,509 | def ensure_file_is_executable ( path ) : if platform . system ( ) != 'Windows' and ( not stat . S_IXUSR & os . stat ( path ) [ stat . ST_MODE ] ) : print ( "Error: File %s is not executable" % path ) sys . exit ( 1 ) | Exit if file is not executable . |
23,510 | def merge_dicts ( dict1 , dict2 , deep_merge = True ) : if deep_merge : if isinstance ( dict1 , list ) and isinstance ( dict2 , list ) : return dict1 + dict2 if not isinstance ( dict1 , dict ) or not isinstance ( dict2 , dict ) : return dict2 for key in dict2 : dict1 [ key ] = merge_dicts ( dict1 [ key ] , dict2 [ key ... | Merge dict2 into dict1 . |
23,511 | def extract_boto_args_from_env ( env_vars ) : boto_args = { } for i in [ 'aws_access_key_id' , 'aws_secret_access_key' , 'aws_session_token' ] : if env_vars . get ( i . upper ( ) ) : boto_args [ i ] = env_vars [ i . upper ( ) ] return boto_args | Return boto3 client args dict with environment creds . |
23,512 | def flatten_path_lists ( env_dict , env_root = None ) : for ( key , val ) in env_dict . items ( ) : if isinstance ( val , list ) : env_dict [ key ] = os . path . join ( env_root , os . path . join ( * val ) ) if ( env_root and not os . path . isabs ( os . path . join ( * val ) ) ) else os . path . join ( * val ) return... | Join paths in environment dict down to strings . |
23,513 | def merge_nested_environment_dicts ( env_dicts , env_name = None , env_root = None ) : if all ( isinstance ( val , ( six . string_types , list ) ) for ( _key , val ) in env_dicts . items ( ) ) : return flatten_path_lists ( env_dicts , env_root ) if env_name is None : if env_dicts . get ( '*' ) : return flatten_path_lis... | Return single - level dictionary from dictionary of dictionaries . |
23,514 | def get_embedded_lib_path ( ) : return os . path . join ( os . path . dirname ( os . path . abspath ( __file__ ) ) , 'embedded' ) | Return path of embedded libraries . |
23,515 | def get_hash_for_filename ( filename , hashfile_path ) : filehash = '' with open ( hashfile_path , 'r' ) as stream : for _cnt , line in enumerate ( stream ) : if line . rstrip ( ) . endswith ( filename ) : filehash = re . match ( r'^[A-Za-z0-9]*' , line ) . group ( 0 ) break if filehash : return filehash raise Attribut... | Return hash for filename in the hashfile . |
23,516 | def fix_windows_command_list ( commands ) : fully_qualified_cmd_path = which ( commands [ 0 ] ) if fully_qualified_cmd_path and ( not which ( commands [ 0 ] , add_win_suffixes = False ) ) : commands [ 0 ] = os . path . basename ( fully_qualified_cmd_path ) return commands | Return command list with working Windows commands . |
23,517 | def run_commands ( commands , directory , env = None ) : if env is None : env = os . environ . copy ( ) for step in commands : if isinstance ( step , ( list , six . string_types ) ) : execution_dir = directory raw_command = step elif step . get ( 'command' ) : execution_dir = os . path . join ( directory , step . get (... | Run list of commands . |
23,518 | def sha256sum ( filename ) : sha256 = hashlib . sha256 ( ) mem_view = memoryview ( bytearray ( 128 * 1024 ) ) with open ( filename , 'rb' , buffering = 0 ) as stream : for i in iter ( lambda : stream . readinto ( mem_view ) , 0 ) : sha256 . update ( mem_view [ : i ] ) return sha256 . hexdigest ( ) | Return SHA256 hash of file . |
23,519 | def use_embedded_pkgs ( embedded_lib_path = None ) : if embedded_lib_path is None : embedded_lib_path = get_embedded_lib_path ( ) old_sys_path = list ( sys . path ) sys . path . insert ( 1 , embedded_lib_path ) try : yield finally : sys . path = old_sys_path | Temporarily prepend embedded packages to sys . path . |
23,520 | def which ( program , add_win_suffixes = True ) : def is_exe ( fpath ) : return os . path . isfile ( fpath ) and os . access ( fpath , os . X_OK ) fpath , fname = os . path . split ( program ) if add_win_suffixes and platform . system ( ) . lower ( ) == 'windows' and not ( fname . endswith ( '.exe' ) or fname . endswit... | Mimic which command behavior . |
23,521 | def create_config_backend_options ( module_opts , env_name , env_vars ) : backend_opts = { } if module_opts . get ( 'terraform_backend_config' ) : backend_opts [ 'config' ] = merge_nested_environment_dicts ( module_opts . get ( 'terraform_backend_config' ) , env_name ) if module_opts . get ( 'terraform_backend_cfn_outp... | Return backend options defined in module options . |
23,522 | def get_backend_init_list ( backend_vals ) : cmd_list = [ ] for ( key , val ) in backend_vals . items ( ) : cmd_list . append ( '-backend-config' ) cmd_list . append ( key + '=' + val ) return cmd_list | Turn backend config dict into command line items . |
23,523 | def get_backend_tfvars_file ( path , environment , region ) : backend_filenames = gen_backend_tfvars_files ( environment , region ) for name in backend_filenames : if os . path . isfile ( os . path . join ( path , name ) ) : return name return backend_filenames [ - 1 ] | Determine Terraform backend file . |
23,524 | def get_module_defined_tf_var ( terraform_version_opts , env_name ) : if isinstance ( terraform_version_opts , six . string_types ) : return terraform_version_opts if terraform_version_opts . get ( env_name ) : return terraform_version_opts . get ( env_name ) if terraform_version_opts . get ( '*' ) : return terraform_v... | Return version of Terraform requested in module options . |
23,525 | def get_workspace_tfvars_file ( path , environment , region ) : for name in gen_workspace_tfvars_files ( environment , region ) : if os . path . isfile ( os . path . join ( path , name ) ) : return name return "%s.tfvars" % environment | Determine Terraform workspace - specific tfvars file name . |
23,526 | def reinit_on_backend_changes ( tf_bin , module_path , backend_options , env_name , env_region , env_vars ) : terraform_dir = os . path . join ( module_path , '.terraform' ) local_tfstate_path = os . path . join ( terraform_dir , 'terraform.tfstate' ) current_backend_config = { } desired_backend_config = { } LOGGER . d... | Clean terraform directory and run init if necessary . |
23,527 | def run_terraform_init ( tf_bin , module_path , backend_options , env_name , env_region , env_vars ) : init_cmd = [ tf_bin , 'init' ] cmd_opts = { 'env_vars' : env_vars , 'exit_on_error' : False } if backend_options . get ( 'config' ) : LOGGER . info ( 'Using provided backend values "%s"' , str ( backend_options . get ... | Run Terraform init . |
23,528 | def find_command_class ( possible_command_names ) : for command_name in possible_command_names : if hasattr ( ALL_COMMANDS_MODULE , command_name ) : command_module = getattr ( ALL_COMMANDS_MODULE , command_name ) command_class_hierarchy = getmembers ( command_module , isclass ) command_class_tuple = list ( filter ( _no... | Try to find a class for one of the given command names . |
23,529 | def generate_sample_module ( module_dir ) : if os . path . isdir ( module_dir ) : LOGGER . error ( "Error generating sample module -- directory %s " "already exists!" , module_dir ) sys . exit ( 1 ) os . mkdir ( module_dir ) | Generate skeleton sample module . |
23,530 | def generate_sample_sls_module ( env_root , module_dir = None ) : if module_dir is None : module_dir = os . path . join ( env_root , 'sampleapp.sls' ) generate_sample_module ( module_dir ) for i in [ 'config-dev-us-east-1.json' , 'handler.py' , 'package.json' , 'serverless.yml' ] : shutil . copyfile ( os . path . join ... | Generate skeleton Serverless sample module . |
23,531 | def generate_sample_sls_tsc_module ( env_root , module_dir = None ) : if module_dir is None : module_dir = os . path . join ( env_root , 'sampleapp.sls' ) generate_sample_module ( module_dir ) for i in [ 'package.json' , 'serverless.yml' , 'tsconfig.json' , 'webpack.config.js' ] : shutil . copyfile ( os . path . join (... | Generate skeleton Serverless TypeScript sample module . |
23,532 | def generate_sample_cdk_tsc_module ( env_root , module_dir = None ) : if module_dir is None : module_dir = os . path . join ( env_root , 'sampleapp.cdk' ) generate_sample_module ( module_dir ) for i in [ '.npmignore' , 'cdk.json' , 'package.json' , 'runway.module.yml' , 'tsconfig.json' , 'README.md' ] : shutil . copyfi... | Generate skeleton CDK TS sample module . |
23,533 | def generate_sample_cdk_py_module ( env_root , module_dir = None ) : if module_dir is None : module_dir = os . path . join ( env_root , 'sampleapp.cdk' ) generate_sample_module ( module_dir ) for i in [ 'app.py' , 'cdk.json' , 'lambda-index.py' , 'package.json' , 'runway.module.yml' , 'Pipfile' ] : shutil . copyfile ( ... | Generate skeleton CDK python sample module . |
23,534 | def generate_sample_cfn_module ( env_root , module_dir = None ) : if module_dir is None : module_dir = os . path . join ( env_root , 'sampleapp.cfn' ) generate_sample_module ( module_dir ) for i in [ 'stacks.yaml' , 'dev-us-east-1.env' ] : shutil . copyfile ( os . path . join ( ROOT , 'templates' , 'cfn' , i ) , os . p... | Generate skeleton CloudFormation sample module . |
23,535 | def generate_sample_stacker_module ( env_root , module_dir = None ) : if module_dir is None : module_dir = os . path . join ( env_root , 'runway-sample-tfstate.cfn' ) generate_sample_module ( module_dir ) for i in [ 'stacks.yaml' , 'dev-us-east-1.env' ] : shutil . copyfile ( os . path . join ( ROOT , 'templates' , 'sta... | Generate skeleton Stacker sample module . |
23,536 | def generate_sample_tf_module ( env_root , module_dir = None ) : if module_dir is None : module_dir = os . path . join ( env_root , 'sampleapp.tf' ) generate_sample_module ( module_dir ) for i in [ 'backend-us-east-1.tfvars' , 'dev-us-east-1.tfvars' , 'main.tf' ] : shutil . copyfile ( os . path . join ( ROOT , 'templat... | Generate skeleton Terraform sample module . |
23,537 | def execute ( self ) : if self . _cli_arguments [ 'cfn' ] : generate_sample_cfn_module ( self . env_root ) elif self . _cli_arguments [ 'sls' ] : generate_sample_sls_module ( self . env_root ) elif self . _cli_arguments [ 'sls-tsc' ] : generate_sample_sls_tsc_module ( self . env_root ) elif self . _cli_arguments [ 'sta... | Run selected module generator . |
23,538 | def execute ( self ) : if os . path . isfile ( 'runway.yml' ) : print ( 'Runway config already present' ) sys . exit ( 1 ) with open ( 'runway.yml' , 'w' ) as stream : stream . write ( ) print ( 'runway.yml generated' ) print ( 'See additional getting started information at ' 'https://docs.onica.com/projects/runway/en/... | Generate runway . yml . |
23,539 | def does_s3_object_exist ( bucket_name , key , session = None ) : if session : s3_resource = session . resource ( 's3' ) else : s3_resource = boto3 . resource ( 's3' ) try : s3_resource . Object ( bucket_name , key ) . load ( ) except ClientError as exc : if exc . response [ 'Error' ] [ 'Code' ] == '404' : return False... | Determine if object exists on s3 . |
23,540 | def download_and_extract_to_mkdtemp ( bucket , key , session = None ) : if session : s3_client = session . client ( 's3' ) else : s3_client = boto3 . client ( 's3' ) transfer = S3Transfer ( s3_client ) filedes , temp_file = tempfile . mkstemp ( ) os . close ( filedes ) transfer . download_file ( bucket , key , temp_fil... | Download zip archive and extract it to temporary directory . |
23,541 | def zip_and_upload ( app_dir , bucket , key , session = None ) : if session : s3_client = session . client ( 's3' ) else : s3_client = boto3 . client ( 's3' ) transfer = S3Transfer ( s3_client ) filedes , temp_file = tempfile . mkstemp ( ) os . close ( filedes ) LOGGER . info ( "staticsite: archiving app at %s to s3://... | Zip built static site and upload to S3 . |
23,542 | def build ( context , provider , ** kwargs ) : session = get_session ( provider . region ) options = kwargs . get ( 'options' , { } ) context_dict = { } context_dict [ 'artifact_key_prefix' ] = "%s-%s-" % ( options [ 'namespace' ] , options [ 'name' ] ) default_param_name = "%shash" % context_dict [ 'artifact_key_prefi... | Build static site . |
23,543 | def ensure_valid_environment_config ( module_name , config ) : if not config . get ( 'namespace' ) : LOGGER . fatal ( "staticsite: module %s's environment configuration is " "missing a namespace definition!" , module_name ) sys . exit ( 1 ) | Exit if config is invalid . |
23,544 | def plan ( self ) : if self . options . get ( 'environments' , { } ) . get ( self . context . env_name ) : self . setup_website_module ( command = 'plan' ) else : LOGGER . info ( "Skipping staticsite plan of %s; no environment " "config found for this environment/region" , self . options [ 'path' ] ) | Create website CFN module and run stacker diff . |
23,545 | def format_npm_command_for_logging ( command ) : if platform . system ( ) . lower ( ) == 'windows' : if command [ 0 ] == 'npx.cmd' and command [ 1 ] == '-c' : return "npx.cmd -c \"%s\"" % " " . join ( command [ 2 : ] ) return " " . join ( command ) return " " . join ( command ) . replace ( '\'\'' , '\'' ) | Convert npm command list to string for display to user . |
23,546 | def generate_node_command ( command , command_opts , path ) : if which ( NPX_BIN ) : LOGGER . debug ( "Using npx to invoke %s." , command ) if platform . system ( ) . lower ( ) == 'windows' : cmd_list = [ NPX_BIN , '-c' , "%s %s" % ( command , ' ' . join ( command_opts ) ) ] else : cmd_list = [ NPX_BIN , '-c' , "''%s %... | Return node bin command list for subprocess execution . |
23,547 | def run_module_command ( cmd_list , env_vars , exit_on_error = True ) : if exit_on_error : try : subprocess . check_call ( cmd_list , env = env_vars ) except subprocess . CalledProcessError as shelloutexc : sys . exit ( shelloutexc . returncode ) else : subprocess . check_call ( cmd_list , env = env_vars ) | Shell out to provisioner command . |
23,548 | def use_npm_ci ( path ) : with open ( os . devnull , 'w' ) as fnull : if ( ( os . path . isfile ( os . path . join ( path , 'package-lock.json' ) ) or os . path . isfile ( os . path . join ( path , 'npm-shrinkwrap.json' ) ) ) and subprocess . call ( [ NPM_BIN , 'ci' , '-h' ] , stdout = fnull , stderr = subprocess . STD... | Return true if npm ci should be used in lieu of npm install . |
23,549 | def cdk_module_matches_env ( env_name , env_config , env_vars ) : if env_config . get ( env_name ) : current_env_config = env_config [ env_name ] if isinstance ( current_env_config , type ( True ) ) and current_env_config : return True if isinstance ( current_env_config , six . string_types ) : ( account_id , region ) ... | Return bool on whether cdk command should continue in current env . |
23,550 | def get_cdk_stacks ( module_path , env_vars , context_opts ) : LOGGER . debug ( 'Listing stacks in the CDK app prior to ' 'diff' ) return subprocess . check_output ( generate_node_command ( command = 'cdk' , command_opts = [ 'list' ] + context_opts , path = module_path ) , env = env_vars ) . strip ( ) . split ( '\n' ) | Return list of CDK stacks . |
23,551 | def assume_role ( role_arn , session_name = None , duration_seconds = None , region = 'us-east-1' , env_vars = None ) : if session_name is None : session_name = 'runway' assume_role_opts = { 'RoleArn' : role_arn , 'RoleSessionName' : session_name } if duration_seconds : assume_role_opts [ 'DurationSeconds' ] = int ( du... | Assume IAM role . |
23,552 | def determine_module_class ( path , class_path ) : if not class_path : basename = os . path . basename ( path ) if basename . endswith ( '.sls' ) : class_path = 'runway.module.serverless.Serverless' elif basename . endswith ( '.tf' ) : class_path = 'runway.module.terraform.Terraform' elif basename . endswith ( '.cdk' )... | Determine type of module and return deployment module class . |
23,553 | def load_module_opts_from_file ( path , module_options ) : module_options_file = os . path . join ( path , 'runway.module.yml' ) if os . path . isfile ( module_options_file ) : with open ( module_options_file , 'r' ) as stream : module_options = merge_dicts ( module_options , yaml . safe_load ( stream ) ) return module... | Update module_options with any options defined in module path . |
23,554 | def post_deploy_assume_role ( assume_role_config , context ) : if isinstance ( assume_role_config , dict ) : if assume_role_config . get ( 'post_deploy_env_revert' ) : context . restore_existing_iam_env_vars ( ) | Revert to previous credentials if necessary . |
23,555 | def validate_account_alias ( iam_client , account_alias ) : current_account_aliases = [ ] paginator = iam_client . get_paginator ( 'list_account_aliases' ) response_iterator = paginator . paginate ( ) for page in response_iterator : current_account_aliases . extend ( page . get ( 'AccountAliases' , [ ] ) ) if account_a... | Exit if list_account_aliases doesn t include account_alias . |
23,556 | def validate_account_id ( sts_client , account_id ) : resp = sts_client . get_caller_identity ( ) if 'Account' in resp : if resp [ 'Account' ] == account_id : LOGGER . info ( 'Verified current AWS account matches required ' 'account id %s.' , account_id ) else : LOGGER . error ( 'Current AWS account %s does not match '... | Exit if get_caller_identity doesn t match account_id . |
23,557 | def validate_account_credentials ( deployment , context ) : boto_args = { 'region_name' : context . env_vars [ 'AWS_DEFAULT_REGION' ] } for i in [ 'aws_access_key_id' , 'aws_secret_access_key' , 'aws_session_token' ] : if context . env_vars . get ( i . upper ( ) ) : boto_args [ i ] = context . env_vars [ i . upper ( ) ... | Exit if requested deployment account doesn t match credentials . |
23,558 | def echo_detected_environment ( env_name , env_vars ) : env_override_name = 'DEPLOY_ENVIRONMENT' LOGGER . info ( "" ) if env_override_name in env_vars : LOGGER . info ( "Environment \"%s\" was determined from the %s environment variable." , env_name , env_override_name ) LOGGER . info ( "If this is not correct, update ... | Print a helper note about how the environment was determined . |
23,559 | def _module_menu_entry ( module , environment_name ) : name = _module_name_for_display ( module ) if isinstance ( module , dict ) : environment_config = module . get ( 'environments' , { } ) . get ( environment_name ) if environment_config : return "%s (%s)" % ( name , environment_config ) return "%s" % ( name ) | Build a string to display in the select module menu . |
23,560 | def _deployment_menu_entry ( deployment ) : paths = ", " . join ( [ _module_name_for_display ( module ) for module in deployment [ 'modules' ] ] ) regions = ", " . join ( deployment . get ( 'regions' , [ ] ) ) return "%s - %s (%s)" % ( deployment . get ( 'name' ) , paths , regions ) | Build a string to display in the select deployment menu . |
23,561 | def select_deployment_to_run ( env_name , deployments = None , command = 'build' ) : if deployments is None or not deployments : return [ ] deployments_to_run = [ ] num_deployments = len ( deployments ) if num_deployments == 1 : selected_deployment_index = 1 else : print ( '' ) print ( 'Configured deployments:' ) for i... | Query user for deployments to run . |
23,562 | def gen_sls_config_files ( stage , region ) : names = [ ] for ext in [ 'yml' , 'json' ] : names . append ( os . path . join ( 'env' , "%s-%s.%s" % ( stage , region , ext ) ) ) names . append ( "config-%s-%s.%s" % ( stage , region , ext ) ) names . append ( os . path . join ( 'env' , "%s.%s" % ( stage , ext ) ) ) names ... | Generate possible SLS config files names . |
23,563 | def get_sls_config_file ( path , stage , region ) : for name in gen_sls_config_files ( stage , region ) : if os . path . isfile ( os . path . join ( path , name ) ) : return name return "config-%s.json" % stage | Determine Serverless config file name . |
23,564 | def run_sls_remove ( sls_cmd , env_vars ) : sls_process = subprocess . Popen ( sls_cmd , stdout = subprocess . PIPE , env = env_vars ) stdoutdata , _stderrdata = sls_process . communicate ( ) sls_return = sls_process . wait ( ) print ( stdoutdata ) if sls_return != 0 and ( sls_return == 1 and not ( re . search ( r"Stac... | Run sls remove command . |
23,565 | def run_serverless ( self , command = 'deploy' ) : response = { 'skipped_configs' : False } sls_opts = [ command ] if not which ( 'npm' ) : LOGGER . error ( '"npm" not found in path or is not executable; ' 'please ensure it is installed correctly.' ) sys . exit ( 1 ) if 'CI' in self . context . env_vars and command != ... | Run Serverless . |
23,566 | def aws_cli ( * cmd ) : old_env = dict ( os . environ ) try : env = os . environ . copy ( ) env [ 'LC_CTYPE' ] = u'en_US.UTF' os . environ . update ( env ) exit_code = create_clidriver ( ) . main ( * cmd ) if exit_code > 0 : raise RuntimeError ( 'AWS CLI exited with code {}' . format ( exit_code ) ) finally : os . envi... | Invoke aws command . |
23,567 | def get_archives_to_prune ( archives , hook_data ) : files_to_skip = [ ] for i in [ 'current_archive_filename' , 'old_archive_filename' ] : if hook_data . get ( i ) : files_to_skip . append ( hook_data [ i ] ) archives . sort ( key = itemgetter ( 'LastModified' ) , reverse = False ) return [ i [ 'Key' ] for i in archiv... | Return list of keys to delete . |
23,568 | def sync ( context , provider , ** kwargs ) : session = get_session ( provider . region ) bucket_name = OutputLookup . handle ( kwargs . get ( 'bucket_output_lookup' ) , provider = provider , context = context ) if context . hook_data [ 'staticsite' ] [ 'deploy_is_current' ] : LOGGER . info ( 'staticsite: skipping uplo... | Sync static website to S3 bucket . |
23,569 | def ensure_stacker_compat_config ( config_filename ) : try : with open ( config_filename , 'r' ) as stream : yaml . safe_load ( stream ) except yaml . constructor . ConstructorError as yaml_error : if yaml_error . problem . startswith ( 'could not determine a constructor for the tag \'!' ) : LOGGER . error ( '"%s" appe... | Ensure config file can be loaded by Stacker . |
23,570 | def get_stacker_env_file ( path , environment , region ) : for name in gen_stacker_env_files ( environment , region ) : if os . path . isfile ( os . path . join ( path , name ) ) : return name return "%s-%s.env" % ( environment , region ) | Determine Stacker environment file name . |
23,571 | def make_stacker_cmd_string ( args , lib_path ) : if platform . system ( ) . lower ( ) == 'windows' : lib_path = lib_path . replace ( '\\' , '/' ) return ( "import sys;" "sys.argv = ['stacker'] + {args};" "sys.path.insert(1, '{lib_path}');" "from stacker.logger import setup_logging;" "from stacker.commands import Stack... | Generate stacker invocation script from command line arg list . |
23,572 | def run_stacker ( self , command = 'diff' ) : response = { 'skipped_configs' : False } stacker_cmd = [ command , "--region=%s" % self . context . env_region ] if command == 'destroy' : stacker_cmd . append ( '--force' ) elif command == 'build' : if 'CI' in self . context . env_vars : stacker_cmd . append ( '--recreate-... | Run Stacker . |
23,573 | def get_cf_distribution_class ( ) : if LooseVersion ( troposphere . __version__ ) == LooseVersion ( '2.4.0' ) : cf_dist = cloudfront . Distribution cf_dist . props [ 'DistributionConfig' ] = ( DistributionConfig , True ) return cf_dist return cloudfront . Distribution | Return the correct troposphere CF distribution class . |
23,574 | def get_s3_origin_conf_class ( ) : if LooseVersion ( troposphere . __version__ ) > LooseVersion ( '2.4.0' ) : return cloudfront . S3OriginConfig if LooseVersion ( troposphere . __version__ ) == LooseVersion ( '2.4.0' ) : return S3OriginConfig return cloudfront . S3Origin | Return the correct S3 Origin Config class for troposphere . |
23,575 | def set_available ( self , show = None ) : show = self . state . show if show is None else show self . set_presence ( PresenceState ( available = True , show = show ) ) | Sets the agent availability to True . |
23,576 | def set_unavailable ( self ) : show = PresenceShow . NONE self . set_presence ( PresenceState ( available = False , show = show ) ) | Sets the agent availability to False . |
23,577 | def set_presence ( self , state = None , status = None , priority = None ) : state = state if state is not None else self . state status = status if status is not None else self . status priority = priority if priority is not None else self . priority self . presenceserver . set_presence ( state , status , priority ) | Change the presence broadcast by the client . If the client is currently connected the new presence is broadcast immediately . |
23,578 | def get_contacts ( self ) : for jid , item in self . roster . items . items ( ) : try : self . _contacts [ jid . bare ( ) ] . update ( item . export_as_json ( ) ) except KeyError : self . _contacts [ jid . bare ( ) ] = item . export_as_json ( ) return self . _contacts | Returns list of contacts |
23,579 | def get_contact ( self , jid ) : try : return self . get_contacts ( ) [ jid . bare ( ) ] except KeyError : raise ContactNotFound except AttributeError : raise AttributeError ( "jid must be an aioxmpp.JID object" ) | Returns a contact |
23,580 | def subscribe ( self , peer_jid ) : self . roster . subscribe ( aioxmpp . JID . fromstr ( peer_jid ) . bare ( ) ) | Asks for subscription |
23,581 | def unsubscribe ( self , peer_jid ) : self . roster . unsubscribe ( aioxmpp . JID . fromstr ( peer_jid ) . bare ( ) ) | Asks for unsubscription |
23,582 | def approve ( self , peer_jid ) : self . roster . approve ( aioxmpp . JID . fromstr ( peer_jid ) . bare ( ) ) | Approve a subscription request from jid |
23,583 | def append ( self , event , category = None ) : date = datetime . datetime . now ( ) self . store . insert ( 0 , ( date , event , category ) ) if len ( self . store ) > self . size : del self . store [ - 1 ] | Adds a new event to the trace store . The event may hava a category |
23,584 | def filter ( self , limit = None , to = None , category = None ) : if category and not to : msg_slice = itertools . islice ( ( x for x in self . store if x [ 2 ] == category ) , limit ) elif to and not category : to = JID . fromstr ( to ) msg_slice = itertools . islice ( ( x for x in self . store if _agent_in_msg ( to ... | Returns the events that match the filters |
23,585 | def start ( self , auto_register = True ) : return self . container . start_agent ( agent = self , auto_register = auto_register ) | Tells the container to start this agent . It returns a coroutine or a future depending on whether it is called from a coroutine or a synchronous method . |
23,586 | async def _async_connect ( self ) : try : self . conn_coro = self . client . connected ( ) aenter = type ( self . conn_coro ) . __aenter__ ( self . conn_coro ) self . stream = await aenter logger . info ( f"Agent {str(self.jid)} connected and authenticated." ) except aiosasl . AuthenticationFailure : raise Authenticati... | connect and authenticate to the XMPP server . Async mode . |
23,587 | async def _async_register ( self ) : metadata = aioxmpp . make_security_layer ( None , no_verify = not self . verify_security ) query = ibr . Query ( self . jid . localpart , self . password ) _ , stream , features = await aioxmpp . node . connect_xmlstream ( self . jid , metadata , loop = self . loop ) await ibr . reg... | Register the agent in the XMPP server from a coroutine . |
23,588 | def build_avatar_url ( jid ) : digest = md5 ( str ( jid ) . encode ( "utf-8" ) ) . hexdigest ( ) return "http://www.gravatar.com/avatar/{md5}?d=monsterid" . format ( md5 = digest ) | Static method to build a gravatar url with the agent s JID |
23,589 | def add_behaviour ( self , behaviour , template = None ) : behaviour . set_agent ( self ) if issubclass ( type ( behaviour ) , FSMBehaviour ) : for _ , state in behaviour . get_states ( ) . items ( ) : state . set_agent ( self ) behaviour . set_template ( template ) self . behaviours . append ( behaviour ) if self . is... | Adds and starts a behaviour to the agent . If template is not None it is used to match new messages and deliver them to the behaviour . |
23,590 | def remove_behaviour ( self , behaviour ) : if not self . has_behaviour ( behaviour ) : raise ValueError ( "This behaviour is not registered" ) index = self . behaviours . index ( behaviour ) self . behaviours [ index ] . kill ( ) self . behaviours . pop ( index ) | Removes a behaviour from the agent . The behaviour is first killed . |
23,591 | async def _async_stop ( self ) : if self . presence : self . presence . set_unavailable ( ) for behav in self . behaviours : behav . kill ( ) if self . web . is_started ( ) : await self . web . runner . cleanup ( ) if self . is_alive ( ) : self . client . stop ( ) aexit = self . conn_coro . __aexit__ ( * sys . exc_info... | Stops an agent and kills all its behaviours . |
23,592 | def _message_received ( self , msg ) : msg = Message . from_node ( msg ) return self . dispatch ( msg ) | Callback run when an XMPP Message is reveived . This callback delivers the message to every behaviour that is waiting for it . First the aioxmpp . Message is converted to spade . message . Message |
23,593 | def dispatch ( self , msg ) : logger . debug ( f"Got message: {msg}" ) futures = [ ] matched = False for behaviour in ( x for x in self . behaviours if x . match ( msg ) ) : futures . append ( self . submit ( behaviour . enqueue ( msg ) ) ) logger . debug ( f"Message enqueued to behaviour: {behaviour}" ) self . traces ... | Dispatch the message to every behaviour that is waiting for it using their templates match . |
23,594 | def from_node ( cls , node ) : if not isinstance ( node , aioxmpp . stanza . Message ) : raise AttributeError ( "node must be a aioxmpp.stanza.Message instance" ) msg = cls ( ) msg . _to = node . to msg . _sender = node . from_ if None in node . body : msg . body = node . body [ None ] else : for key in node . body . k... | Creates a new spade . message . Message from an aixoxmpp . stanza . Message |
23,595 | def to ( self , jid : str ) : if jid is not None and not isinstance ( jid , str ) : raise TypeError ( "'to' MUST be a string" ) self . _to = aioxmpp . JID . fromstr ( jid ) if jid is not None else None | Set jid of the receiver . |
23,596 | def sender ( self , jid : str ) : if jid is not None and not isinstance ( jid , str ) : raise TypeError ( "'sender' MUST be a string" ) self . _sender = aioxmpp . JID . fromstr ( jid ) if jid is not None else None | Set jid of the sender |
23,597 | def thread ( self , value : str ) : if value is not None and not isinstance ( value , str ) : raise TypeError ( "'thread' MUST be a string" ) self . _thread = value | Set thread id of the message |
23,598 | def set_metadata ( self , key : str , value : str ) : if not isinstance ( key , str ) or not isinstance ( value , str ) : raise TypeError ( "'key' and 'value' of metadata MUST be strings" ) self . metadata [ key ] = value | Add a new metadata to the message |
23,599 | def get_metadata ( self , key ) -> str : return self . metadata [ key ] if key in self . metadata else None | Get the value of a metadata . Returns None if metadata does not exist . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.