module Omnibus

Copyright 2012-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

This is the base class that all commands and subcommands should extend from. It handles all of the Thor nastiness and method mutating, as well as defining the global configuration options.

Copyright 2013-2014 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2013-2014 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the ”License“); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2012-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2012-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2012-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2013-2014 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2012-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2013-2014 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014-2020, Chef Software Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2016-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2016-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

need to make sure rpmbuild is installed

Copyright 2016-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2012-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2014 Mike Heijmans Copyright 2014-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Copyright 2012-2018 Chef Software, Inc.

Licensed under the Apache License, Version 2.0 (the “License”); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Constants

DEFAULT_CONFIG

The path to the default configuration file.

@return [String]

VERSION

Public Class Methods

load_configuration(file) click to toggle source

Load in an Omnibus configuration file. Values will be merged with and override the defaults defined in {Config}.

@param [String] file path to a configuration file to load

@return [void]

# File lib/omnibus.rb, line 162
def load_configuration(file)
  Config.load(file)
end
logger() click to toggle source

The logger for this Omnibus instance.

@example

Omnibus.logger.debug { 'This is a message!' }

@return [Logger]

# File lib/omnibus.rb, line 130
def logger
  @logger ||= Logger.new
end
logger=(logger) click to toggle source

@api private

Programatically set the logger for Omnibus.

@param [Logger] logger

# File lib/omnibus.rb, line 141
def logger=(logger)
  @logger = logger
end
possible_paths_for(path) click to toggle source

The list of directories to search for the given path. These paths are returned **in order** of specificity.

@param [String] path

the subpath to search for

@return [Array<String>]

# File lib/omnibus.rb, line 243
def possible_paths_for(path)
  possible_paths[path] ||= [
    paths_from_project_root,
    paths_from_local_software_dirs,
    paths_from_software_gems,
  ].flatten.inject([]) do |array, directory|
    destination = File.join(directory, path)

    if File.directory?(destination)
      array << destination
    end

    array
  end
end
project(name) click to toggle source

Load the {Project} instance with the given name.

@param [String] name

the name of the project to get

@return [Project]

# File lib/omnibus.rb, line 203
def project(name)
  Project.load(name)
end
project_path(name) click to toggle source

The preferred filepath to a project with the given name on disk.

@return [String, nil]

# File lib/omnibus.rb, line 221
def project_path(name)
  project_map[name.to_s]
end
projects() click to toggle source

All {Project} instances that have been loaded.

@return [Array<:Project>]

# File lib/omnibus.rb, line 189
def projects
  project_map.map do |name, _|
    Project.load(name)
  end
end
reset!(include_logger = false) click to toggle source

Reset the current Omnibus configuration. This is primary an internal API used in testing, but it can also be useful when Omnibus is used as a library.

Note - this persists the Logger object by default.

@param [true, false] include_logger

whether the logger object should be cleared as well

@return [void]

# File lib/omnibus.rb, line 107
def reset!(include_logger = false)
  instance_variables.each do |instance_variable|
    unless include_logger
      next if instance_variable == :@logger
    end

    remove_instance_variable(instance_variable)
  end

  Config.reset!
  # Clear caches on Project and Software
  Project.reset!
  Software.reset!
end
software_path(name) click to toggle source

The preferred filepath to a software with the given name on disk.

@return [String, nil]

# File lib/omnibus.rb, line 230
def software_path(name)
  software_map[name.to_s]
end
source_root() click to toggle source

The source root is the path to the root directory of the ‘omnibus` gem.

@return [Pathname]

# File lib/omnibus.rb, line 212
def source_root
  @source_root ||= Pathname.new(File.expand_path("..", __dir__))
end
ui() click to toggle source

The UI class for Omnibus.

@return [Thor::Shell]

# File lib/omnibus.rb, line 150
def ui
  @ui ||= Thor::Base.shell.new
end
which(executable) click to toggle source

Locate an executable in the current $PATH.

@return [String, nil]

the path to the executable, or +nil+ if not present
# File lib/omnibus.rb, line 172
def which(executable)
  if File.file?(executable) && File.executable?(executable)
    executable
  elsif ENV["PATH"]
    path = ENV["PATH"].split(File::PATH_SEPARATOR).find do |path|
      File.executable?(File.join(path, executable))
    end

    path && File.expand_path(executable, path)
  end
end

Private Class Methods

basename_map(paths) click to toggle source

Map the given file paths to the basename of their file, with the .rb extension removed.

@example

{ 'foo' => '/path/to/foo' }

@return [Hash<String, String>]

# File lib/omnibus.rb, line 281
def basename_map(paths)
  paths.inject({}) do |hash, directory|
    Dir.glob("#{directory}/*.rb").each do |path|
      name = File.basename(path, ".rb")
      hash[name] ||= path
    end

    hash
  end
end
paths_from_local_software_dirs() click to toggle source

The list of all software paths on disk to software files. If relative paths are given, they are expanded relative to {Config#project_root}.

@see (Config#local_software_dirs)

@return [Array<String>]

# File lib/omnibus.rb, line 345
def paths_from_local_software_dirs
  @paths_from_local_software_dirs ||=
    Array(Config.local_software_dirs).inject([]) do |array, path|
      fullpath = File.expand_path(path, Config.project_root)

      if File.directory?(fullpath)
        array << fullpath
      end

      array
    end
end
paths_from_project_root() click to toggle source

The list of all software paths to software from the project root. This is always a single value, but an array is returned for consistency with the other software_paths_* methods.

@see (Config#project_root) @see (Config#software_dir)

@return [Array<String>]

# File lib/omnibus.rb, line 332
def paths_from_project_root
  @paths_from_project_root ||=
    [Config.project_root]
end
paths_from_software_gems() click to toggle source

The list of software paths from within the list of gems. These gems paths are loaded from disk using Gem::Specification. The latest version of the gem on disk is loaded. For this reason, it is recommended that you add these gems to your bundle and be nice to your co-workers.

@see (Config#software_gems)

@return [Array<String>]

# File lib/omnibus.rb, line 368
def paths_from_software_gems
  @paths_from_software_gems ||=
    Array(Config.software_gems).inject([]) do |array, name|
      if (spec = Gem::Specification.find_all_by_name(name).first)
        array << File.expand_path(spec.gem_dir)
      end

      array
    end
end
possible_paths() click to toggle source

The list of possible paths, cached as a hash for quick lookup.

@see {Omnibus.possible_paths_for}

@return [Hash]

# File lib/omnibus.rb, line 268
def possible_paths
  @possible_paths ||= {}
end
project_map() click to toggle source

A hash of all projects (by name) and their respective path on disk. These files are **in order**, meaning the project path is the first occurrence of the project in the list. If the same project is encountered a second time, it will be skipped.

@example

{ 'chefdk' => '/home/omnibus/project/config/projects/chefdk.rb' }

@return [Hash<String, String>]

# File lib/omnibus.rb, line 318
def project_map
  @project_map ||= basename_map(possible_paths_for(Config.project_dir))
end
software_map() click to toggle source

A hash of all softwares (by name) and their respective path on disk. These files are **in order**, meaning the software path is the first occurrence of the software in the list. If the same software is encountered a second time, it will be skipped.

@example

{ 'preparation' => '/home/omnibus/project/config/software/preparation.rb' }

@return [Hash<String, String>]

# File lib/omnibus.rb, line 303
def software_map
  @software_map ||= basename_map(possible_paths_for(Config.software_dir))
end