<s> import getpass <EOL> import hashlib <EOL> import json <EOL> import locale <EOL> import os <EOL> import platform <EOL> import re <EOL> import shutil <EOL> import subprocess <EOL> import tempfile <EOL> import time <EOL> import uuid <EOL> import yaml <EOL> from appcontroller_client import AppControllerClient <EOL> from appscale_logger import AppScaleLogger <EOL> from custom_exceptions import AppScaleException <EOL> from custom_exceptions import AppScalefileException <EOL> from custom_exceptions import BadConfigurationException <EOL> from custom_exceptions import ShellException <EOL> APPSCALE_VERSION = "<STR_LIT>" <EOL> class LocalState ( object ) : <EOL> """<STR_LIT>""" <EOL> DEFAULT_NUM_RETRIES = <NUM_LIT:5> <EOL> LOCAL_APPSCALE_PATH = os . path . expanduser ( "<STR_LIT>" ) + os . sep + "<STR_LIT>" + os . sep <EOL> ETC_APPSCALE_KEY_PATH = "<STR_LIT>" <EOL> VALID_KEY_PATHS = [ LOCAL_APPSCALE_PATH , ETC_APPSCALE_KEY_PATH ] <EOL> SECRET_KEY_LENGTH = <NUM_LIT:32> <EOL> DEFAULT_USER = "<STR_LIT>" <EOL> DEFAULT_PASSWORD = "<STR_LIT>" <EOL> @ classmethod <EOL> def make_appscale_directory ( cls ) : <EOL> """<STR_LIT>""" <EOL> if os . path . exists ( cls . LOCAL_APPSCALE_PATH ) : <EOL> return <EOL> else : <EOL> os . mkdir ( cls . LOCAL_APPSCALE_PATH ) <EOL> @ classmethod <EOL> def ensure_appscale_isnt_running ( cls , keyname , force ) : <EOL> """<STR_LIT>""" <EOL> if force : <EOL> return <EOL> if os . path . exists ( cls . get_secret_key_location ( keyname ) ) : <EOL> raise BadConfigurationException ( "<STR_LIT>" + <EOL> "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> @ classmethod <EOL> def generate_secret_key ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> key = str ( uuid . uuid4 ( ) ) . replace ( '<STR_LIT:->' , '<STR_LIT>' ) [ : cls . SECRET_KEY_LENGTH ] <EOL> with open ( cls . get_secret_key_location ( keyname ) , '<STR_LIT:w>' ) as file_handle : <EOL> file_handle . write ( key ) <EOL> return key <EOL> @ classmethod <EOL> def get_secret_key_location ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> return cls . LOCAL_APPSCALE_PATH + keyname + "<STR_LIT>" <EOL> @ classmethod <EOL> def get_secret_key ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> with open ( cls . get_secret_key_location ( keyname ) , '<STR_LIT:r>' ) as file_handle : <EOL> return file_handle . read ( ) <EOL> @ classmethod <EOL> def write_key_file ( cls , location , contents ) : <EOL> """<STR_LIT>""" <EOL> with open ( location , '<STR_LIT:w>' ) as file_handle : <EOL> file_handle . write ( contents ) <EOL> os . chmod ( location , <NUM_LIT:0> <NUM_LIT> ) <EOL> @ classmethod <EOL> def generate_deployment_params ( cls , options , node_layout , first_host , <EOL> additional_creds ) : <EOL> """<STR_LIT>""" <EOL> creds = { <EOL> "<STR_LIT>" : options . table , <EOL> "<STR_LIT>" : first_host , <EOL> "<STR_LIT>" : json . dumps ( node_layout . to_list_without_head_node ( ) ) , <EOL> "<STR_LIT>" : options . keyname , <EOL> "<STR_LIT>" : str ( node_layout . replication_factor ( ) ) , <EOL> "<STR_LIT>" : str ( options . appengine ) , <EOL> "<STR_LIT>" : str ( options . autoscale ) , <EOL> "<STR_LIT>" : str ( options . alter_etc_resolv ) , <EOL> "<STR_LIT>" : str ( options . clear_datastore ) , <EOL> "<STR_LIT>" : json . dumps ( options . user_commands ) , <EOL> "<STR_LIT>" : str ( options . verbose ) , <EOL> "<STR_LIT>" : options . flower_password , <EOL> "<STR_LIT>" : options . max_memory <EOL> } <EOL> creds . update ( additional_creds ) <EOL> if options . infrastructure : <EOL> iaas_creds = { <EOL> '<STR_LIT>' : options . machine , <EOL> '<STR_LIT>' : options . infrastructure , <EOL> '<STR_LIT>' : options . group , <EOL> '<STR_LIT>' : node_layout . min_vms , <EOL> '<STR_LIT>' : node_layout . max_vms , <EOL> '<STR_LIT>' : options . use_spot_instances , <EOL> '<STR_LIT>' : json . dumps ( options . zone ) <EOL> } <EOL> if options . infrastructure in [ "<STR_LIT>" , "<STR_LIT>" ] : <EOL> iaas_creds [ '<STR_LIT>' ] = options . instance_type <EOL> elif options . infrastructure == "<STR_LIT>" : <EOL> iaas_creds [ '<STR_LIT>' ] = options . project <EOL> iaas_creds [ '<STR_LIT>' ] = getpass . getuser ( ) <EOL> iaas_creds [ '<STR_LIT>' ] = options . gce_instance_type <EOL> creds . update ( iaas_creds ) <EOL> return creds <EOL> @ classmethod <EOL> def obscure_dict ( cls , dict_to_obscure ) : <EOL> """<STR_LIT>""" <EOL> obscured = { } <EOL> obscure_regex = re . compile ( '<STR_LIT>' ) <EOL> for key , value in dict_to_obscure . iteritems ( ) : <EOL> if obscure_regex . match ( key ) : <EOL> obscured [ key ] = cls . obscure_str ( value ) <EOL> else : <EOL> obscured [ key ] = value <EOL> return obscured <EOL> @ classmethod <EOL> def obscure_str ( cls , str_to_obscure ) : <EOL> """<STR_LIT>""" <EOL> if len ( str_to_obscure ) < <NUM_LIT:4> : <EOL> return str_to_obscure <EOL> last_four = str_to_obscure [ len ( str_to_obscure ) - <NUM_LIT:4> : len ( str_to_obscure ) ] <EOL> return "<STR_LIT:*>" * ( len ( str_to_obscure ) - <NUM_LIT:4> ) + last_four <EOL> @ classmethod <EOL> def generate_ssl_cert ( cls , keyname , is_verbose ) : <EOL> """<STR_LIT>""" <EOL> cls . shell ( "<STR_LIT>" + "<STR_LIT>" + "<STR_LIT>" . format ( LocalState . get_private_key_location ( keyname ) , <EOL> LocalState . get_certificate_location ( keyname ) ) , is_verbose , stdin = None ) <EOL> @ classmethod <EOL> def get_key_path_from_name ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> for local_path in cls . VALID_KEY_PATHS : <EOL> key_file_path = local_path + keyname + "<STR_LIT>" <EOL> if os . path . isfile ( key_file_path ) : <EOL> return key_file_path <EOL> @ classmethod <EOL> def get_private_key_location ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> return cls . LOCAL_APPSCALE_PATH + keyname + "<STR_LIT>" <EOL> @ classmethod <EOL> def get_certificate_location ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> return cls . LOCAL_APPSCALE_PATH + keyname + "<STR_LIT>" <EOL> @ classmethod <EOL> def get_locations_yaml_location ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> return cls . LOCAL_APPSCALE_PATH + "<STR_LIT>" + keyname + "<STR_LIT>" <EOL> @ classmethod <EOL> def get_locations_json_location ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> return cls . LOCAL_APPSCALE_PATH + "<STR_LIT>" + keyname + "<STR_LIT>" <EOL> @ classmethod <EOL> def update_local_metadata ( cls , options , node_layout , host , instance_id ) : <EOL> """<STR_LIT>""" <EOL> acc = AppControllerClient ( host , cls . get_secret_key ( options . keyname ) ) <EOL> all_ips = [ str ( ip ) for ip in acc . get_all_public_ips ( ) ] <EOL> role_info = acc . get_role_info ( ) <EOL> infrastructure = options . infrastructure or '<STR_LIT>' <EOL> yaml_contents = { <EOL> '<STR_LIT>' : str ( host ) , <EOL> '<STR_LIT>' : str ( instance_id ) , <EOL> '<STR_LIT>' : options . table , <EOL> '<STR_LIT>' : cls . get_secret_key ( options . keyname ) , <EOL> '<STR_LIT>' : node_layout . db_master ( ) . public_ip , <EOL> '<STR_LIT>' : all_ips , <EOL> '<STR_LIT>' : infrastructure , <EOL> '<STR_LIT>' : options . group , <EOL> } <EOL> if infrastructure != "<STR_LIT>" : <EOL> yaml_contents [ '<STR_LIT>' ] = options . zone <EOL> if infrastructure == "<STR_LIT>" : <EOL> yaml_contents [ '<STR_LIT>' ] = options . project <EOL> with open ( cls . get_locations_yaml_location ( options . keyname ) , '<STR_LIT:w>' ) as file_handle : <EOL> file_handle . write ( yaml . dump ( yaml_contents , default_flow_style = False ) ) <EOL> with open ( cls . get_locations_json_location ( options . keyname ) , '<STR_LIT:w>' ) as file_handle : <EOL> file_handle . write ( json . dumps ( role_info ) ) <EOL> @ classmethod <EOL> def get_from_yaml ( cls , keyname , tag ) : <EOL> """<STR_LIT>""" <EOL> with open ( cls . get_locations_yaml_location ( keyname ) , '<STR_LIT:r>' ) as file_handle : <EOL> locations_yaml = yaml . safe_load ( file_handle . read ( ) ) <EOL> return locations_yaml [ tag ] <EOL> @ classmethod <EOL> def get_local_nodes_info ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> if not os . path . exists ( cls . get_locations_json_location ( keyname ) ) : <EOL> raise BadConfigurationException ( "<STR_LIT>" + "<STR_LIT>" . format ( keyname ) ) <EOL> with open ( cls . get_locations_json_location ( keyname ) , '<STR_LIT:r>' ) as file_handle : <EOL> return json . loads ( file_handle . read ( ) ) <EOL> @ classmethod <EOL> def get_host_for_role ( cls , keyname , role ) : <EOL> """<STR_LIT>""" <EOL> for node in cls . get_local_nodes_info ( keyname ) : <EOL> if role in node [ "<STR_LIT>" ] : <EOL> return node [ "<STR_LIT>" ] <EOL> @ classmethod <EOL> def are_disks_used ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> disks = [ node . get ( "<STR_LIT>" ) for node in cls . get_local_nodes_info ( keyname ) ] <EOL> for disk in disks : <EOL> if disk : <EOL> return True <EOL> return False <EOL> @ classmethod <EOL> def encrypt_password ( cls , username , password ) : <EOL> """<STR_LIT>""" <EOL> return hashlib . sha1 ( username + password ) . hexdigest ( ) <EOL> @ classmethod <EOL> def get_login_host ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> return cls . get_host_with_role ( keyname , '<STR_LIT>' ) <EOL> @ classmethod <EOL> def get_host_with_role ( cls , keyname , role ) : <EOL> """<STR_LIT>""" <EOL> nodes = cls . get_local_nodes_info ( keyname ) <EOL> for node in nodes : <EOL> if role in node [ '<STR_LIT>' ] : <EOL> return node [ '<STR_LIT>' ] <EOL> raise AppScaleException ( "<STR_LIT>" . format ( role ) ) <EOL> @ classmethod <EOL> def get_all_public_ips ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> nodes = cls . get_local_nodes_info ( keyname ) <EOL> return [ node [ '<STR_LIT>' ] for node in nodes ] <EOL> @ classmethod <EOL> def get_credentials ( cls , is_admin = True ) : <EOL> """<STR_LIT>""" <EOL> username , password = None , None <EOL> username = cls . get_username_from_stdin ( is_admin ) <EOL> password = cls . get_password_from_stdin ( ) <EOL> return username , password <EOL> @ classmethod <EOL> def get_username_from_stdin ( cls , is_admin ) : <EOL> """<STR_LIT>""" <EOL> while True : <EOL> if is_admin : <EOL> username = raw_input ( '<STR_LIT>' ) <EOL> else : <EOL> username = raw_input ( '<STR_LIT>' ) <EOL> username = username . lstrip ( ) . rstrip ( ) <EOL> email_regex = '<STR_LIT>' <EOL> if re . match ( email_regex , username ) : <EOL> return username <EOL> else : <EOL> AppScaleLogger . warn ( '<STR_LIT>' ) <EOL> @ classmethod <EOL> def get_password_from_stdin ( cls ) : <EOL> """<STR_LIT>""" <EOL> while True : <EOL> password = getpass . getpass ( '<STR_LIT>' ) <EOL> if len ( password ) < <NUM_LIT:6> : <EOL> AppScaleLogger . warn ( '<STR_LIT>' ) <EOL> continue <EOL> password_confirmation = getpass . getpass ( '<STR_LIT>' ) <EOL> if password == password_confirmation : <EOL> return password <EOL> else : <EOL> AppScaleLogger . warn ( '<STR_LIT>' ) <EOL> @ classmethod <EOL> def map_to_array ( cls , the_map ) : <EOL> """<STR_LIT>""" <EOL> the_list = [ ] <EOL> for key , value in the_map . items ( ) : <EOL> the_list . append ( key ) <EOL> the_list . append ( value ) <EOL> return the_list <EOL> @ classmethod <EOL> def get_infrastructure ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> with open ( cls . get_locations_yaml_location ( keyname ) , '<STR_LIT:r>' ) as file_handle : <EOL> return yaml . safe_load ( file_handle . read ( ) ) [ "<STR_LIT>" ] <EOL> @ classmethod <EOL> def get_group ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> with open ( cls . get_locations_yaml_location ( keyname ) , '<STR_LIT:r>' ) as file_handle : <EOL> return yaml . safe_load ( file_handle . read ( ) ) [ "<STR_LIT>" ] <EOL> @ classmethod <EOL> def get_project ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> with open ( cls . get_locations_yaml_location ( keyname ) , '<STR_LIT:r>' ) as file_handle : <EOL> return yaml . safe_load ( file_handle . read ( ) ) [ "<STR_LIT>" ] <EOL> @ classmethod <EOL> def get_zone ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> with open ( cls . get_locations_yaml_location ( keyname ) , '<STR_LIT:r>' ) as file_handle : <EOL> return yaml . safe_load ( file_handle . read ( ) ) [ "<STR_LIT>" ] <EOL> @ classmethod <EOL> def get_client_secrets_location ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> return cls . LOCAL_APPSCALE_PATH + keyname + "<STR_LIT>" <EOL> @ classmethod <EOL> def get_oauth2_storage_location ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> return cls . LOCAL_APPSCALE_PATH + keyname + "<STR_LIT>" <EOL> @ classmethod <EOL> def cleanup_appscale_files ( cls , keyname ) : <EOL> """<STR_LIT>""" <EOL> files_to_remove = [ LocalState . get_locations_yaml_location ( keyname ) , <EOL> LocalState . get_locations_json_location ( keyname ) , <EOL> LocalState . get_secret_key_location ( keyname ) ] <EOL> for file_to_remove in files_to_remove : <EOL> if os . path . exists ( file_to_remove ) : <EOL> os . remove ( file_to_remove ) <EOL> @ classmethod <EOL> def shell ( cls , command , is_verbose , num_retries = DEFAULT_NUM_RETRIES , <EOL> stdin = None ) : <EOL> """<STR_LIT>""" <EOL> tries_left = num_retries <EOL> try : <EOL> while tries_left : <EOL> AppScaleLogger . verbose ( "<STR_LIT>" . format ( command ) , is_verbose ) <EOL> the_temp_file = tempfile . NamedTemporaryFile ( ) <EOL> if stdin is not None : <EOL> stdin_strio = tempfile . TemporaryFile ( ) <EOL> stdin_strio . write ( stdin ) <EOL> stdin_strio . seek ( <NUM_LIT:0> ) <EOL> AppScaleLogger . verbose ( "<STR_LIT>" . format ( stdin ) , is_verbose ) <EOL> result = subprocess . Popen ( command , shell = True , stdout = the_temp_file , <EOL> stdin = stdin_strio , stderr = subprocess . STDOUT ) <EOL> else : <EOL> result = subprocess . Popen ( command , shell = True , stdout = the_temp_file , <EOL> stderr = subprocess . STDOUT ) <EOL> AppScaleLogger . verbose ( "<STR_LIT>" . format ( the_temp_file . name ) , is_verbose ) <EOL> result . wait ( ) <EOL> if stdin is not None : <EOL> stdin_strio . close ( ) <EOL> if result . returncode == <NUM_LIT:0> : <EOL> the_temp_file . seek ( <NUM_LIT:0> ) <EOL> output = the_temp_file . read ( ) <EOL> the_temp_file . close ( ) <EOL> return output <EOL> tries_left -= <NUM_LIT:1> <EOL> if tries_left : <EOL> the_temp_file . close ( ) <EOL> AppScaleLogger . verbose ( "<STR_LIT>" . format ( command ) , is_verbose ) <EOL> else : <EOL> the_temp_file . seek ( <NUM_LIT:0> ) <EOL> output = the_temp_file . read ( ) <EOL> the_temp_file . close ( ) <EOL> if stdin : <EOL> raise ShellException ( "<STR_LIT>" . format ( command , stdin , output ) ) <EOL> else : <EOL> raise ShellException ( "<STR_LIT>" . format ( command , output ) ) <EOL> time . sleep ( <NUM_LIT:1> ) <EOL> except OSError as os_error : <EOL> if stdin : <EOL> raise ShellException ( "<STR_LIT>" . format ( command , stdin , os_error ) ) <EOL> else : <EOL> raise ShellException ( "<STR_LIT>" . format ( command , os_error ) ) <EOL> @ classmethod <EOL> def require_ssh_commands ( cls , needs_expect , is_verbose ) : <EOL> """<STR_LIT>""" <EOL> required_commands = [ '<STR_LIT>' , '<STR_LIT>' ] <EOL> if needs_expect : <EOL> required_commands . append ( '<STR_LIT>' ) <EOL> for command in required_commands : <EOL> try : <EOL> cls . shell ( "<STR_LIT>" . format ( command ) , is_verbose ) <EOL> except ShellException : <EOL> raise BadConfigurationException ( "<STR_LIT>" <EOL> . format ( command ) ) <EOL> @ classmethod <EOL> def generate_rsa_key ( cls , keyname , is_verbose ) : <EOL> """<STR_LIT>""" <EOL> private_key = cls . LOCAL_APPSCALE_PATH + keyname <EOL> public_key = private_key + "<STR_LIT>" <EOL> if os . path . exists ( public_key ) : <EOL> os . remove ( public_key ) <EOL> if os . path . exists ( private_key ) : <EOL> os . remove ( private_key ) <EOL> cls . shell ( "<STR_LIT>" . format ( private_key ) , is_verbose ) <EOL> os . chmod ( public_key , <NUM_LIT:0> <NUM_LIT> ) <EOL> os . chmod ( private_key , <NUM_LIT:0> <NUM_LIT> ) <EOL> shutil . copy ( private_key , private_key + "<STR_LIT>" ) <EOL> return public_key , private_key <EOL> @ classmethod <EOL> def extract_tgz_app_to_dir ( cls , tar_location , is_verbose ) : <EOL> """<STR_LIT>""" <EOL> return cls . extract_app_to_dir ( tar_location , "<STR_LIT>" , is_verbose ) <EOL> @ classmethod <EOL> def extract_zip_app_to_dir ( cls , zip_location , is_verbose ) : <EOL> """<STR_LIT>""" <EOL> return cls . extract_app_to_dir ( zip_location , "<STR_LIT>" , is_verbose ) <EOL> @ classmethod <EOL> def extract_app_to_dir ( cls , archive_location , extract_command , is_verbose ) : <EOL> """<STR_LIT>""" <EOL> extracted_location = "<STR_LIT>" . format ( str ( uuid . uuid4 ( ) ) . replace ( '<STR_LIT:->' , '<STR_LIT>' ) [ : <NUM_LIT:8> ] ) <EOL> os . mkdir ( extracted_location ) <EOL> cls . shell ( "<STR_LIT>" . format ( extracted_location , extract_command , <EOL> os . path . abspath ( archive_location ) ) , is_verbose ) <EOL> file_list = os . listdir ( extracted_location ) <EOL> if len ( file_list ) > <NUM_LIT:0> : <EOL> file_list [ : ] = [ itm for itm in file_list if itm [ <NUM_LIT:0> ] != '<STR_LIT:.>' ] <EOL> included_dir = extracted_location + os . sep + file_list [ <NUM_LIT:0> ] <EOL> if len ( file_list ) == <NUM_LIT:1> and os . path . isdir ( included_dir ) : <EOL> extracted_location = included_dir <EOL> return extracted_location <EOL> @ classmethod <EOL> def generate_crash_log ( cls , exception , stacktrace ) : <EOL> """<STR_LIT>""" <EOL> crash_log_filename = '<STR_LIT>' . format ( <EOL> LocalState . LOCAL_APPSCALE_PATH , uuid . uuid4 ( ) ) <EOL> try : <EOL> locale . setlocale ( locale . LC_ALL , '<STR_LIT>' ) <EOL> this_locale = locale . getlocale ( ) [ <NUM_LIT:0> ] <EOL> except locale . Error : <EOL> this_locale = "<STR_LIT>" <EOL> log_info = { <EOL> '<STR_LIT>' : platform . platform ( ) , <EOL> '<STR_LIT>' : platform . python_implementation ( ) , <EOL> '<STR_LIT>' : this_locale , <EOL> '<STR_LIT>' : exception . __class__ . __name__ , <EOL> '<STR_LIT:message>' : str ( exception ) , <EOL> '<STR_LIT>' : stacktrace . rstrip ( ) , <EOL> '<STR_LIT>' : APPSCALE_VERSION <EOL> } <EOL> if not os . path . exists ( LocalState . LOCAL_APPSCALE_PATH ) : <EOL> os . mkdir ( LocalState . LOCAL_APPSCALE_PATH ) <EOL> with open ( crash_log_filename , '<STR_LIT:w>' ) as file_handle : <EOL> for key , value in log_info . iteritems ( ) : <EOL> file_handle . write ( "<STR_LIT>" . format ( key , value ) ) <EOL> AppScaleLogger . warn ( str ( exception ) ) <EOL> AppScaleLogger . log ( "<STR_LIT>" "<STR_LIT>" . format ( crash_log_filename ) ) <EOL> return crash_log_filename <EOL> @ classmethod <EOL> def ensure_user_wants_to_terminate ( cls ) : <EOL> """<STR_LIT>""" <EOL> cls . confirm_or_abort ( "<STR_LIT>" ) <EOL> @ classmethod <EOL> def ensure_user_wants_to_run_without_disks ( cls ) : <EOL> """<STR_LIT>""" <EOL> cls . confirm_or_abort ( "<STR_LIT>" + <EOL> "<STR_LIT>" ) <EOL> @ classmethod <EOL> def confirm_or_abort ( cls , message ) : <EOL> """<STR_LIT>""" <EOL> AppScaleLogger . warn ( message ) <EOL> confirm = raw_input ( "<STR_LIT>" ) <EOL> if confirm . lower ( ) == '<STR_LIT:y>' or confirm . lower ( ) == '<STR_LIT:yes>' : <EOL> return <EOL> else : <EOL> raise AppScaleException ( '<STR_LIT>' ) <EOL> @ classmethod <EOL> def ensure_appscalefile_is_up_to_date ( cls ) : <EOL> """<STR_LIT>""" <EOL> appscalefile_path = os . getcwd ( ) + os . sep + "<STR_LIT>" <EOL> if not os . path . exists ( appscalefile_path ) : <EOL> raise AppScalefileException ( "<STR_LIT>" . format ( appscalefile_path ) ) <EOL> file_contents = '<STR_LIT>' <EOL> with open ( appscalefile_path ) as file_handle : <EOL> file_contents = file_handle . read ( ) <EOL> yaml_contents = yaml . safe_load ( file_contents ) <EOL> if '<STR_LIT>' in yaml_contents and '<STR_LIT>' in yaml_contents : <EOL> return True <EOL> file_contents += "<STR_LIT>" <EOL> random_suffix = str ( uuid . uuid4 ( ) ) . replace ( '<STR_LIT:->' , '<STR_LIT>' ) <EOL> cloud_name = "<STR_LIT>" . format ( random_suffix ) <EOL> if '<STR_LIT>' not in yaml_contents : <EOL> file_contents += "<STR_LIT>" . format ( cloud_name ) <EOL> if '<STR_LIT>' not in yaml_contents : <EOL> file_contents += "<STR_LIT>" . format ( cloud_name ) <EOL> with open ( appscalefile_path , '<STR_LIT:w>' ) as file_handle : <EOL> file_handle . write ( file_contents ) <EOL> return False </s>
