Dynamically builds a list of possible cookbook paths from the
 `@options` hash, Berkshelf config, and Chef config, and a logical
 guess

 @return [Array<Pathname>]
   a list of possible cookbook locations
761924
def cookbooks_paths
        @cookbooks_paths ||= begin
          paths = [
            @options[:cookbooks_path],
            Berkshelf.chef_config[:cookbook_path],
            'cookbooks'
          ].flatten.compact.map{ |path| Pathname.new(File.expand_path(path)) }.uniq

          paths.select!{ |path| File.exists?(path) }
          Strainer.ui.debug "Setting Sandbox#cookbooks_paths to #{paths.map(&:to_s)}"
          paths
        end
      end
1099588
def to_options
      @options.merge(
        environment: environment,
        env_config:  env_config,
        apps_path:   apps_path,
        rackup:      rackup,
        host:        host,
        port:        port
      )
    end
1036603
def options
      args = []

      # add all subtask options
      @subtasks.each_value do |task|
        args += task.arguments
      end

      # add the task options
      @options.each do |name,value|
        opt = get_option(name)
        args += opt.arguments(value) if opt
      end

      return args
    end
128508
def cookbook_collection(node)
      if chef_run.respond_to?(:run_context)
        chef_run.run_context.cookbook_collection # Chef 11.8+
      elsif node.respond_to?(:run_context)
        node.run_context.cookbook_collection # Chef 11+
      else
        node.cookbook_collection # Chef 10
      end
    end
759734
def calling_cookbook_path(options, kaller)
      File.expand_path(File.join(calling_cookbook_root(options, kaller), '..'))
    end
501208
def apply_chef_config!
      Chef::Log.level = @options[:log_level]

      Chef::Config.reset!
      Chef::Config.formatters.clear
      Chef::Config.add_formatter('chefspec')
      Chef::Config[:cache_type]      = 'Memory'
      Chef::Config[:client_key]      = nil
      Chef::Config[:client_name]     = nil
      Chef::Config[:node_name]       = nil
      Chef::Config[:file_cache_path] = @options[:file_cache_path] || file_cache_path
      Chef::Config[:cookbook_path]   = Array(@options[:cookbook_path])
      # If the word cookbook is in the folder name, treat it as the path. Otherwise
      # it's probably not a cookbook path and so we activate the gross hack mode.
      if Chef::Config[:cookbook_path].size == 1 && Chef::Config[:cookbook_path].first !~ /cookbook/
        Chef::Config[:chefspec_cookbook_root] = @options[:cookbook_root]
      end
      Chef::Config[:no_lazy_load]    = true
      Chef::Config[:role_path]       = Array(@options[:role_path])
      Chef::Config[:force_logger]    = true
      Chef::Config[:solo]            = true
      Chef::Config[:solo_legacy_mode] = true
      Chef::Config[:use_policyfile]  = false
      Chef::Config[:environment_path] = @options[:environment_path]
    end
720612
def copy_cookbooks
        Strainer.ui.debug "Sandbox#copy_cookbooks"
        cookbooks_and_dependencies.each do |cookbook|
          cookbook_sandbox = Strainer.sandbox_path.join(cookbook.cookbook_name)

          # Copy the files to our sandbox
          Strainer.ui.debug "Copying '#{cookbook.name}' to '#{cookbook_sandbox}'"
          FileUtils.cp_r(cookbook.path, cookbook_sandbox)

          # Override the @path location so we don't need to create a new object
          cookbook.path = cookbook_sandbox
        end
      end
392120
def process_options
        @options.verbose = false if @options.quiet
        @options.file = (user_home+"/.route53") if @options.file.nil?
        #setup file
        if @options.setup
          setup
        end
        load_config
        @config['access_key'] = @options.access unless @options.access.nil?
        @config['secret_key'] = @options.secret unless @options.secret.nil?


        required_options("",["--access-key"]) if @config['access_key'].nil? || @config['access_key'] == ""
        required_options("",["--secret_key"]) if @config['secret_key'].nil? || @config['secret_key'] == ""

      end
1019828
def all_paths
      results = []
      paths = routes.map(&:path)
      paths.each do |p|
        sub_paths = []
        parts = p.split('/')
        until parts.empty?
          parts.pop
          sub_path = parts.join('/')
          sub_paths << sub_path unless sub_path == ''
        end
        results += sub_paths
      end
      @all_paths = (results + paths).sort.uniq
    end
1047198
def build_cookbook(build_config, templatepack_path,
                   cookbooks_home, force=False):
    
    with open(build_config) as cfg:
        cfg = json.load(cfg)

    cookbook_name = cfg['name']
    template_pack = pack.TemplatePack(templatepack_path)

    written_files = []
    cookbook = create_new_cookbook(cookbook_name, cookbooks_home)

    for stencil_definition in cfg['stencils']:

        selected_stencil_set_name = stencil_definition.get('stencil_set')
        stencil_set = template_pack.load_stencil_set(selected_stencil_set_name)

        selected_stencil_name = _determine_selected_stencil(
            stencil_set,
            stencil_definition
        )

        stencil = stencil_set.get_stencil(selected_stencil_name,
                                          **stencil_definition)

        updated_cookbook = process_stencil(
            cookbook,
            cookbook_name,  # in case no metadata.rb yet
            template_pack,
            force,
            stencil_set,
            stencil,
            written_files
        )

    return written_files, updated_cookbook
792887
def build_path
      template = path_template.dup
      path_params.each{ |key, value| template["{#{key}}"] = ERB::Util.url_encode(value) if template.include?("{#{key}}") } unless path_params.nil?
      skip_encoding_path_params.each{ |key, value| template["{#{key}}"] = value } unless skip_encoding_path_params.nil?
      path = URI.parse(template.gsub(/([^:]|\A)\/\//, '\1/'))
      unless skip_encoding_query_params.nil?
        path.query = [(path.query || ""), skip_encoding_query_params.reject{|_, v| v.nil?}.map{|k,v| "#{k}=#{v}"}].join('&')
      end
      path
    end
16371
def get_path_list(opts):
    
    paths = []
    for opt, arg in list(opts.items()):
        if opt in ('-p', '--jspath'):
            paths.append(arg)
    return paths or [os.getcwd()]
385492
def run
      @ok = true
      if @run_list.empty?
        # Deliberately avoid auditing anything since we did not run any recipes
        # Still download the cookbooks repos if in dev mode
        checkout_cookbook_repos
        download_cookbooks if CookState.cookbooks_path
        report_success(nil)
      else
        configure_ohai
        configure_logging
        configure_chef
        download_attachments if @ok
        install_packages if @ok
        checkout_cookbook_repos if @ok
        download_cookbooks if @ok
        update_cookbook_path if @ok

        # note that chef normally enforces path sanity before executing ohai in
        # the client run method. we create ohai before client run and some ohai
        # plugins behave badly when there is no ruby on the PATH. we need to do
        # a pre-emptive path sanity here before we start ohai and chef.
        enforce_path_sanity
        check_ohai { |o| converge(o) } if @ok
      end
      true
    rescue Exception => e
      report_failure('Execution failed', "The following exception was caught while preparing for execution: (#{e.message}) from\n#{e.backtrace.join("\n")}")
    end
112050
def generate_temp_cookbook(arguments, reporter)
      opts = if arguments.length == 1
               { recipe_spec: arguments.shift,
                 cookbook_repo_paths: parsed_options[:cookbook_repo_paths] }
             else
               { resource_type: arguments.shift,
                 resource_name: arguments.shift,
                 resource_properties: properties_from_string(arguments) }
             end
      action = ChefApply::Action::GenerateTempCookbook.from_options(opts)
      action.run do |event, data|
        case event
        when :generating
          reporter.update(TS.generate_temp_cookbook.generating)
        when :success
          reporter.success(TS.generate_temp_cookbook.success)
        else
          handle_message(event, data, reporter)
        end
      end
      action.generated_cookbook
    end
786039
def get_recipes_in_cookbook(name):
    
    recipes = {}
    path = None
    cookbook_exists = False
    metadata_exists = False
    for cookbook_path in cookbook_paths:
        path = os.path.join(cookbook_path, name)
        path_exists = os.path.exists(path)
        # cookbook exists if present in any of the cookbook paths
        cookbook_exists = cookbook_exists or path_exists
        if not path_exists:
            continue

        _generate_metadata(path, cookbook_path, name)

        # Now try to open metadata.json
        try:
            with open(os.path.join(path, 'metadata.json'), 'r') as f:
                try:
                    cookbook = json.loads(f.read())
                except ValueError as e:
                    msg = "Little Chef found the following error in your"
                    msg += " {0} file:\n  {1}".format(
                        os.path.join(path, 'metadata.json'), e)
                    abort(msg)
                # Add each recipe defined in the cookbook
                metadata_exists = True
                recipe_defaults = {
                    'description': '',
                    'version': cookbook.get('version'),
                    'dependencies': cookbook.get('dependencies', {}).keys(),
                    'attributes': cookbook.get('attributes', {})
                }
                for recipe in cookbook.get('recipes', []):
                    recipes[recipe] = dict(
                        recipe_defaults,
                        name=recipe,
                        description=cookbook['recipes'][recipe]
                    )
            # Cookbook metadata.json was found, don't try next cookbook path
            # because metadata.json in site-cookbooks has preference
            break
        except IOError:
            # metadata.json was not found, try next cookbook_path
            pass
    if not cookbook_exists:
        abort('Unable to find cookbook "{0}"'.format(name))
    elif not metadata_exists:
        abort('Cookbook "{0}" has no metadata.json'.format(name))
    # Add recipes found in the 'recipes' directory but not listed
    # in the metadata
    for cookbook_path in cookbook_paths:
        recipes_dir = os.path.join(cookbook_path, name, 'recipes')
        if not os.path.isdir(recipes_dir):
            continue
        for basename in os.listdir(recipes_dir):
            fname, ext = os.path.splitext(basename)
            if ext != '.rb':
                continue
            if fname != 'default':
                recipe = '%s::%s' % (name, fname)
            else:
                recipe = name
            if recipe not in recipes:
                recipes[recipe] = dict(recipe_defaults, name=recipe)
    # When a recipe has no default recipe (libraries?),
    # add one so that it is listed
    if not recipes:
        recipes[name] = dict(
            recipe_defaults,
            name=name,
            description='This cookbook has no default recipe'
        )
    return recipes.values()
296470
def get_path_suggestions path
      return [] if path.nil?
      result = []
      result.concat store.get_path_pins(path)
      # if result.empty?
      #   lp = live_map.get_path_pin(path)
      #   result.push lp unless lp.nil?
      # end
      resolve_method_aliases(result)
    end
805257
def copy_globals
        if chef_repo?
          files = Dir[*%W(#{@options['strainer_file']} foodcritic .cane .kitchen.yml Berksfile README.md .rspec spec test)]
        elsif cookbook_repo?
          files = Dir[*%W(#{@options['strainer_file']} foodcritic .cane .kitchen.yml Berksfile README.md .rspec)]
        else
          files = []
        end

        Strainer.ui.debug "Copying '#{files}' to '#{Strainer.sandbox_path}'"
        FileUtils.cp_r(files, Strainer.sandbox_path)
      end