idx
int64
0
24.9k
question
stringlengths
68
4.14k
target
stringlengths
9
749
300
def create_profile! cert = certificate_to_use bundle_id = Sigh . config [ :app_identifier ] name = Sigh . config [ :provisioning_name ] || [ bundle_id , profile_type . pretty_type ] . join ( ' ' ) unless Sigh . config [ :skip_fetch_profiles ] if Spaceship . provisioning_profile . all . find { | p | p . name == name } U...
Create a new profile and return it
301
def certificate_to_use certificates = certificates_for_profile_and_platform certificates = certificates . find_all do | c | if Sigh . config [ :cert_id ] next unless c . id == Sigh . config [ :cert_id ] . strip end if Sigh . config [ :cert_owner_name ] next unless c . owner_name . strip == Sigh . config [ :cert_owner_n...
Certificate to use based on the current distribution mode
302
def download_profile ( profile ) UI . important ( "Downloading provisioning profile..." ) profile_name ||= "#{profile_type.pretty_type}_#{Sigh.config[:app_identifier]}" if Sigh . config [ :platform ] . to_s == 'tvos' profile_name += "_tvos" end if Sigh . config [ :platform ] . to_s == 'macos' profile_name += '.provisio...
Downloads and stores the provisioning profile
303
def ensure_app_exists! return if Spaceship :: App . find ( Sigh . config [ :app_identifier ] , mac : Sigh . config [ :platform ] . to_s == 'macos' ) print_produce_command ( Sigh . config ) UI . user_error! ( "Could not find App with App Identifier '#{Sigh.config[:app_identifier]}'" ) end
Makes sure the current App ID exists . If not it will show an appropriate error message
304
def download_all ( download_xcode_profiles : false ) UI . message ( "Starting login with user '#{Sigh.config[:username]}'" ) Spaceship . login ( Sigh . config [ :username ] , nil ) Spaceship . select_team UI . message ( "Successfully logged in" ) Spaceship . provisioning_profile . all ( xcode : download_xcode_profiles ...
Download all valid provisioning profiles
305
def handle_control_command ( command ) exit_reason = nil if command . cancel_signal? UI . verbose ( "received cancel signal shutting down, reason: #{command.reason}" ) cancel_response = '{"payload":{"status":"cancelled"}}' send_response ( cancel_response ) exit_reason = :cancelled elsif command . done_signal? UI . verb...
we got a server control command from the client to do something like shutdown
306
def send_response ( json ) UI . verbose ( "sending #{json}" ) begin @client . puts ( json ) rescue Errno :: EPIPE => e UI . verbose ( e ) return COMMAND_EXECUTION_STATE [ :error ] end return COMMAND_EXECUTION_STATE [ :ready ] end
send json back to client
307
def execute_action_command ( command : nil ) command_return = @command_executor . execute ( command : command , target_object : nil ) return_object = command_return . return_value return_value_type = command_return . return_value_type closure_arg = command_return . closure_argument_value return_object = return_value_pr...
execute fastlane action command
308
def schemes @schemes ||= if workspace? workspace . schemes . reject do | k , v | v . include? ( "Pods/Pods.xcodeproj" ) end . keys else Xcodeproj :: Project . schemes ( path ) end end
Get all available schemes in an array
309
def select_scheme ( preferred_to_include : nil ) if options [ :scheme ] . to_s . length > 0 unless schemes . include? ( options [ :scheme ] . to_s ) UI . error ( "Couldn't find specified scheme '#{options[:scheme]}'. Please make sure that the scheme is shared, see https://developer.apple.com/library/content/documentati...
Let the user select a scheme Use a scheme containing the preferred_to_include string when multiple schemes were found
310
def configurations @configurations ||= if workspace? workspace . file_references . map ( & :path ) . reject { | p | p . include? ( "Pods/Pods.xcodeproj" ) } . map do | p | begin Xcodeproj :: Project . open ( p ) . build_configurations rescue [ ] end end . flatten . compact . map ( & :name ) else project . build_configu...
Get all available configurations in an array
311
def default_build_settings ( key : nil , optional : true ) options [ :scheme ] ||= schemes . first if is_workspace build_settings ( key : key , optional : optional ) end
Returns the build settings and sets the default scheme to the options hash
312
def print_tables puts ( "" ) if self . certs . count > 0 rows = self . certs . collect do | cert | cert_expiration = cert . expires . nil? ? "Unknown" : cert . expires . strftime ( "%Y-%m-%d" ) [ cert . name , cert . id , cert . class . to_s . split ( "::" ) . last , cert_expiration ] end puts ( Terminal :: Table . new...
Print tables to ask the user
313
def upload ( options ) return if options [ :skip_metadata ] verify_available_languages! ( options ) unless options [ :edit_live ] app = options [ :app ] details = app . details if options [ :edit_live ] v = app . live_version ( platform : options [ :platform ] ) localised_options = LOCALISED_LIVE_VALUES non_localised_o...
Make sure to call load_from_filesystem before calling upload
314
def upload_individual_item ( app , version , language , key , value ) details = app . details version . send ( key ) [ language ] = value if LOCALISED_VERSION_VALUES . include? ( key ) details . send ( key ) [ language ] = value if LOCALISED_APP_VALUES . include? ( key ) Helper . show_loading_indicator ( "Uploading #{l...
Uploads metadata individually by language to help identify exactly which items have issues
315
def verify_available_languages! ( options ) return if options [ :skip_metadata ] v = options [ :app ] . edit_version ( platform : options [ :platform ] ) UI . user_error! ( "Could not find a version to edit for app '#{options[:app].name}', the app metadata is read-only currently" ) unless v enabled_languages = options ...
Makes sure all languages we need are actually created
316
def load_from_filesystem ( options ) return if options [ :skip_metadata ] ignore_validation = options [ :ignore_language_directory_validation ] Loader . language_folders ( options [ :metadata_path ] , ignore_validation ) . each do | lang_folder | language = File . basename ( lang_folder ) ( LOCALISED_VERSION_VALUES + L...
Loads the metadata files and stores them into the options object
317
def normalize_language_keys ( options ) ( LOCALISED_VERSION_VALUES + LOCALISED_APP_VALUES ) . each do | key | current = options [ key ] next unless current && current . kind_of? ( Hash ) current . keys . each do | language | current [ language . to_s ] = current . delete ( language ) end end options end
Normalizes languages keys from symbols to strings
318
def resolution ( path ) return FastImage . size ( path ) if content_type ( path ) . start_with? ( "image" ) return video_resolution ( path ) if content_type ( path ) . start_with? ( "video" ) raise "Cannot find resolution of file #{path}" end
Identifies the resolution of a video or an image . Supports all video and images required by DU - UTC right now
319
def run_action_requiring_special_handling ( command : nil , parameter_map : nil , action_return_type : nil ) action_return = nil closure_argument_value = nil case command . method_name when "sh" error_callback = proc { | string_value | closure_argument_value = string_value } command_param = parameter_map [ :command ] l...
Some actions have special handling in fast_file . rb that means we can t directly call the action but we have to use the same logic that is in fast_file . rb instead . That s where this switch statement comes into play
320
def build_app command = BuildCommandGenerator . generate print_command ( command , "Generated Build Command" ) if FastlaneCore :: Globals . verbose? FastlaneCore :: CommandExecutor . execute ( command : command , print_all : true , print_command : ! Gym . config [ :silent ] , error : proc do | output | ErrorHandler . h...
Builds the app and prepares the archive
321
def post_build_app command = BuildCommandGenerator . post_build return if command . empty? print_command ( command , "Generated Post-Build Command" ) if FastlaneCore :: Globals . verbose? FastlaneCore :: CommandExecutor . execute ( command : command , print_all : true , print_command : ! Gym . config [ :silent ] , erro...
Post - processing of build_app
322
def move_ipa FileUtils . mv ( PackageCommandGenerator . ipa_path , File . expand_path ( Gym . config [ :output_directory ] ) , force : true ) ipa_path = File . expand_path ( File . join ( Gym . config [ :output_directory ] , File . basename ( PackageCommandGenerator . ipa_path ) ) ) UI . success ( "Successfully exporte...
Moves over the binary and dsym file to the output directory
323
def copy_mac_app exe_name = Gym . project . build_settings ( key : "EXECUTABLE_NAME" ) app_path = File . join ( BuildCommandGenerator . archive_path , "Products/Applications/#{exe_name}.app" ) UI . crash! ( "Couldn't find application in '#{BuildCommandGenerator.archive_path}'" ) unless File . exist? ( app_path ) FileUt...
Copies the . app from the archive into the output directory
324
def move_manifest if File . exist? ( PackageCommandGenerator . manifest_path ) FileUtils . mv ( PackageCommandGenerator . manifest_path , File . expand_path ( Gym . config [ :output_directory ] ) , force : true ) manifest_path = File . join ( File . expand_path ( Gym . config [ :output_directory ] ) , File . basename (...
Move the manifest . plist if exists into the output directory
325
def move_app_thinning if File . exist? ( PackageCommandGenerator . app_thinning_path ) FileUtils . mv ( PackageCommandGenerator . app_thinning_path , File . expand_path ( Gym . config [ :output_directory ] ) , force : true ) app_thinning_path = File . join ( File . expand_path ( Gym . config [ :output_directory ] ) , F...
Move the app - thinning . plist file into the output directory
326
def move_app_thinning_size_report if File . exist? ( PackageCommandGenerator . app_thinning_size_report_path ) FileUtils . mv ( PackageCommandGenerator . app_thinning_size_report_path , File . expand_path ( Gym . config [ :output_directory ] ) , force : true ) app_thinning_size_report_path = File . join ( File . expand...
Move the App Thinning Size Report . txt file into the output directory
327
def move_apps_folder if Dir . exist? ( PackageCommandGenerator . apps_path ) FileUtils . mv ( PackageCommandGenerator . apps_path , File . expand_path ( Gym . config [ :output_directory ] ) , force : true ) apps_path = File . join ( File . expand_path ( Gym . config [ :output_directory ] ) , File . basename ( PackageCo...
Move the Apps folder to the output directory
328
def determine_api_version ( new_file_content : nil , old_file_content : nil ) unless old_file_content . length >= new_file_content . length old_api_version = find_api_version_string ( content : old_file_content ) return DEFAULT_API_VERSION_STRING if old_api_version . nil? return increment_api_version_string ( api_versi...
compares the new file content to the old and figures out what api_version the new content should be
329
def increment_api_version_string ( api_version_string : nil , increment_by : :patch ) versions = api_version_string . split ( "." ) major = versions [ 0 ] . to_i minor = versions [ 1 ] . to_i patch = versions [ 2 ] . to_i case increment_by when :patch patch += 1 when :minor minor += 1 patch = 0 when :major major += 1 m...
expects format to be X . Y . Z where each value is a number
330
def for_lane ( lane_name ) if lane_name . to_s . split ( " " ) . count > 1 puts ( "You use deprecated syntax '#{lane_name}' in your Appfile." . yellow ) puts ( "Please follow the Appfile guide: https://docs.fastlane.tools/advanced/#appfile" . yellow ) platform , lane_name = lane_name . split ( " " ) return unless platf...
Override Appfile configuration for a specific lane .
331
def file_needs_update? ( filename : nil ) regex_to_use = API_VERSION_REGEX source = File . join ( self . source_swift_code_file_folder_path , "/#{filename}" ) target = File . join ( self . target_swift_code_file_folder_path , "/#{filename}" ) return true unless File . exist? ( target ) source_file_content = File . read...
compares source file against the target file s FastlaneRunnerAPIVersion and returned true if there is a difference
332
def copy_file_if_needed! ( filename : nil , dry_run : false ) needs_update = file_needs_update? ( filename : filename ) UI . verbose ( "file #{filename} needs an update" ) if needs_update return needs_update if dry_run unless needs_update return false end source = File . join ( self . source_swift_code_file_folder_path...
currently just copies file even if not needed .
333
def serve @server_transport . listen begin loop do @thread_q . push ( :token ) Thread . new do begin loop do client = @server_transport . accept trans = @transport_factory . get_transport ( client ) prot = @protocol_factory . get_protocol ( trans ) begin loop do @processor . process ( prot , prot ) end rescue Thrift ::...
exceptions that happen in worker threads simply cause that thread to die and another to be spawned in its place .
334
def write_json_char ( ch ) kJSONCharTable = [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 'b' , 't' , 'n' , 0 , 'f' , 'r' , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 1 , 1 , '"' , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , ] ch_value = ch [ 0 ] if ( ch_value . kind_of? String ) ch_value = ch ...
Write the character ch as part of a JSON string escaping as appropriate .
335
def write_json_string ( str ) @context . write ( trans ) trans . write ( @@kJSONStringDelimiter ) str . split ( '' ) . each do | ch | write_json_char ( ch ) end trans . write ( @@kJSONStringDelimiter ) end
Write out the contents of the string str as a JSON string escaping characters as appropriate .
336
def write_json_base64 ( str ) @context . write ( trans ) trans . write ( @@kJSONStringDelimiter ) trans . write ( Base64 . strict_encode64 ( str ) ) trans . write ( @@kJSONStringDelimiter ) end
Write out the contents of the string as JSON string base64 - encoding the string s contents and escaping as appropriate
337
def write_json_double ( num ) @context . write ( trans ) special = false ; if ( num . nan? ) special = true ; val = @@kThriftNan ; elsif ( num . infinite? ) special = true ; val = @@kThriftInfinity ; if ( num < 0.0 ) val = @@kThriftNegativeInfinity ; end else val = num . to_s end escapeNum = special || @context . escap...
Convert the given double to a JSON string which is either the number NaN or Infinity or - Infinity .
338
def read_json_escape_char str = @reader . read str += @reader . read str += @reader . read str += @reader . read if RUBY_VERSION >= '1.9' str . hex . chr ( Encoding :: UTF_8 ) else str . hex . chr end end
Decodes the four hex parts of a JSON escaped string character and returns the character via out .
339
def read_json_string ( skipContext = false ) escape_chars = "\"\\/bfnrt" escape_char_vals = [ "\"" , "\\" , "\/" , "\b" , "\f" , "\n" , "\r" , "\t" , ] if ! skipContext @context . read ( @reader ) end read_json_syntax_char ( @@kJSONStringDelimiter ) ch = "" str = "" while ( true ) ch = @reader . read if ( ch == @@kJSON...
Decodes a JSON string including unescaping and returns the string via str
340
def read_json_base64 str = read_json_string m = str . length % 4 if m != 0 ( 4 - m ) . times do str += '=' end end Base64 . strict_decode64 ( str ) end
Reads a block of base64 characters decoding it and returns via str
341
def read_json_numeric_chars str = "" while ( true ) ch = @reader . peek if ( ! is_json_numeric ( ch ) ) break ; end ch = @reader . read str += ch end return str end
Reads a sequence of characters stopping at the first one that is not a valid JSON numeric character .
342
def read_json_integer @context . read ( @reader ) if ( @context . escapeNum ) read_json_syntax_char ( @@kJSONStringDelimiter ) end str = read_json_numeric_chars begin num = Integer ( str ) ; rescue raise ProtocolException . new ( ProtocolException :: INVALID_DATA , "Expected numeric value; got \"#{str}\"" ) end if ( @c...
Reads a sequence of characters and assembles them into a number returning them via num
343
def read_json_double @context . read ( @reader ) num = 0 if ( @reader . peek == @@kJSONStringDelimiter ) str = read_json_string ( true ) if ( str == @@kThriftNan ) num = ( + 1.0 / 0.0 ) / ( + 1.0 / 0.0 ) elsif ( str == @@kThriftInfinity ) num = + 1.0 / 0.0 elsif ( str == @@kThriftNegativeInfinity ) num = - 1.0 / 0.0 el...
Reads a JSON number or string and interprets it as a double .
344
def write_field ( * args ) if args . size == 3 field_info = args [ 0 ] fid = args [ 1 ] value = args [ 2 ] elsif args . size == 4 field_info = { :name => args [ 0 ] , :type => args [ 1 ] } fid = args [ 2 ] value = args [ 3 ] else raise ArgumentError , "wrong number of arguments (#{args.size} for 3)" end write_field_beg...
Writes a field based on the field information field ID and value .
345
def write_type ( field_info , value ) if field_info . is_a? Fixnum field_info = { :type => field_info } end case field_info [ :type ] when Types :: BOOL write_bool ( value ) when Types :: BYTE write_byte ( value ) when Types :: DOUBLE write_double ( value ) when Types :: I16 write_i16 ( value ) when Types :: I32 write_...
Writes a field value based on the field information .
346
def read_type ( field_info ) if field_info . is_a? Fixnum field_info = { :type => field_info } end case field_info [ :type ] when Types :: BOOL read_bool when Types :: BYTE read_byte when Types :: DOUBLE read_double when Types :: I16 read_i16 when Types :: I32 read_i32 when Types :: I64 read_i64 when Types :: STRING if...
Reads a field value based on the field information .
347
def write_field_begin_internal ( type , id , type_override = nil ) last_id = @last_field . pop typeToWrite = type_override || CompactTypes . get_compact_type ( type ) if id > last_id && id - last_id <= 15 write_byte ( ( id - last_id ) << 4 | typeToWrite ) else write_byte ( typeToWrite ) write_i16 ( id ) end @last_field...
The workhorse of writeFieldBegin . It has the option of doing a type override of the type header . This is used specifically in the boolean field case .
348
def write_collection_begin ( elem_type , size ) if size <= 14 write_byte ( size << 4 | CompactTypes . get_compact_type ( elem_type ) ) else write_byte ( 0xf0 | CompactTypes . get_compact_type ( elem_type ) ) write_varint32 ( size ) end end
Abstract method for writing the start of lists and sets . List and sets on the wire differ only by the type indicator .
349
def read_into_buffer ( buffer , size ) i = 0 while i < size if @index >= @rbuf . size @rbuf = @transport . read ( DEFAULT_BUFFER ) @index = 0 end byte = Bytes . get_string_byte ( @rbuf , @index ) Bytes . set_string_byte ( buffer , i , byte ) @index += 1 i += 1 end i end
Reads a number of bytes from the transport into the buffer passed .
350
def fibonacci ( n ) seq = [ 1 , 1 ] 3 . upto ( n ) do seq << seq [ - 1 ] + seq [ - 2 ] end seq [ n - 1 ] end
1 - based index into the fibonacci sequence
351
def flush return @transport . flush unless @write out = [ @wbuf . length ] . pack ( 'N' ) out << @wbuf @transport . write ( out ) @transport . flush @wbuf = Bytes . empty_byte_buffer end
Writes the output buffer to the stream in the format of a 4 - byte length followed by the actual data .
352
def to_uri ( uri , base_uri = nil ) case base_uri when nil , '' Utils . normalize_uri ( uri . to_s ) else Utils . normalize_uri ( base_uri ) + Utils . normalize_uri ( uri . to_s ) end rescue URI :: Error nil end
Parse an input into a URI object optionally resolving it against a base URI if given .
353
def to_xpath ( string ) subs = string . to_s . scan ( / \G \A \z / ) . map { | x | case x when / / %Q{'#{x}'} else %Q{"#{x}"} end } if subs . size == 1 subs . first else 'concat(' << subs . join ( ', ' ) << ')' end end
Escape a string for use in XPath expression
354
def store_payload! ( old_events , result ) case interpolated [ 'mode' ] . presence when 'on_change' result_json = result . to_json if found = old_events . find { | event | event . payload . to_json == result_json } found . update! ( expires_at : new_event_expiration_date ) false else true end when 'all' , 'merge' , '' ...
This method returns true if the result should be stored as a new event . If mode is set to on_change this method may return false and update an existing event to expire further in the future .
355
def run par = false if @allow_parallel par = true @logger . info ( "Enabling parallelization by default." ) end if par @actions . each do | machine , _ , _ | if ! machine . provider_options [ :parallel ] @logger . info ( "Disabling parallelization because provider doesn't support it: #{machine.provider_name}" ) par = f...
Run all the queued up actions parallelizing if possible .
356
def get ( key ) return nil if ! @items . key? ( key ) return @results_cache [ key ] if @results_cache . key? ( key ) @results_cache [ key ] = @items [ key ] . call end
Get a value by the given key .
357
def merge ( other ) self . class . new . tap do | result | result . merge! ( self ) result . merge! ( other ) end end
Merge one registry with another and return a completely new registry . Note that the result cache is completely busted so any gets on the new registry will result in a cache miss .
358
def init! ( plugins , repair = false ) if ! @initial_specifications @initial_specifications = Gem :: Specification . find_all { true } else Gem :: Specification . all = @initial_specifications Gem :: Specification . reset end if ! Gem . sources . include? ( HASHICORP_GEMSTORE ) current_sources = Gem . sources . sources...
Initializes Bundler and the various gem paths so that we can begin loading gems .
359
def update ( plugins , specific , ** opts ) specific ||= [ ] update = opts . merge ( { gems : specific . empty? ? true : specific } ) internal_install ( plugins , update ) end
Update updates the given plugins or every plugin if none is given .
360
def clean ( plugins , ** opts ) @logger . debug ( "Cleaning Vagrant plugins of stale gems." ) plugin_deps = plugins . map do | name , info | gem_version = info [ 'installed_gem_version' ] gem_version = info [ 'gem_version' ] if gem_version . to_s . empty? gem_version = "> 0" if gem_version . to_s . empty? Gem :: Depend...
Clean removes any unused gems .
361
def validate_configured_sources! Gem . sources . each_source do | src | begin src . load_specs ( :released ) rescue Gem :: Exception => source_error if ENV [ "VAGRANT_ALLOW_PLUGIN_SOURCE_ERRORS" ] @logger . warn ( "Failed to load configured plugin source: #{src}!" ) @logger . warn ( "Error received attempting to load s...
Iterates each configured RubyGem source to validate that it is properly available . If source is unavailable an exception is raised .
362
def generate_builtin_set ( system_plugins = [ ] ) builtin_set = BuiltinSet . new @logger . debug ( "Generating new builtin set instance." ) vagrant_internal_specs . each do | spec | if ! system_plugins . include? ( spec . name ) builtin_set . add_builtin_spec ( spec ) end end builtin_set end
Generate the builtin resolver set
363
def activate_solution ( solution ) retried = false begin @logger . debug ( "Activating solution set: #{solution.map(&:full_name)}" ) solution . each do | activation_request | unless activation_request . full_spec . activated? @logger . debug ( "Activating gem #{activation_request.full_spec.full_name}" ) activation_requ...
Activate a given solution
364
def delete ( entry ) return true if ! entry . id @lock . synchronize do with_index_lock do return true if ! @machines [ entry . id ] if ! @machine_locks [ entry . id ] raise "Unlocked delete on machine: #{entry.id}" end unlocked_reload @machines . delete ( entry . id ) unlocked_save unlocked_release ( entry . id ) end ...
Initializes a MachineIndex at the given file location .
365
def find_by_prefix ( prefix ) @machines . each do | uuid , data | return data . merge ( "id" => uuid ) if uuid . start_with? ( prefix ) end nil end
Finds a machine where the UUID is prefixed by the given string .
366
def lock_machine ( uuid ) lock_path = @data_dir . join ( "#{uuid}.lock" ) lock_file = lock_path . open ( "w+" ) if lock_file . flock ( File :: LOCK_EX | File :: LOCK_NB ) === false lock_file . close lock_file = nil end lock_file end
Locks a machine exclusively to us returning the file handle that holds the lock .
367
def unlocked_release ( id ) lock_file = @machine_locks [ id ] if lock_file lock_file . close begin File . delete ( lock_file . path ) rescue Errno :: EACCES end @machine_locks . delete ( id ) end end
Releases a local lock on a machine . This does not acquire any locks so make sure to lock around it .
368
def unlocked_reload return if ! @index_file . file? data = nil begin data = JSON . load ( @index_file . read ) rescue JSON :: ParserError raise Errors :: CorruptMachineIndex , path : @index_file . to_s end if data if ! data [ "version" ] || data [ "version" ] . to_i != 1 raise Errors :: CorruptMachineIndex , path : @in...
This will reload the data without locking the index . It is assumed the caller with lock the index outside of this call .
369
def with_index_lock lock_path = "#{@index_file}.lock" File . open ( lock_path , "w+" ) do | f | f . flock ( File :: LOCK_EX ) yield end end
This will hold a lock to the index so it can be read or updated .
370
def version ( version , ** opts ) requirements = version . split ( "," ) . map do | v | Gem :: Requirement . new ( v . strip ) end providers = nil providers = Array ( opts [ :provider ] ) . map ( & :to_sym ) if opts [ :provider ] @version_map . keys . sort . reverse . each do | v | next if ! requirements . all? { | r |...
Loads the metadata associated with the box from the given IO .
371
def help opts = OptionParser . new do | o | o . banner = "Usage: vagrant [options] <command> [<args>]" o . separator "" o . on ( "-v" , "--version" , "Print the version and exit." ) o . on ( "-h" , "--help" , "Print this help." ) o . separator "" o . separator "Common commands:" commands = { } longest = 0 Vagrant . plu...
This prints out the help for the CLI .
372
def action_runner @action_runner ||= Action :: Runner . new do { action_runner : action_runner , box_collection : boxes , hook : method ( :hook ) , host : host , machine_index : machine_index , gems_path : gems_path , home_path : home_path , root_path : root_path , tmp_path : tmp_path , ui : @ui , env : self } end end
Action runner for executing actions in the context of this environment .
373
def active_machines return [ ] if ! @local_data_path machine_folder = @local_data_path . join ( "machines" ) return [ ] if ! machine_folder . directory? result = [ ] machine_folder . children ( true ) . each do | name_folder | next if ! name_folder . directory? name = name_folder . basename . to_s . to_sym name_folder ...
Returns a list of machines that this environment is currently managing that physically have been created .
374
def batch ( parallel = true ) parallel = false if ENV [ "VAGRANT_NO_PARALLEL" ] @batch_lock . synchronize do BatchAction . new ( parallel ) . tap do | b | yield b b . run end end end
This creates a new batch action yielding it and then running it once the block is called .
375
def hook ( name , opts = nil ) @logger . info ( "Running hook: #{name}" ) opts ||= { } opts [ :callable ] ||= Action :: Builder . new opts [ :runner ] ||= action_runner opts [ :action_name ] = name opts [ :env ] = self opts . delete ( :runner ) . run ( opts . delete ( :callable ) , opts ) end
This defines a hook point where plugin action hooks that are registered against the given name will be run in the context of this environment .
376
def host return @host if defined? ( @host ) host_klass = vagrantfile . config . vagrant . host host_klass = nil if host_klass == :detect begin @host = Host . new ( host_klass , Vagrant . plugin ( "2" ) . manager . hosts , Vagrant . plugin ( "2" ) . manager . host_capabilities , self ) rescue Errors :: CapabilityHostNot...
Returns the host object associated with this environment .
377
def lock ( name = "global" , ** opts ) f = nil return if ! block_given? return yield if @locks [ name ] || opts [ :noop ] lock_path = data_dir . join ( "lock.#{name}.lock" ) @logger . debug ( "Attempting to acquire process-lock: #{name}" ) lock ( "dotlock" , noop : name == "dotlock" , retry : true ) do f = File . open ...
This acquires a process - level lock with the given name .
378
def push ( name ) @logger . info ( "Getting push: #{name}" ) name = name . to_sym pushes = self . vagrantfile . config . push . __compiled_pushes if ! pushes . key? ( name ) raise Vagrant :: Errors :: PushStrategyNotDefined , name : name , pushes : pushes . keys end strategy , config = pushes [ name ] push_registry = V...
This executes the push with the given name raising any exceptions that occur .
379
def machine ( name , provider , refresh = false ) @logger . info ( "Getting machine: #{name} (#{provider})" ) cache_key = [ name , provider ] @machines ||= { } if refresh @logger . info ( "Refreshing machine (busting cache): #{name} (#{provider})" ) @machines . delete ( cache_key ) end if @machines . key? ( cache_key )...
This returns a machine with the proper provider for this environment . The machine named by name must be in this environment .
380
def setup_local_data_path ( force = false ) if @local_data_path . nil? @logger . warn ( "No local data path is set. Local data cannot be stored." ) return end @logger . info ( "Local data path: #{@local_data_path}" ) if @local_data_path . file? upgrade_v1_dotfile ( @local_data_path ) end return if ! force && root_path ...
This creates the local data directory and show an error if it couldn t properly be created .
381
def process_configured_plugins return if ! Vagrant . plugins_enabled? errors = vagrantfile . config . vagrant . validate ( nil ) if ! errors [ "vagrant" ] . empty? raise Errors :: ConfigInvalid , errors : Util :: TemplateRenderer . render ( "config/validation_failed" , errors : errors ) end installed = Plugin :: Manage...
Check for any local plugins defined within the Vagrantfile . If found validate they are available . If they are not available request to install them or raise an exception
382
def copy_insecure_private_key if ! @default_private_key_path . exist? @logger . info ( "Copying private key to home directory" ) source = File . expand_path ( "keys/vagrant" , Vagrant . source_root ) destination = @default_private_key_path begin FileUtils . cp ( source , destination ) rescue Errno :: EACCES raise Error...
This method copies the private key into the home directory if it doesn t already exist .
383
def find_vagrantfile ( search_path , filenames = nil ) filenames ||= [ "Vagrantfile" , "vagrantfile" ] filenames . each do | vagrantfile | current_path = search_path . join ( vagrantfile ) return current_path if current_path . file? end nil end
Finds the Vagrantfile in the given directory .
384
def upgrade_home_path_v1_1 if ! ENV [ "VAGRANT_UPGRADE_SILENT_1_5" ] @ui . ask ( I18n . t ( "vagrant.upgrading_home_path_v1_5" ) ) end collection = BoxCollection . new ( @home_path . join ( "boxes" ) , temp_dir_root : tmp_path ) collection . upgrade_v1_1_v1_5 end
This upgrades a home directory that was in the v1 . 1 format to the v1 . 5 format . It will raise exceptions if anything fails .
385
def upgrade_v1_dotfile ( path ) @logger . info ( "Upgrading V1 dotfile to V2 directory structure..." ) contents = path . read . strip if contents . strip == "" @logger . info ( "V1 dotfile was empty. Removing and moving on." ) path . delete return end @logger . debug ( "Attempting to parse JSON of V1 file" ) json_data ...
This upgrades a Vagrant 1 . 0 . x dotfile to the new V2 format .
386
def detect! guest_name = @machine . config . vm . guest initialize_capabilities! ( guest_name , @guests , @capabilities , @machine ) rescue Errors :: CapabilityHostExplicitNotDetected => e raise Errors :: GuestExplicitNotDetected , value : e . extra_data [ :value ] rescue Errors :: CapabilityHostNotDetected raise Error...
This will detect the proper guest OS for the machine and set up the class to actually execute capabilities .
387
def machine ( name , provider , boxes , data_path , env ) results = machine_config ( name , provider , boxes , data_path ) box = results [ :box ] config = results [ :config ] config_errors = results [ :config_errors ] config_warnings = results [ :config_warnings ] provider_cls = results [ :provider_cls ] provider_optio...
Initializes by loading a Vagrantfile .
388
def machine_names_and_options { } . tap do | r | @config . vm . defined_vms . each do | name , subvm | r [ name ] = subvm . options || { } end end end
Returns a list of the machine names as well as the options that were specified for that machine .
389
def primary_machine_name return machine_names . first if machine_names . length == 1 @config . vm . defined_vms . each do | name , subvm | return name if subvm . options [ :primary ] end nil end
Returns the name of the machine that is designated as the primary .
390
def action ( name , opts = nil ) @triggers . fire_triggers ( name , :before , @name . to_s , :action ) @logger . info ( "Calling action: #{name} on provider #{@provider}" ) opts ||= { } lock = true lock = opts . delete ( :lock ) if opts . key? ( :lock ) extra_env = opts . dup extra_env [ :trigger_env ] = @env check_cwd...
Initialize a new machine .
391
def action_raw ( name , callable , extra_env = nil ) env = { action_name : "machine_action_#{name}" . to_sym , machine : self , machine_action : name , ui : @ui , } . merge ( extra_env || { } ) @env . action_runner . run ( callable , env ) end
This calls a raw callable in the proper context of the machine using the middleware stack .
392
def id = ( value ) @logger . info ( "New machine ID: #{value.inspect}" ) id_file = nil if @data_dir id_file = @data_dir . join ( "id" ) end if value if id_file id_file . open ( "w+" ) do | f | f . write ( value ) end end if uid_file uid_file . open ( "w+" ) do | f | f . write ( Process . uid . to_s ) end end if index_u...
This sets the unique ID associated with this machine . This will persist this ID so that in the future Vagrant will be able to find this machine again . The unique ID must be absolutely unique to the virtual machine and can be used by providers for finding the actual machine associated with this instance .
393
def reload old_id = @id @id = nil if @data_dir id_file = @data_dir . join ( "id" ) id_content = id_file . read . strip if id_file . file? if ! id_content . to_s . empty? @id = id_content end end if @id != old_id && @provider @provider . machine_id_changed end @id end
This reloads the ID of the underlying machine .
394
def state result = @provider . state raise Errors :: MachineStateInvalid if ! result . is_a? ( MachineState ) uuid = index_uuid if uuid @state_mutex . synchronize do entry = @env . machine_index . get ( uuid ) if entry entry . state = result . short_description @env . machine_index . set ( entry ) @env . machine_index ...
Returns the state of this machine . The state is queried from the backing provider so it can be any arbitrary symbol .
395
def check_cwd desired_encoding = @env . root_path . to_s . encoding vagrant_cwd_filepath = @data_dir . join ( 'vagrant_cwd' ) vagrant_cwd = if File . exist? ( vagrant_cwd_filepath ) File . read ( vagrant_cwd_filepath , external_encoding : desired_encoding ) . chomp end if ! File . identical? ( vagrant_cwd . to_s , @env...
Checks the current directory for a given machine and displays a warning if that machine has moved from its previous location on disk . If the machine has moved it prints a warning to the user .
396
def all results = [ ] with_collection_lock do @logger . debug ( "Finding all boxes in: #{@directory}" ) @directory . children ( true ) . each do | child | next if ! child . directory? box_name = undir_name ( child . basename . to_s ) child . children ( true ) . each do | versiondir | next if ! versiondir . directory? n...
This returns an array of all the boxes on the system given by their name and their provider .
397
def find ( name , providers , version ) providers = Array ( providers ) requirements = version . to_s . split ( "," ) . map do | v | Gem :: Requirement . new ( v . strip ) end with_collection_lock do box_directory = @directory . join ( dir_name ( name ) ) if ! box_directory . directory? @logger . info ( "Box not found:...
Find a box in the collection with the given name and provider .
398
def upgrade_v1_1_v1_5 with_collection_lock do temp_dir = Pathname . new ( Dir . mktmpdir ( TEMP_PREFIX , @temp_root ) ) @directory . children ( true ) . each do | boxdir | next if ! boxdir . directory? box_name = boxdir . basename . to_s if v1_box? ( boxdir ) upgrade_dir = v1_upgrade ( boxdir ) FileUtils . mv ( upgrade...
This upgrades a v1 . 1 - v1 . 4 box directory structure up to a v1 . 5 directory structure . This will raise exceptions if it fails in any way .
399
def clean ( name ) return false if exists? ( name ) path = File . join ( directory , dir_name ( name ) ) FileUtils . rm_rf ( path ) end
Cleans the directory for a box by removing the folders that are empty .