Module: EbmSharedLib
- Defined in:
- lib/ebmsharedlib/options.rb,
lib/ebmsharedlib/utilities.rb
Overview
Greg Seitz
Copyright 2013, eBay Inc.
All rights reserved.
http://www.ebay.com
Defined Under Namespace
Constant Summary collapse
- ROOT_PATH =
File.("~/.ebm")
- CONFIG_DIR =
"build_configs"- CONFIG_PATH =
"#{ROOT_PATH}/#{CONFIG_DIR}"- CONFIG_SUFFIX =
".config"
Class Method Summary collapse
-
.config_name_from_dir(dir) ⇒ Object
expects us to be in the top level dir that has the same name as the config.
- .get_config_from_top_dir(prepare) ⇒ Object
-
.get_current_branch(repo, repo_path) ⇒ Object
get the current banch.
- .get_repo_name(git_path) ⇒ Object
- .prepare_config_repo ⇒ Object
- .printer ⇒ Object
-
.read_repo_config(config_name, err_msg = nil) ⇒ Object
read and return the config info for this repo.
Class Method Details
.config_name_from_dir(dir) ⇒ Object
expects us to be in the top level dir that has the same name as the config. Such as /Users/gseitz/Develop/ebay/iphone_3.1 will extract the config_name of iphone_3.1
97 98 99 |
# File 'lib/ebmsharedlib/utilities.rb', line 97 def self.config_name_from_dir(dir) config_name = "#{Dir.pwd}".split("/").last end |
.get_config_from_top_dir(prepare) ⇒ Object
121 122 123 124 125 126 127 128 129 |
# File 'lib/ebmsharedlib/utilities.rb', line 121 def self.get_config_from_top_dir(prepare) # determine config_name by extracting parent of our directory config_name = EbmSharedLib.config_name_from_dir(Dir.pwd) # try to make sure the repo is available EbmSharedLib.prepare_config_repo if (prepare) info = EbmSharedLib.read_repo_config(config_name, "Config not found, make sure you are in the top level version directory.") end |
.get_current_branch(repo, repo_path) ⇒ Object
get the current banch
110 111 112 113 114 115 116 117 118 119 |
# File 'lib/ebmsharedlib/utilities.rb', line 110 def self.get_current_branch(repo, repo_path) repo_name = EbmSharedLib.get_repo_name(repo[:git_path]) cmd = "git symbolic-ref HEAD" result = EbmSharedLib::CL.do_cmd_output(cmd, repo_path) if $?.exitstatus != 0 raise "Unable to get the current branch for #{repo_name}, you may be on a detached HEAD." end branch = result.rstrip.split("/").last end |
.get_repo_name(git_path) ⇒ Object
101 102 103 |
# File 'lib/ebmsharedlib/utilities.rb', line 101 def self.get_repo_name(git_path) repo_name = git_path.split("/").last.split(".git")[0] end |
.prepare_config_repo ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/ebmsharedlib/utilities.rb', line 63 def self.prepare_config_repo # make the root if missing FileUtils.mkpath(ROOT_PATH) #`mkdir -p #{ROOT_PATH}` # try to pull, if it fails could be due to repo not cloned cmd = "git pull" if EbmSharedLib::CL.do_cmd_result(cmd, CONFIG_PATH) != 0 # pull failed, try to clone cmd = "git clone [email protected]:eBayMobile/build_configs.git" if EbmSharedLib::CL.do_cmd_result(cmd, ROOT_PATH) != 0 raise "Unable to clone build_configs repo into #{ROOT_PATH}" end end end |
.printer ⇒ Object
105 106 107 |
# File 'lib/ebmsharedlib/utilities.rb', line 105 def self.printer @printer ||= Printer.new end |
.read_repo_config(config_name, err_msg = nil) ⇒ Object
read and return the config info for this repo
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/ebmsharedlib/utilities.rb', line 81 def self.read_repo_config(config_name, err_msg = nil) config_path = "#{EbmSharedLib::CONFIG_PATH}/configs/#{config_name}#{EbmSharedLib::CONFIG_SUFFIX}" begin json = File.open(config_path, 'r') {|f| f.read } info = JSON.parse(json) info.recursively_symbolize_keys! rescue msg = err_msg.nil? ? "Error opening config file JSON: #{config_path}" : err_msg raise msg end end |