Top Level Namespace
Defined Under Namespace
Modules: A4Tools Classes: String, StringBuffer
Instance Method Summary collapse
- #acl_line(acl) ⇒ Object
- #acquire_object ⇒ Object
- #add_queries(*new_queries) ⇒ Object
-
#all_apps ⇒ Object
Tab completors.
- #all_branches ⇒ Object
- #all_commits ⇒ Object
- #all_jebs ⇒ Object
- #all_of_key(key) ⇒ Object
- #author(build) ⇒ Object
- #branches(build) ⇒ Object
- #build(cls, path = []) ⇒ Object
- #build_id(build) ⇒ Object
- #build_info(build) ⇒ Object
- #build_request(code, machine) ⇒ Object
- #build_set ⇒ Object
- #build_set_by_app(builds) ⇒ Object
-
#builds ⇒ Object
Builds.
- #builds_for_app(app) ⇒ Object
- #builds_for_branch(branch) ⇒ Object
- #builds_for_commit(commit) ⇒ Object
- #builds_for_jeb(jeb) ⇒ Object
- #bypass(object, type) ⇒ Object
- #categories ⇒ Object
- #checkout(id) ⇒ Object
- #client_for_key(key, url) ⇒ Object
- #client_interfaces ⇒ Object
- #clone_repo ⇒ Object
- #collapse_ranges(elements) ⇒ Object
- #concise_host(host) ⇒ Object
- #connect_kai ⇒ Object
- #connect_raw ⇒ Object
- #connect_to_site_id(site_id) ⇒ Object
- #connect_to_url(base) ⇒ Object
- #connect_to_usher_host(host) ⇒ Object
- #descriptions ⇒ Object
- #device_type ⇒ Object
- #event_by_identifier(identifier) ⇒ Object
- #event_code(identifier = nil) ⇒ Object
- #event_description(event) ⇒ Object
- #event_name(identifier = nil) ⇒ Object
- #event_table_item(code) ⇒ Object
- #events ⇒ Object
- #expiration(mod) ⇒ Object
- #fake_repo_info ⇒ Object
- #fetch ⇒ Object
- #field_value(object, field_name) ⇒ Object
- #find_class(target, data, type = nil) ⇒ Object
- #find_class_in_array(target, data, type) ⇒ Object
- #find_request_with_id(id) ⇒ Object
- #get_a4tools ⇒ Object
- #get_action(allowed) ⇒ Object
- #get_commits ⇒ Object
- #get_talk ⇒ Object
- #get_value(field, path) ⇒ Object
- #get_value_boolean(value) ⇒ Object
- #get_value_integer(value) ⇒ Object
- #get_value_real(value) ⇒ Object
- #get_value_string(value) ⇒ Object
- #get_version ⇒ Object
- #handle_array_element(field, path, depth) ⇒ Object
- #handle_array_start(field, path, depth) ⇒ Object
- #handle_complex(field, path, assume_build = false) ⇒ Object
- #handle_field(field, path, depth = 0, assume_build = false) ⇒ Object
- #handle_primitive(field, path) ⇒ Object
- #has_cache?(field) ⇒ Boolean
- #host_event(code) ⇒ Object
- #host_supports_ssh?(host) ⇒ Boolean
- #hostname ⇒ Object
- #human_readable_size(size) ⇒ Object
- #in_array?(field, depth) ⇒ Boolean
- #in_container?(field, depth) ⇒ Boolean
- #in_hash?(field, depth) ⇒ Boolean
- #json_output ⇒ Object
-
#list ⇒ Object
List.
- #list_all_commands ⇒ Object
- #list_branches ⇒ Object
- #list_category(category) ⇒ Object
- #list_command(name) ⇒ Object
- #list_commits ⇒ Object
- #list_fields(name) ⇒ Object
- #list_methods(name) ⇒ Object
- #list_site(site_id, publications) ⇒ Object
- #list_site_app(app, orders) ⇒ Object
- #machine_list ⇒ Object
- #make_talk ⇒ Object
- #messages ⇒ Object
- #method(message) ⇒ Object
- #origin_line(method) ⇒ Object
- #os_name ⇒ Object
- #os_version ⇒ Object
- #parse_params(args) ⇒ Object
- #persist ⇒ Object
- #pick_toplevel(message) ⇒ Object
- #player_rating ⇒ Object
- #populate(field, path) ⇒ Object
- #prompt(basis = {}) ⇒ Object
- #prompt_add ⇒ Object
- #prompt_delete ⇒ Object
- #prompt_edit ⇒ Object
- #prompt_for_action(field, path, type, actions) ⇒ Object
-
#prompt_for_apps(set) ⇒ Object
Publish.
- #prompt_for_path(path) ⇒ Object
- #prompt_for_value(path, type) ⇒ Object
- #provider_line(id_provider) ⇒ Object
- #publish ⇒ Object
- #qa_event_table_item(code, machine) ⇒ Object
- #query_for_params ⇒ Object
- #random_machine ⇒ Object
- #range_for_args(args) ⇒ Object
- #read ⇒ Object
- #refresh_talk ⇒ Object
- #render_client(key) ⇒ Object
- #render_result(response) ⇒ Object
- #render_success(result) ⇒ Object
- #render_summary(message) ⇒ Object
- #render_text(message) ⇒ Object
- #repo ⇒ Object
- #repo_exists? ⇒ Boolean
- #repo_info(directory, repository = nil) ⇒ Object
- #request_caches ⇒ Object
- #send(message) ⇒ Object
- #send_event(message) ⇒ Object
- #send_raw(message) ⇒ Object
- #send_wrapped(message) ⇒ Object
- #sender(msg) ⇒ Object
- #serial_number ⇒ Object
- #show(query) ⇒ Object
- #show_all_sites ⇒ Object
-
#show_app(app, builds) ⇒ Object
Other stuff.
- #show_build_set(set) ⇒ Object
- #show_builder_list(builders) ⇒ Object
- #show_class(query) ⇒ Object
- #show_constant(query) ⇒ Object
- #show_enumeration(query) ⇒ Object
- #show_field(cls, field) ⇒ Object
- #show_field_help(field, depth = -1)) ⇒ Object
- #show_glossary(query) ⇒ Object
- #show_host_info(site_id) ⇒ Object
- #show_list ⇒ Object
- #show_method(protocol, method) ⇒ Object
- #show_protocol(query) ⇒ Object
- #show_publications(publications) ⇒ Object
- #show_site(site_id) ⇒ Object
- #show_usher_site(site_id, site) ⇒ Object
- #site_id_for_arg(arg) ⇒ Object
- #source_id(target) ⇒ Object
- #store ⇒ Object
- #string_for_range(start, last, params = {}) ⇒ Object
- #style_for_section(section) ⇒ Object
- #symbolify(item) ⇒ Object
- #talk ⇒ Object
- #talk_file ⇒ Object
- #talk_json_path ⇒ Object
- #target_client ⇒ Object
- #text_output ⇒ Object
- #timecode(msg) ⇒ Object
- #timestamp(ts) ⇒ Object
- #toplevel_value ⇒ Object
- #translate(value) ⇒ Object
- #try_acl(params, acl) ⇒ Object
- #try_connection(hostname, port) ⇒ Object
-
#try_connection_options(options, timeout = 2) ⇒ Object
array of { :host, :port }.
- #type_at_depth(field, depth) ⇒ Object
- #use_json? ⇒ Boolean
- #verbose_host(host) ⇒ Object
- #yes_no(b) ⇒ Object
Instance Method Details
#acl_line(acl) ⇒ Object
82 83 84 85 86 87 88 89 |
# File 'lib/net_shell/builtin_commands/host.rb', line 82 def acl_line(acl) service = usherm.service_for_id(acl[:idService]) return "Non-existent service #{acl[:idService]}" if service.nil? proto = service[:isUdp] ? "UDP" : "TCP" external_addr = [acl[:ip], acl[:port]].compact.join(":") "\t\t#{service[:name].style(:service)}, #{proto} #{service[:port]} (#{external_addr} external)" end |
#acquire_object ⇒ Object
37 38 39 40 |
# File 'lib/net_shell/builtin_commands/jsoncache.rb', line 37 def acquire_object obj = JSON.parse(@input.read_all) rescue nil talk.locate_data(obj, params[:field], params[:type]) rescue nil end |
#add_queries(*new_queries) ⇒ Object
54 55 56 57 58 59 60 61 62 |
# File 'lib/net_shell/builtin_commands/show.rb', line 54 def add_queries(*new_queries) @subqueries ||= [] @seen ||= {} new_queries.each do |q| next if q == "none" # given by methods @subqueries.push q unless @seen.has_key? q @seen[q] = true end end |
#all_apps ⇒ Object
Tab completors
63 64 65 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 63 def all_apps all_of_key(:appId) end |
#all_branches ⇒ Object
67 68 69 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 67 def all_branches all_of_key(:branches) end |
#all_commits ⇒ Object
71 72 73 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 71 def all_commits all_of_key(:commitId) end |
#all_jebs ⇒ Object
75 76 77 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 75 def all_jebs all_of_key(:buildId) end |
#all_of_key(key) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 79 def all_of_key(key) instances = {} deployment[:buildList][:builds].each do |build| if build[key].is_a? Array then build[key].each { |item| instances[item] = true } else instances[build[key]] = true end end instances.keys end |
#author(build) ⇒ Object
262 263 264 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 262 def (build) build[:author].style(:author) rescue "" end |
#branches(build) ⇒ Object
258 259 260 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 258 def branches(build) build[:branches].join(",").style(:branch) end |
#build(cls, path = []) ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/net_shell/builtin_commands/build.rb', line 241 def build(cls, path=[]) if path.empty? then console_puts "Building #{talk.truncated_name cls}..." else console_puts "#{talk.truncated_name cls} #{path.last}\n\t#{cls[:description]}" end result = {} cls[:field].each { |field| result[field[:name]] = handle_field(field, path) } result end |
#build_id(build) ⇒ Object
254 255 256 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 254 def build_id(build) sprintf("%4d", build[:buildRecordId]).style(:identifier) end |
#build_info(build) ⇒ Object
118 119 120 121 122 |
# File 'lib/net_shell/builtin_commands/site.rb', line 118 def build_info(build) name = build[:buildId].style(:build_name) branches = build[:branches].join(",").style(:branch) "#{name} [#{branches}]" end |
#build_request(code, machine) ⇒ Object
83 84 85 86 87 88 89 |
# File 'lib/net_shell/builtin_commands/kai_event.rb', line 83 def build_request(code, machine) { __class: "com.acres4.common.info.mercury.qatest.QATestEventRequest", tok:nil, eventList:[ qa_event_table_item(code, machine) ] } end |
#build_set ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 138 def build_set if params[:jeb] then builds_for_jeb(params[:jeb]) elsif params[:commit] then builds_for_commit(params[:commit]) elsif params[:branch] then builds_for_branch(params[:branch]) elsif params[:app] then builds_for_app(params[:app]) else deployment[:buildList][:builds] end end |
#build_set_by_app(builds) ⇒ Object
189 190 191 192 193 194 195 196 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 189 def build_set_by_app(builds) apps = {} builds.each do |build| apps[build[:appId]] ||= [] apps[build[:appId]].push build end apps end |
#builds ⇒ Object
Builds
133 134 135 136 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 133 def builds show_build_set(build_set) "" end |
#builds_for_app(app) ⇒ Object
152 153 154 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 152 def builds_for_app(app) deployment[:buildList][:builds].select { |build| talk.name_matches?(build[:appId], app) } end |
#builds_for_branch(branch) ⇒ Object
178 179 180 181 182 183 184 185 186 187 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 178 def builds_for_branch(branch) set = if params[:app] then builds_for_app(params[:app]) else deployment[:buildList][:builds] end set.select { |build| build[:branches].include? branch } end |
#builds_for_commit(commit) ⇒ Object
156 157 158 159 160 161 162 163 164 165 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 156 def builds_for_commit(commit) set = if params[:app] then builds_for_app(params[:app]) else deployment[:buildList][:builds] end set.select { |build| build[:commitId].start_with? commit } end |
#builds_for_jeb(jeb) ⇒ Object
167 168 169 170 171 172 173 174 175 176 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 167 def builds_for_jeb(jeb) set = if params[:app] then builds_for_app(params[:app]) else deployment[:buildList][:builds] end set.select { |build| build[:buildId] == jeb } end |
#bypass(object, type) ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 177 def bypass(object, type) case type when "com.acres4.common.info.NamedObjectWrapper" return bypass(object[:body], object[:className]) when "com.acres4.common.info.JSONRPCRequest" return bypass(object[:params], talk.guess_class(object[:params])) when "com.acres4.common.info.JSONRPCResponse" return bypass(object[:result], talk.guess_class(object[:result])) else return [object, type] end end |
#categories ⇒ Object
26 27 28 |
# File 'lib/net_shell/builtin_commands/help.rb', line 26 def categories (@shell.built_ins.map { |name| @shell.built_in(name).category_text }).sort.uniq end |
#checkout(id) ⇒ Object
60 61 62 63 |
# File 'lib/net_shell/builtin_commands/talk.rb', line 60 def checkout(id) id = Jebediah.new.process(id)[:result] if params[:jeb] `cd #{repo} && git checkout origin/#{id}` end |
#client_for_key(key, url) ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/net_shell/builtin_commands/connect.rb', line 100 def client_for_key(key, url) case key when :mercury AcresClient.new(url, @shell.get_env(:kai_user), @shell.get_env(:kai_pass)) when :central AcresClient.new(url, @shell.get_env(:usherm_user), @shell.get_env(:usherm_pass)) when :config KaiConfigClient.new(url, @shell.get_env(:usherm_user), @shell.get_env(:usherm_pass)) when :qa AcresClient.new(url, @shell.get_env(:kai_user), @shell.get_env(:kai_pass)) else AcresClient.new(url, @shell.get_env(:usherm_user), @shell.get_env(:usherm_pass)) end end |
#client_interfaces ⇒ Object
115 116 117 118 119 120 121 122 |
# File 'lib/net_shell/builtin_commands/connect.rb', line 115 def client_interfaces { mercury:"/mercury/client?wrap", central:"/central/central?wrap", config:"/config/config?wrap", qa:"/mercury/qatest?wrap" } end |
#clone_repo ⇒ Object
71 72 73 74 |
# File 'lib/net_shell/builtin_commands/talk.rb', line 71 def clone_repo puts "Cloning respository into #{repo}" `cd #{File.join(repo, "..")} && git clone [email protected]:acres4/talk` end |
#collapse_ranges(elements) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/net_shell/builtin_commands/host.rb', line 40 def collapse_ranges(elements) return "None" if elements.nil? or elements.empty? elements = (elements.map { |element| element.to_i }).sort ranges = [] start = elements.first last = nil elements.each do |element| if not(last.nil?) and element != last + 1 ranges.push(string_for_range(start, last)) start = element end last = element end ranges.push(string_for_range(start, last)) ranges.join(", ") end |
#concise_host(host) ⇒ Object
116 117 118 119 120 121 122 123 124 125 |
# File 'lib/net_shell/builtin_commands/host.rb', line 116 def concise_host(host) datacenter = usherm.datacenter(host[:idDataCenter]) dcnote = if datacenter.nil? "unknown (#{host[:idDataCenter]})" else "#{datacenter[:dataCenterName].style(:datacenter)}" end "#{host[:hostName].style(:host)} -- #{dcnote} #{usherm.env_type(host[:systemHostEnvironment])}" end |
#connect_kai ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/net_shell/builtin_commands/connect.rb', line 55 def connect_kai dest = args[1] if dest.match(/^([a-zA-Z]+):\/\/[a-zA-Z0-9\-\.]+(:[0-9]+)?(\/)?/) then connect_to_url(dest) elsif dest.match(/^[0-9]+$/) then connect_to_site_id(dest.to_i) else connect_to_usher_host(dest) end end |
#connect_raw ⇒ Object
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/net_shell/builtin_commands/connect.rb', line 39 def connect_raw key = args[2].to_sym rescue :user clients = [] client = AcresClient.new(args[1]) return show_error("Unable to contact server at #{args[1]}") unless client.transport_connect @shell.set_client(key, client) client.on(:connect) { |trigger, msg| @shell.notify_connect(client) } client.on(:sent) { |trigger,msg| @shell.(client, msg) } client.on(:message) { |trigger,msg| @shell.(client, msg) } client.on(:disconnect) { |trigger,msg| @shell.notify_disconnect(client) } @shell.set_active_client(key) "" end |
#connect_to_site_id(site_id) ⇒ Object
83 84 85 86 87 88 89 90 91 92 |
# File 'lib/net_shell/builtin_commands/connect.rb', line 83 def connect_to_site_id(site_id) site = usherm.site_with_id(site_id) return show_error("Site ##{site_id}: No such site ID in usher") if site.nil? provider = usherm.provider_for_product(site_id, "Mercury") return show_error("Site ##{site_id}: Does not offer Mercury") if provider.nil? url = usherm.url_for_provider(provider) return show_error("Site ##{site_id}: Site appears to be down") if url.nil? puts "Connecting to Kai at #{url}" connect_to_url(url) end |
#connect_to_url(base) ⇒ Object
73 74 75 76 77 78 79 80 81 |
# File 'lib/net_shell/builtin_commands/connect.rb', line 73 def connect_to_url(base) client_interfaces.each do |key, uri| url = URI.join(base, uri).to_s @shell.set_client(key, client_for_key(key, url)) end request_caches "Connected to #{@shell.client(:config).version.style(:host)} server" end |
#connect_to_usher_host(host) ⇒ Object
94 95 96 97 98 |
# File 'lib/net_shell/builtin_commands/connect.rb', line 94 def connect_to_usher_host(host) site = usherm.site_with_name(host) return show_error("Site #{host}: Does not appear to be listed in usher") if site.nil? connect_to_site_id(site[:idSite]) end |
#descriptions ⇒ Object
96 97 98 |
# File 'lib/net_shell/builtin_commands/show.rb', line 96 def descriptions { class:"Classes", glossary:"Glossaries", enumeration:"Enumerations", protocol:"Protocols" } end |
#device_type ⇒ Object
13 14 15 |
# File 'lib/object_builder/definitions/connection_request.rb', line 13 def device_type "Ruby #{RUBY_VERSION}" end |
#event_by_identifier(identifier) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/net_shell/builtin_commands/kai_event.rb', line 133 def event_by_identifier(identifier) identifier ||= args[1] identifier = identifier.to_i if identifier.is_a? String and identifier.match(/^[0-9]+$/) events.events.each do |event| return event if(event[:key].to_s == identifier.to_s or event[:code] == identifier) end pp identifier pp args[1] nil end |
#event_code(identifier = nil) ⇒ Object
145 146 147 |
# File 'lib/net_shell/builtin_commands/kai_event.rb', line 145 def event_code(identifier=nil) event_by_identifier(identifier)[:code] end |
#event_description(event) ⇒ Object
63 64 65 66 67 |
# File 'lib/net_shell/builtin_commands/kai_event.rb', line 63 def event_description(event) name = event_name(event[:eventList][0][:event][:idEventCode]) || event[:eventList][0][:event][:idEventCode] location = event[:eventList][0][:location] "#{name} @ #{location}" end |
#event_name(identifier = nil) ⇒ Object
149 150 151 |
# File 'lib/net_shell/builtin_commands/kai_event.rb', line 149 def event_name(identifier=nil) event_by_identifier(identifier)[:key] end |
#event_table_item(code) ⇒ Object
98 99 100 101 102 103 104 105 106 |
# File 'lib/net_shell/builtin_commands/kai_event.rb', line 98 def event_table_item(code) { idEventCode:code, hostEvent:host_event(code), collectStats:false, receiptTime:Time.now.to_i, playerRating: } end |
#events ⇒ Object
33 34 35 |
# File 'lib/a4tools.rb', line 33 def events $events ||= A4Tools::EventManager.new end |
#expiration(mod) ⇒ Object
66 67 68 |
# File 'lib/net_shell/builtin_commands/site.rb', line 66 def expiration(mod) mod[:permanent] ? "Never" : (mod[:expiration]) end |
#fake_repo_info ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/object_builder/definitions/app_info_for_script.rb', line 56 def fake_repo_info { repository: "a4tools", sha1:"67021ff1f82c941454a6d2bffa7a2ffde0a6320a", jeb:"exquisitely eased cougar", timestamp:1399271669, author:"Jonas Acres", notes:"Progress commit", branches:["master"] } end |
#fetch ⇒ Object
56 57 58 |
# File 'lib/net_shell/builtin_commands/talk.rb', line 56 def fetch `cd #{repo} && git fetch` end |
#field_value(object, field_name) ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/net_shell/builtin_commands/inject.rb', line 33 def field_value(object, field_name) m = field_name.to_s.match(/^([a-zA-Z0-9_]+)\[([0-9]+)\]$/) if m.nil? then return object[field_name.to_sym] rescue nil else name = m[1] value = object[name.to_sym][m[2].to_i] rescue nil return value end end |
#find_class(target, data, type = nil) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/net_shell/builtin_commands/excerpt.rb', line 44 def find_class(target, data, type=nil) return find_class_in_array(target, data, type) if data.is_a? Array type ||= talk.guess_class(data) cls = talk.class_named(type) rescue nil if cls.nil? then data.each do |key, value| searchval = find_class(target, value) return searchval unless searchval.nil? end else cls[:field].each do |field| value = data[field[:name].to_sym] fieldtype = talk.(field[:type].first) next if value.nil? or fieldtype.nil? return value if talk.name_matches?(fieldtype, target) end end nil end |
#find_class_in_array(target, data, type) ⇒ Object
67 68 69 70 71 72 73 74 |
# File 'lib/net_shell/builtin_commands/excerpt.rb', line 67 def find_class_in_array(target, data, type) data.each do |datum| result = find_class(target, datum, type) return result unless result.nil? end return nil end |
#find_request_with_id(id) ⇒ Object
157 158 159 160 161 162 163 164 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 157 def find_request_with_id(id) target_client.history.each do |msg| next if msg[:message].nil? or msg[:message][:id].nil? or not(msg[:message].has_key? :params) return msg[:message] if msg[:message][:id].to_i == id.to_i end nil end |
#get_a4tools ⇒ Object
68 69 70 |
# File 'lib/object_builder/definitions/app_info_for_script.rb', line 68 def get_a4tools repo_info(File.dirname(__FILE__), "a4tools") end |
#get_action(allowed) ⇒ Object
37 38 39 40 41 |
# File 'lib/net_shell/builtin_commands/build.rb', line 37 def get_action(allowed) char = STDIN.gets.chomp rescue nil char = nil unless char.nil? or allowed.include? char char end |
#get_commits ⇒ Object
76 77 78 79 |
# File 'lib/object_builder/definitions/app_info_for_script.rb', line 76 def get_commits #list = [ get_a4tools, get_talk ].compact list = [ fake_repo_info ] if list.nil? or list.empty? end |
#get_talk ⇒ Object
72 73 74 |
# File 'lib/object_builder/definitions/app_info_for_script.rb', line 72 def get_talk repo_info(File.join(File.dirname(__FILE__), "../../../../talk"), "talk") end |
#get_value(field, path) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/net_shell/builtin_commands/build.rb', line 83 def get_value(field, path) type = field[:type].first console_print prompt_for_value(path, type) value = STDIN.gets if value.nil? then value = "null" # nil => CTRL+D. Take advantage that all get_value_* interpret null as nil-value to make CTRL+D -> null shortcut. console_puts # need a newline since none was actually typed end value = value.chomp if(value == "?") then show_field_help(field) return get_value(field, path) end return get_value_integer(value) if([ "uint8", "uint16", "uint32", "uint64", "int8", "int16", "int32", "int64" ].include?(type)) return get_value_real(value) if([ "real" ].include?(type)) return get_value_boolean(value) if([ "bool" ].include?(type)) return get_value_string(value) if([ "string" ].include?(type)) end |
#get_value_boolean(value) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/net_shell/builtin_commands/build.rb', line 61 def get_value_boolean(value) case value when "0", "false" false when "1", "true" true when "", "null" nil else true end end |
#get_value_integer(value) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/net_shell/builtin_commands/build.rb', line 52 def get_value_integer(value) case value when nil, "null", "" nil else value.to_i end end |
#get_value_real(value) ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/net_shell/builtin_commands/build.rb', line 43 def get_value_real(value) case value when nil, "null", "" nil else value.to_f end end |
#get_value_string(value) ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/net_shell/builtin_commands/build.rb', line 74 def get_value_string(value) case value when nil, "null" nil else value end end |
#get_version ⇒ Object
81 82 83 |
# File 'lib/object_builder/definitions/app_info_for_script.rb', line 81 def get_version VERSION end |
#handle_array_element(field, path, depth) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/net_shell/builtin_commands/build.rb', line 157 def handle_array_element(field, path, depth) actions = [ "build", "null", "done", "?" ] case prompt_for_action(field, path, type_at_depth(field, depth), actions) when "?" show_field_help(field, depth) return handle_array_element(field, path, depth) when nil, "null" return { value:nil } when "done" return nil when "build" return { value:handle_field(field, path, depth+1, true) } end end |
#handle_array_start(field, path, depth) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/net_shell/builtin_commands/build.rb', line 135 def handle_array_start(field, path, depth) actions = [ "build", "null", "?" ] case prompt_for_action(field, path, type_at_depth(field, depth), actions) when "?" show_field_help(field, depth) return handle_array_start(field, path, depth) when nil, "null" return nil when "build" collection = [] building = true index = 0 while true do element = handle_array_element(field, path[0..-2] + ["#{path.last}[#{index}]"], depth+1) return collection if element.nil? collection.push element[:value] index += 1 end end end |
#handle_complex(field, path, assume_build = false) ⇒ Object
197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 |
# File 'lib/net_shell/builtin_commands/build.rb', line 197 def handle_complex(field, path, assume_build=false) return build(talk.class_named(field[:type].first), path) if assume_build actions = if has_cache?(field) then [ "build", "populate", "null", "?" ] else [ "build", "null", "?" ] end case prompt_for_action(field, path, field[:type].first, actions) when "build" build(talk.class_named(field[:type].first), path) when nil, "null" nil when "populate" populate(field, path) when "?" show_field_help(field, field[:type].length-1) return handle_complex(field, path) end end |
#handle_field(field, path, depth = 0, assume_build = false) ⇒ Object
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
# File 'lib/net_shell/builtin_commands/build.rb', line 223 def handle_field(field, path, depth=0, assume_build=false) path += [field[:name]] if depth == 0 if depth+1 < field[:type].length then if in_array?(field, depth) return handle_array_start(field, path, depth) else # TODO: handle dictionary return nil end end if talk.primitive? field[:type].first return handle_primitive(field, path) else return handle_complex(field, path, assume_build) end end |
#handle_primitive(field, path) ⇒ Object
219 220 221 |
# File 'lib/net_shell/builtin_commands/build.rb', line 219 def handle_primitive(field, path) get_value(field, path) end |
#has_cache?(field) ⇒ Boolean
190 191 192 193 194 195 |
# File 'lib/net_shell/builtin_commands/build.rb', line 190 def has_cache?(field) ObjectBuilder.supported_classes(false).each do |name| return true if talk.name_matches?(name, field[:type].first) end false end |
#host_event(code) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/net_shell/builtin_commands/kai_event.rb', line 108 def host_event(code) { priKey:0, hostDeviceId:nil, eventCode:code.to_s, idPatron:params[:patron] || 0, idEmployee:params[:employee] || 0, amount:params[:amount] || 0, meters:nil, eventTime:Time.now.to_i, hostTime:Time.now.to_i } end |
#host_supports_ssh?(host) ⇒ Boolean
46 47 48 |
# File 'lib/net_shell/builtin_commands/ssh.rb', line 46 def host_supports_ssh?(host) not usherm.acl_for_service(host, "ssh").nil? end |
#hostname ⇒ Object
22 23 24 |
# File 'lib/object_builder/definitions/connection_request.rb', line 22 def hostname `hostname`.chomp end |
#human_readable_size(size) ⇒ Object
141 142 143 144 145 146 147 148 149 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 141 def human_readable_size(size) titles = [ "B", "KiB", "MiB", "GiB", "TiB" ] titles.each_index do |idx| title = titles[idx] unit = 1024**idx boundary = 1024*unit return "#{size/unit} #{title}" if size < boundary or title == titles.last end end |
#in_array?(field, depth) ⇒ Boolean
105 106 107 |
# File 'lib/net_shell/builtin_commands/build.rb', line 105 def in_array?(field, depth) field[:type][-1 - depth] == "[]" end |
#in_container?(field, depth) ⇒ Boolean
113 114 115 |
# File 'lib/net_shell/builtin_commands/build.rb', line 113 def in_container?(field, depth) in_array?(field, depth) or in_hash?(field, depth) end |
#in_hash?(field, depth) ⇒ Boolean
109 110 111 |
# File 'lib/net_shell/builtin_commands/build.rb', line 109 def in_hash?(field, depth) field[:type][-1 - depth] == "{}" end |
#json_output ⇒ Object
100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 100 def json_output set = params[:reverse] ? : .reverse set = (set.reverse[range_for_args(args)].map do |msg| if params[:raw] then msg[:message] else msg.reject { |k,v| k == :raw } end end) set = set[0] if set.length == 1 and not params[:array] set.to_json end |
#list ⇒ Object
List
96 97 98 99 100 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 96 def list(query) query = [ :class, :enumeration, :glossary, :protocol ] if query.empty? query.map! { |e| e.to_sym } end |
#list_all_commands ⇒ Object
16 17 18 |
# File 'lib/net_shell/builtin_commands/help.rb', line 16 def list_all_commands (categories.map { |cat| list_category(cat) }).join("\n\n") end |
#list_branches ⇒ Object
85 86 87 88 89 90 |
# File 'lib/net_shell/builtin_commands/talk.rb', line 85 def list_branches return [] unless repo_exists? branches = `cd #{repo} && git branch -a --no-color`.split("\n").map { |x| x.gsub(/^\*? */,"").gsub(/^.*-> /,"").gsub(/^(remotes\/)?origin\//,"") } branches &= branches # remove dupes branches.sort end |
#list_category(category) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/net_shell/builtin_commands/help.rb', line 30 def list_category(category) commands = @shell.built_ins.select { |name| @shell.built_in(name).category_text == category } cat = category.style(:category) cmds = (commands.sort.map do |name| cmd = @shell.built_in(name).new(@shell) usermark = cmd.user_defined? ? "@".style(:userdefined) : " " "#{sprintf("%25s", name.to_s).style(:command)}#{usermark} -- #{cmd.description}" end).join("\n") [cat, cmds].join("\n") end |
#list_command(name) ⇒ Object
20 21 22 23 24 |
# File 'lib/net_shell/builtin_commands/help.rb', line 20 def list_command(name) return show_error("#{name}: command not found") unless @shell.has_built_in?(name) cmd = @shell.built_in(name).new(@shell) cmd.educate end |
#list_commits ⇒ Object
76 77 78 79 80 81 82 83 |
# File 'lib/net_shell/builtin_commands/talk.rb', line 76 def list_commits return [] unless repo_exists? jeb = Jebediah.new `cd #{repo} && git log --pretty=format:"%an:%h:%s"`.split("\n").map do |commit| components = commit.split(":") { author:components[0], hash:components[1], jeb:jeb.process(components[1])[:result].join(" "), notes:components[2] } end end |
#list_fields(name) ⇒ Object
46 47 48 49 50 51 52 53 54 55 |
# File 'lib/net_shell/builtin_commands/references.rb', line 46 def list_fields(name) fields = [] talk.definition[:class].each do |cls| cls[:field].each do |field| fields.push({class:cls, field:field}) if talk.name_matches?(name, field[:type].first) end end fields end |
#list_methods(name) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/net_shell/builtin_commands/references.rb', line 35 def list_methods(name) methods = [] talk.definition[:protocol].each do |proto| proto[:method].each do |method| methods.push({protocol:proto, method:method}) if(talk.name_matches?(name, method[:request]) or talk.name_matches?(name, method[:response])) end end methods end |
#list_site(site_id, publications) ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 109 def list_site(site_id, publications) site = usherm.site_with_id(site_id) || {name:"Unknown site", siteDescription:"Not in usher"} lines = [] lines.push "Site #{site_id} -- #{site[:name]} (#{site[:siteDescription]})" publications[:orders].keys.sort.each do |app| next if params[:app] and not talk.name_matches?(app, params[:app]) lines.push list_site_app(app.to_s, publications[:orders][app]) end puts lines.join("\n")+"\n" unless lines.length == 1 end |
#list_site_app(app, orders) ⇒ Object
110 111 112 113 114 115 116 |
# File 'lib/net_shell/builtin_commands/site.rb', line 110 def list_site_app(app, orders) pub = orders.first return if params[:jeb] and pub[:buildInfo][:buildId] != params[:jeb] return if params[:commit] and pub[:buildInfo][:commitId] != params[:commit] return if params[:branch] and not(pub[:buildInfo][:branches].include? params[:branch]) puts "\t\t#{(pub[:publicationTime])} #{app.style(:class)} -- #{build_info(pub[:buildInfo])}" end |
#machine_list ⇒ Object
69 70 71 |
# File 'lib/net_shell/builtin_commands/kai_event.rb', line 69 def machine_list @shell.client(:config).machines rescue [] end |
#make_talk ⇒ Object
65 66 67 68 69 |
# File 'lib/net_shell/builtin_commands/talk.rb', line 65 def make_talk version = params[:talkversion] ? " _#{params[:talkversion]}_" : "" `cd #{repo} && maketalk#{version} --upgrade --json info > #{talk_json_path}` refresh_talk end |
#messages ⇒ Object
52 53 54 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 52 def = target_client.history end |
#method(message) ⇒ Object
151 152 153 154 155 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 151 def method() return [:method] if .has_key? :method request = find_request_with_id([:id]) request[:method] rescue "unknown" end |
#origin_line(method) ⇒ Object
132 133 134 135 |
# File 'lib/net_shell/builtin_commands/show.rb', line 132 def origin_line(method) return "Asynchronous from server\n\t\t".style(:origin) if method[:origin] == "server" return "" end |
#os_name ⇒ Object
26 27 28 |
# File 'lib/object_builder/definitions/connection_request.rb', line 26 def os_name `uname`.chomp end |
#os_version ⇒ Object
35 36 37 |
# File 'lib/object_builder/definitions/device_info_for_system.rb', line 35 def os_version RUBY_VERSION end |
#parse_params(args) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/net_shell/builtin_commands/ssh.rb', line 50 def parse_params(args) if args.length == 3 return { host:args[1], user:args[2] } else if args[1].include? "@" then comps = args[1].split("@") return { host:comps[1], user:comps[0] } else return { host:args[1], user:"acres4" } end end end |
#persist ⇒ Object
53 54 55 56 57 58 |
# File 'lib/net_shell/builtin_commands/jsoncache.rb', line 53 def persist builder = ObjectBuilder[args[1]] return show_error("#{args[1]}: no such identifier") if builder.nil? File.write(File.join(@shell.shelldir(:json), args[1]), builder.value.to_json) "" end |
#pick_toplevel(message) ⇒ Object
166 167 168 169 170 171 172 173 174 175 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 166 def pick_toplevel() = symbolify(JSON.parse()) if .is_a? String if [:jsonrpc] == "2.0" then return bypass(, "com.acres4.common.info.JSONRPCRequest") if .has_key? :params return [, "Error"] unless [:error].nil? return bypass(, "com.acres4.common.info.JSONRPCResponse") if .has_key? :result end [, talk.guess_class()] end |
#player_rating ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/net_shell/builtin_commands/kai_event.rb', line 122 def return nil unless params[:patron] or params[:firstName] or params[:lastName] or params[:loyaltyTierStr] { idPatron:params[:patron] || 0, firstName:params[:first_name] || "Little", lastName:params[:last_name] || "Timmy", loyaltyTierStr:params[:tier] || "Wood" } end |
#populate(field, path) ⇒ Object
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/net_shell/builtin_commands/build.rb', line 172 def populate(field, path) while true do idx = 0 builders = ObjectBuilder.builders_for_name(field[:type].first) builders.each do |builder| console_puts("#{idx.to_s.style(:constant_value)} #{builder.identifier.to_s.style(:method_name)}: #{builder.description}") idx += 1 end console_print prompt_for_path(path) action = STDIN.gets.chomp rescue nil return handle_complex(field, path) if action.nil? # CTRL+D cancels populate index = action.match(/^[0-9]+$/) ? action.to_i : nil return builders[index].value if not index.nil? and index < builders.length end end |
#prompt(basis = {}) ⇒ Object
244 245 |
# File 'lib/net_shell/builtin_commands/usher_site.rb', line 244 def prompt(basis={}) end |
#prompt_add ⇒ Object
233 234 |
# File 'lib/net_shell/builtin_commands/usher_site.rb', line 233 def prompt_add end |
#prompt_delete ⇒ Object
239 240 |
# File 'lib/net_shell/builtin_commands/usher_site.rb', line 239 def prompt_delete end |
#prompt_edit ⇒ Object
236 237 |
# File 'lib/net_shell/builtin_commands/usher_site.rb', line 236 def prompt_edit end |
#prompt_for_action(field, path, type, actions) ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/net_shell/builtin_commands/build.rb', line 117 def prompt_for_action(field, path, type, actions) while true do console_puts "#{path.join('.').style(:class)}: #{type.style(:field_datatype)}. #{actions.map { |a| "[#{a[0].bold}]#{a[1..-1]}" }.join(', ')}" console_print prompt_for_path(path) action = get_action(actions.map { |a| a[0] }) return (actions.select { |a| a[0] == action }).first unless action.nil? end end |
#prompt_for_apps(set) ⇒ Object
Publish
201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 201 def prompt_for_apps(set) apps = build_set_by_app(set) return apps.keys.sort.map { |app| apps[app].last } if params[:yes] selected = [] apps.keys.sort.each do |app| build = apps[app].last cls = sprintf("%s", app).style(:class) name = sprintf("%s", build[:buildId]).style(:build_name) branch = build[:branches].join(",").style(:branch) line = sprintf("%99s", "#{cls}: #{name} [#{branch}]") while true do print "#{line} [y/N]> " input = STDIN.gets.chomp.upcase rescue nil input = "N" if not input.nil? and input.empty? selected.push build if input == "Y" puts if input.nil? break if ["Y", "N"].include? input end end selected end |
#prompt_for_path(path) ⇒ Object
29 30 31 |
# File 'lib/net_shell/builtin_commands/build.rb', line 29 def prompt_for_path(path) path.join(".").style(:class) + ") " end |
#prompt_for_value(path, type) ⇒ Object
33 34 35 |
# File 'lib/net_shell/builtin_commands/build.rb', line 33 def prompt_for_value(path, type) "#{path.join(".").style(:class)} #{type.style(:field_datatype)}) " end |
#provider_line(id_provider) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/net_shell/builtin_commands/host.rb', line 60 def provider_line(id_provider) provider = usherm.provider(id_provider) return "Non-existent provider #{id_provider}" if provider.nil? return nil if provider[:isSpecial] sites = collapse_ranges(provider[:idSites]) ipLines = ["Internal", "External"].map do |zone| hosts = provider["usherHosts#{zone}".to_sym] || [] zone + ": " + if hosts.empty? then "None" else urls = hosts.map { |host| host[:url] } urls.join(", ") end end out = "\t\t#{provider[:product].style(:product)}: Site #{sites}\n" out += (ipLines.map { |line| "\t\t\t#{line}"}).join("\n") + "\n" out end |
#publish ⇒ Object
227 228 229 230 231 232 233 234 235 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 227 def publish sites = args[2..-1].map { |arg| arg.to_i } selected = prompt_for_apps(build_set) selected.each do |build| puts "Publishing #{build[:appId].style(:class)} \"#{build[:buildId].style(:build_name)}\" to site #{sites.join(",")}..." deployment.publish_build(build, sites) end "Done." end |
#qa_event_table_item(code, machine) ⇒ Object
91 92 93 94 95 96 |
# File 'lib/net_shell/builtin_commands/kai_event.rb', line 91 def qa_event_table_item(code, machine) { event:event_table_item(code), location:machine } end |
#query_for_params ⇒ Object
74 75 76 77 78 79 80 81 |
# File 'lib/net_shell/builtin_commands/show.rb', line 74 def query_for_params query = [] = [ :class, :enumeration, :glossary, :protocol ] .each { |opt| query.push(opt) if params[opt] } query = if query.empty? query end |
#random_machine ⇒ Object
73 74 75 |
# File 'lib/net_shell/builtin_commands/kai_event.rb', line 73 def random_machine machine_list.sample end |
#range_for_args(args) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 56 def range_for_args(args) case args.length when 0,1 range = (0 .. -1) when 2 range = args[1].to_i .. args[1].to_i when 3 low = [args[1], args[2]].min high = [args[1], args[2]].max range = low.to_i .. high.to_i end end |
#read ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/net_shell/builtin_commands/jsoncache.rb', line 60 def read if args.length == 1 then builders = ObjectBuilder.builders return show_error("no builders defined") if builders.empty? return show_builder_list(builders) end builder = ObjectBuilder[args[1]] return builder.value.to_json unless builder.nil? builders = ObjectBuilder.builders_for_name(args[1]) return "#{args[0]}: #{args[1]}: no such identifier or class in cache" if builders.empty? show_builder_list(builders) end |
#refresh_talk ⇒ Object
24 25 26 |
# File 'lib/a4tools.rb', line 24 def refresh_talk $talk = A4Tools::TalkConsumer.new(talk_file) end |
#render_client(key) ⇒ Object
18 19 20 21 22 23 24 25 |
# File 'lib/net_shell/builtin_commands/select.rb', line 18 def render_client(key) target = @shell.client(key) fmt_key = sprintf("%20s", key.to_s) host = usherm.host_for_url(target.uri) || "unknown host" info = source_id(target) "#{fmt_key.style(:target)}: #{info} #{target.uri.to_s.style(:url)} (#{host.style(:host)})" end |
#render_result(response) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/net_shell/builtin_commands/usher.rb', line 28 def render_result(response) return ("Unable to contact usher") if response.nil? return "Usher returned status #{response.code}" if response.code.to_i < 200 or response.code.to_i >= 300 begin payload = JSON.parse(response.body) return ("Usher returned non-JSON RPC response") unless payload["jsonrpc"] == "2.0" return ("Usher returned error: \"#{payload["error"]}\"") unless payload["error"].nil? return ("Usher did not include result") if payload["result"].nil? return ("Usher server returned non-usher response") unless payload["result"]["className"] == "com.acres4.common.info.usher.UsherResponse" return ("Usher response did not include body") if payload["result"]["body"].nil? return render_success(payload["result"]["body"]) rescue JSON::ParserError return ("Usher returned non-JSON response") end end |
#render_success(result) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/net_shell/builtin_commands/usher.rb', line 44 def render_success(result) s = " Site ID: #{result["siteID"]}\n" s += " Site name: #{result["siteName"]}\n" s += "Remote address: #{result["remoteAddr"]}\n\n" result["hosts"].each do |host| s += "Product: #{host["product"]} (#{host["host"]}:#{host["port"]})\n\t#{host["url"]}, #{host["ctx"]}, System #{host["systemId"]}\n\n" end s end |
#render_summary(message) ⇒ Object
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 126 def render_summary() toplevel, cls = pick_toplevel() puts toplevel if cls.nil? cls ||= talk.guess_class(toplevel) class_name = cls.style(:class) || "Unknown" id_str = [:id] ? sprintf("%3d", [:id]) : " " sprintf("%s %20s %s %s", id_str.style(:id), method().style(:method_name), class_name.style(:class), human_readable_size(.to_json.length) ) end |
#render_text(message) ⇒ Object
118 119 120 121 122 123 124 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 118 def render_text() if params[:summary] then render_summary() else .is_a?(Hash) ? JSON.generate() : end end |
#repo ⇒ Object
44 45 46 |
# File 'lib/net_shell/builtin_commands/talk.rb', line 44 def repo params[:repo] || @shell.shelldir("talk") end |
#repo_exists? ⇒ Boolean
52 53 54 |
# File 'lib/net_shell/builtin_commands/talk.rb', line 52 def repo_exists? File.exist?(File.join(repo, ".git")) end |
#repo_info(directory, repository = nil) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/object_builder/definitions/app_info_for_script.rb', line 37 def repo_info(directory, repository=nil) begin info = {} info[:repository] = repository || File.basename(directory) info[:sha1] = `cd "#{directory}"; git log --format="%H" -n1`.chomp info[:jeb] = Jebediah.new.process(info[:sha1])[:result].join(" ") info[:timestamp] = `cd "#{directory}"; git log --format="%at" -n1`.chomp.to_i info[:author] = `cd "#{directory}"; git log --format="%an" -n1`.chomp info[:notes] = `cd "#{directory}"; git log --format="%s" -n1`.chomp info[:branches] = (`cd "#{directory}"; git branch --contains #{info[:sha1]}`.split("\n").map do |line| line.length > 0 ? line.gsub(/^[\s*]*/, "").gsub(/\s*$/, "") : nil end).compact return info rescue return nil end end |
#request_caches ⇒ Object
67 68 69 70 71 |
# File 'lib/net_shell/builtin_commands/connect.rb', line 67 def request_caches version = @shell.client(:config).site_version client_interfaces.keys.each { |key| @shell.client(key).version = version } @shell.client(:config).machines end |
#send(message) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/net_shell/builtin_commands/send.rb', line 68 def send() if params[:dry] then puts else client.() end end |
#send_event(message) ⇒ Object
77 78 79 80 81 |
# File 'lib/net_shell/builtin_commands/kai_event.rb', line 77 def send_event() qa.inject_token() jsonrpc = qa.(:qaTestEvent, "qatest", nil, ) qa.(jsonrpc).body end |
#send_raw(message) ⇒ Object
50 51 52 |
# File 'lib/net_shell/builtin_commands/send.rb', line 50 def send_raw() send() end |
#send_wrapped(message) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/net_shell/builtin_commands/send.rb', line 54 def send_wrapped() = symbolify(JSON.parse()) if .is_a? String method, protocol = talk.method_named(args[2]) return show_error("#{args[1]}: unknown method") if method.nil? cls = talk.class_named(method[:request]) return show_error("#{args[1]}: unable to locate request class") if cls.nil? client.inject_token() unless params[:no_inject] jsonrpc = client.(method[:name], args[1], talk.guess_class(), ) = JSON.generate(jsonrpc) send() end |
#sender(msg) ⇒ Object
69 70 71 72 73 74 75 76 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 69 def sender(msg) case msg[:sender] when :client "client".light_blue when :server "server".magenta end end |
#serial_number ⇒ Object
17 18 19 20 |
# File 'lib/object_builder/definitions/connection_request.rb', line 17 def serial_number return $config[:serial] unless $config.nil? or $config[:serial].nil? "1234" end |
#show(query) ⇒ Object
180 181 182 |
# File 'lib/net_shell/builtin_commands/show.rb', line 180 def show(query) show_field(query) || show_method(query) || show_class(query) || show_protocol(query) || show_constant(query) || show_glossary(query) || show_enumeration(query) end |
#show_all_sites ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/net_shell/builtin_commands/site.rb', line 42 def show_all_sites sites = (usherm[:usherSystemId][:usherSites].map { |site| site[:idSite] }).sort sites.each do |site_id| site = usherm.site_with_id(site_id) site_id_str = sprintf("%6d", site_id).style(:id) puts "##{site_id_str}: #{site[:name]} (#{site[:siteDescription]})" end end |
#show_app(app, builds) ⇒ Object
Other stuff
239 240 241 242 243 244 245 246 247 248 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 239 def show_app(app, limit=50) list = deployment.index_list_by_app[app] return show_error("#{app}: No such app in deployment server") if list.nil? list.each do |build| puts show_build(build) end "" end |
#show_build_set(set) ⇒ Object
277 278 279 280 |
# File 'lib/net_shell/builtin_commands/deploy.rb', line 277 def show_build_set(set) apps = build_set_by_app(set) apps.keys.sort.each { |app| show_app(app, apps[app]) } end |
#show_builder_list(builders) ⇒ Object
75 76 77 78 79 |
# File 'lib/net_shell/builtin_commands/jsoncache.rb', line 75 def show_builder_list(builders) (builders.map do |builder| "#{builder.name.to_s.style(:class)} #{builder.identifier.to_s.green}: #{builder.description}" end).join("\n") end |
#show_class(query) ⇒ Object
120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/net_shell/builtin_commands/show.rb', line 120 def show_class(query) cls = (query[0].is_a? Hash) ? query[0] : talk.class_named(query[0]) return nil if cls.nil? fields = cls[:field].map do |f| add_queries(f[:type].first) "\t#{f[:name].style(:field_name)}, #{(f[:type].map { |t| talk.truncated_name t }).join('').style(:field_datatype)}\n\t\t#{f[:description]}\n" end "Class #{cls[:name].style(:class)}\n\t#{cls[:description]}\n\n" + fields.join("\n") end |
#show_constant(query) ⇒ Object
157 158 159 160 161 162 163 164 |
# File 'lib/net_shell/builtin_commands/show.rb', line 157 def show_constant(query) constant, container = (query.length > 1) ? talk.constant_named(query[1], query[0]) : talk.constant_named(query[0], nil) return nil if constant.nil? origin = (container.has_key? :term) ? "Glossary #{container[:name]}" : "Enumeration #{container[:name]}" "Constant #{constant[:name].style(:constant_name)}: #{constant[:value].to_s.style(:constant_value)}\n\t#{origin}\n\t#{constant[:description]}\n\n" end |
#show_enumeration(query) ⇒ Object
173 174 175 176 177 178 |
# File 'lib/net_shell/builtin_commands/show.rb', line 173 def show_enumeration(query) enumeration = (query[0].is_a? Hash) ? query[0] : talk.enumeration_named(query[0]) return nil if enumeration.nil? "Enumeration #{enumeration[:name].style(:collection_name)}\n\t#{enumeration[:description]}\n\n" + (enumeration[:constant].map { |c| "\t#{c[:value].to_i.to_s.style(:constant_value)} #{c[:name].style(:constant_name)}\n\t\t#{c[:description]}\n"}).join("\n") end |
#show_field(cls, field) ⇒ Object
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/net_shell/builtin_commands/show.rb', line 108 def show_field(query) return nil if query.length < 2 cls = (query[0].is_a? Hash) ? query[0] : talk.class_named(query[0]) return nil if cls.nil? field = talk.field_named(cls, query[1]) return nil if field.nil? add_queries(field[:type].first) "Field #{field[:name]}: #{(field[:type].map { |t| talk.truncated_name t }).join('')}\n\tClass #{cls[:name]}\n\t#{field[:description]}\n" end |
#show_field_help(field, depth = -1)) ⇒ Object
130 131 132 133 |
# File 'lib/net_shell/builtin_commands/build.rb', line 130 def show_field_help(field, depth=-1) depth = field[:type].length - 1 if depth < 0 console_puts "#{talk.truncated_name(type_at_depth(field, depth)).style(:field_datatype)} #{field[:name].style(:field_name)}\n\t#{field[:description]}" end |
#show_glossary(query) ⇒ Object
166 167 168 169 170 171 |
# File 'lib/net_shell/builtin_commands/show.rb', line 166 def show_glossary(query) glossary = (query[0].is_a? Hash) ? query[0] : talk.glossary_named(query[0]) return nil if glossary.nil? "Glossary #{glossary[:name].style(:collection_name)}\n\t#{glossary[:description]}\n\n" + (glossary[:term].map { |t| "\t#{t[:name].style(:constant_name)} (\"#{t[:value].style(:constant_value)}\")\n\t\t#{t[:description]}\n"}).join("\n") end |
#show_host_info(site_id) ⇒ Object
93 94 95 96 97 98 99 100 |
# File 'lib/net_shell/builtin_commands/site.rb', line 93 def show_host_info(site_id) puts "\tHosts".style(:heading) usherm.providers_for_site(site_id).each do |provider| host = usherm.host_with_id(provider[:idSystemHost]) product = sprintf("%20s", provider[:product]).style(:product) puts "\t\t#{product}: #{host[:hostName].style(:host)}" end end |
#show_list ⇒ Object
64 65 66 67 68 69 70 71 72 |
# File 'lib/net_shell/builtin_commands/show.rb', line 64 def show_list s = "" query_for_params.each do |section| next if talk.definition[section].nil? s += descriptions[section] + " (#{talk.definition[section].length})\n" s += (talk.definition[section].map { |item| "\t#{item[:name].style(style_for_section(section))}\n\t#{item[:description]}\n" }).join("\n") + "\n\n" end s end |
#show_method(protocol, method) ⇒ Object
149 150 151 152 153 154 155 |
# File 'lib/net_shell/builtin_commands/show.rb', line 149 def show_method(query) method, protocol = (query.length == 1) ? talk.method_named(query[0], nil) : talk.method_named(query[1], query[0]) return nil if method.nil? add_queries(method[:request], method[:response]) "Method #{method[:name].style(:method_name)}: #{method[:request].style(:class)} -> #{method[:response].style(:class)}\n\tProtocol #{protocol[:name].style(:protocol_name)}\n\t#{method[:description]}\n\n" end |
#show_protocol(query) ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/net_shell/builtin_commands/show.rb', line 137 def show_protocol(query) proto = (query[0].is_a? Hash) ? query[0] : talk.protocol_named(query[0]) return nil if proto.nil? methods = proto[:method].map do |m| add_queries(m[:request], m[:response]) "\t#{m[:name].style(:method_name)}: #{m[:request].style(:class)} -> #{m[:response].style(:class)}\n\t\t#{origin_line(m)}#{m[:description]}\n" end "Protocol #{proto[:name].style(:protocol_name)}\n\t#{proto[:description]}\n" + methods.join("\n") end |
#show_publications(publications) ⇒ Object
102 103 104 105 106 107 108 |
# File 'lib/net_shell/builtin_commands/site.rb', line 102 def show_publications(publications) puts "\tDeployments".style(:heading) publications[:orders].keys.sort.each do |app| next if params[:app] and not talk.name_matches?(app, params[:app]) list_site_app(app.to_s, publications[:orders][app]) end end |
#show_site(site_id) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/net_shell/builtin_commands/site.rb', line 51 def show_site(site_id) site = usherm.site_with_id(site_id) show_usher_site(site_id, site) show_host_info(site_id) show_publications(deployment.query(:buildPublicationList,site_id)) unless params[:no_deploy] end |
#show_usher_site(site_id, site) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/net_shell/builtin_commands/site.rb', line 70 def show_usher_site(site_id, site) if site.nil? puts "Site #{site_id.to_s.style(:id)}: Unknown (not in usher)" return end puts "Site".style(:heading) +" #{site[:idSite].to_s.style(:id)}: #{site[:name]} (#{site[:siteDescription]})" puts "\t Timezone: #{site[:zoneinfoId].style(:timezone)}" mod = site[:moduleProvision] if mod then mask = sprintf("%16x", mod[:modules]).style(:mask) puts "\t Modules: #{mask}" puts "\t Max machines: #{mod[:maxAllowedMachines]}" puts "\t Active: #{yes_no(mod[:active])}" puts "\tPermanent license: #{yes_no(mod[:permanent])}" puts "\t Expiration: #{expiration(mod)}" puts "\t Renewal attempts: #{mod[:renewalAttemtps]}" end site[:siteRange].each do |range| puts "\t CIDR: #{range[:cidrBlock].style(:cidr)} #{range[:siteRangeDescription]}" end end |
#site_id_for_arg(arg) ⇒ Object
36 37 38 39 40 |
# File 'lib/net_shell/builtin_commands/site.rb', line 36 def site_id_for_arg(arg) return arg.to_i if arg.is_a? Fixnum or arg.match(/^[0-9]+$/) usherm[:usherSystemId][:usherSites].each { |site| return site[:idSite] if site[:name] == arg } nil end |
#source_id(target) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/net_shell/builtin_commands/select.rb', line 27 def source_id(target) app_info = target.server_info || {} version = target.version || app_info[:currentTalkVersion] protocol = sprintf("%-6s", (version || "")).style(:protocol_name) name = sprintf("%20s", ((app_info[:appName] rescue nil) || "")).style(:name) commit = sprintf("%7s", ((app_info[:sourceRevision][0..6] rescue nil) || "")).style(:commit) branch = sprintf("%-30s", ((app_info[:supportingRevisions].first[:branches].first rescue nil) || "")).style(:branch) "#{protocol} #{commit} #{branch}" end |
#store ⇒ Object
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/net_shell/builtin_commands/jsoncache.rb', line 42 def store description = args[1] rescue "Defined from console" obj, type = acquire_object return show_error("Unable to acquire field from JSON") if obj.nil? obj[:__class] = type unless type.nil? ObjectBuilder.load_object(obj, params[:store], description) "" end |
#string_for_range(start, last, params = {}) ⇒ Object
32 33 34 35 36 37 38 |
# File 'lib/net_shell/builtin_commands/host.rb', line 32 def string_for_range(start, last, params={}) if start == last then last else "#{start}-#{last}" end end |
#style_for_section(section) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/net_shell/builtin_commands/show.rb', line 83 def style_for_section(section) case section when :class :class when :protocol :protocol_name when :enumeration, :glossary :collection_name else :none end end |
#symbolify(item) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/a4tools.rb', line 8 def symbolify(item) if item.is_a? Array return item.map! { |value| symbolify value } elsif not item.is_a? Hash return item end new_hash = {} item.each { |key, value| new_hash[key.to_sym] = symbolify value } new_hash end |
#talk ⇒ Object
20 21 22 |
# File 'lib/a4tools.rb', line 20 def talk $talk ||= A4Tools::TalkConsumer.new(talk_file) end |
#talk_file ⇒ Object
28 29 30 31 |
# File 'lib/a4tools.rb', line 28 def talk_file return $localtalk if not $localtalk.nil? and File.exists?($localtalk) A4Tools::TalkConsumer.new(File.join(File.dirname(__FILE__), "talk.json")) end |
#talk_json_path ⇒ Object
48 49 50 |
# File 'lib/net_shell/builtin_commands/talk.rb', line 48 def talk_json_path $localtalk end |
#target_client ⇒ Object
48 49 50 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 48 def target_client params[:client] ? @shell.client(params[:client]) : client end |
#text_output ⇒ Object
90 91 92 93 94 95 96 97 98 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 90 def text_output index = -1 set = params[:reverse] ? : .reverse (set.reverse[range_for_args(args)].map do |msg| index += 1 index_str = sprintf("%3d", index) "#{index_str} #{timecode(msg)} #{sender(msg)} #{render_text(msg[:message])}" end).join("\n") end |
#timecode(msg) ⇒ Object
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 78 def timecode(msg) delta = msg[:time] - target_client.start_time all_seconds = delta.to_i milliseconds = 1000.0*(delta - all_seconds) hours = (all_seconds / 3660).to_i minutes = ((all_seconds - 3660*hours) / 60).to_i seconds = (all_seconds - 3600*hours - 60*minutes).to_i return sprintf("%3d:%02d:%02d.%03d", hours, minutes, seconds, milliseconds).light_black end |
#timestamp(ts) ⇒ Object
62 63 64 |
# File 'lib/net_shell/builtin_commands/site.rb', line 62 def (ts) DateTime.strptime(ts.to_s,'%s').strftime("%Y-%m-%d %H:%M:%S").style(:timestamp) end |
#toplevel_value ⇒ Object
76 77 78 79 80 81 82 83 84 |
# File 'lib/net_shell/builtin_commands/excerpt.rb', line 76 def toplevel_value json = @input.read_all object = symbolify(JSON.parse(json)) rescue nil type = (talk.(params[:type]) rescue nil) || talk.guess_class(object) rescue nil return nil if type.nil? or object.nil? return [object, type] if params[:no_bypass] return bypass(object, type) end |
#translate(value) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/net_shell/builtin_commands/translate.rb', line 27 def translate(value) is_numeric = (not(value.is_a?(String)) or value.match(/^[-+]?[0-9]+(.[0-9]+)?$/) != nil) candidates = case is_numeric when true talk.definition[:enumeration].inject([]) do |c, enum| c + (enum[:constant].select { |constant| constant[:value] == value.to_f }).map { |x| { collection:enum, constant:x } } end when false talk.definition[:glossary].inject([]) do |c, glossary| c + (glossary[:term].select { |term| term[:value] == value }).map { |x| { collection:glossary, constant:x } } end end return "No matches for #{value}" if candidates.empty? (candidates.map { |item| "#{item[:constant][:name].style(:constant_name)} (#{talk.truncated_name item[:collection][:name].style(:collection_name)}): #{item[:constant][:description]}" }).join("\n") end |
#try_acl(params, acl) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/net_shell/builtin_commands/ssh.rb', line 29 def try_acl(params, acl) host = usherm.host_named(params[:host]) service = usherm.service_for_id(acl[:idService]) = [ { host:host[:ipAddrInt], port:service[:port] }, { host:host[:ipAddrExt], port:acl[:port] } ] result = () unless result.nil? then process = fork { exec "ssh -l #{params[:user]} -p #{result[:port]} #{result[:ip]}" } Process.waitpid(process) end not result.nil? end |
#try_connection(hostname, port) ⇒ Object
37 38 39 40 |
# File 'lib/a4tools.rb', line 37 def try_connection(hostname, port) s = TCPSocket.new(hostname, port) rescue false s != false end |
#try_connection_options(options, timeout = 2) ⇒ Object
array of { :host, :port }
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/a4tools.rb', line 43 def (, timeout=2) mutex = Mutex.new condition = ConditionVariable.new result = nil mutex.synchronize do .each do |opt| Thread.new do if try_connection(opt[:host], opt[:port]) then result = opt mutex.synchronize { condition.signal } end end end condition.wait(mutex, timeout) end result end |
#type_at_depth(field, depth) ⇒ Object
126 127 128 |
# File 'lib/net_shell/builtin_commands/build.rb', line 126 def type_at_depth(field, depth) field[:type][0 .. -1 - depth].join("") end |
#use_json? ⇒ Boolean
114 115 116 |
# File 'lib/net_shell/builtin_commands/recap.rb', line 114 def use_json? params[:json] or params[:raw] or params[:array] end |
#verbose_host(host) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/net_shell/builtin_commands/host.rb', line 91 def verbose_host(host) datacenter = usherm.datacenter(host[:idDataCenter]) out = "Host #{host[:hostName].style(:host)} (#{host[:idSystemHost]})\n" out += "\tInternal #{host[:ipAddrInt].style(:ip)}\n" out += "\tExternal #{host[:ipAddrExt].style(:ip)}\n" if datacenter.nil? out += "\tDatacenter: not found in usher (#{host[:idDataCenter]})\n" else out += "\tDatacenter: #{datacenter[:dataCenterName].style(:datacenter)} (#{host[:idDataCenter]})\n" end out += "\tHost environment: #{usherm.env_type(host[:systemHostEnvironment])}\n" out += "\tUsher system type: #{usherm.system_type(host[:usherResponseType])}\n" out += (host[:providers].map { |id_provider| provider_line(id_provider) }).compact.join("\n") out += "\tACLs:\n" acls = usherm.acls_for_host_id(host[:idSystemHost]) if acls.empty? out += "\t\tNo ACLs for this host." else out += (acls.map { |acl| acl_line(acl) }).compact.join("\n") end out end |
#yes_no(b) ⇒ Object
58 59 60 |
# File 'lib/net_shell/builtin_commands/site.rb', line 58 def yes_no(b) b ? "yes" : "no" end |