Class | Stella::Command::Base |
In: |
lib/stella/command/base.rb
|
Parent: | Object |
BrowserNicks | = | { 'ff' => 'firefox', 'ie' => 'internetexplorer' | ||
OperatingSystemNicks | = | { 'win' => 'windows', 'lin' => 'linux', 'osx' => 'osx', 'freebsd' => 'bsd', 'netbsd' => 'bsd', 'openbsd' => 'bsd' | ||
IMPLEMENTATIONS | = | [ [/darwin/i, :unix, :macosx ] | TODO: See EC2::Platform for example to improve/generalize platform discovery. We‘ll need this for monitoring. | |
ARCHITECTURES | = | [ [/(i\d86)/i, :i386 ] |
shortname | [RW] | When using Stella::CLI this will contain the string used to call this command i.e. ab, siege, help, etc… |
# File lib/stella/command/base.rb, line 34 34: def initialize() 35: 36: #agent = find_agent(*expand_str(v)) 37: #@logger.info(:cli_print_agent, agent) if @options.verbose >= 1 38: 39: end
Takes an input string which can be either a shortname or a complete user agent string. If the string matches the shortname format, it will select an agent string from useragents.txt based on the shortname. Shortname takes the following format: browser-version-os. Examples: ff-3-linux, ie-5, opera-10-win, chrome-0.2-osx, random If os doesn‘t match, it will look for the browser and version. If it can‘t find the version it will look for the browser and apply the version given. If browser doesn‘t match a known browser, it assumes the string is a complete user agent and simply returns that value.
# File lib/stella/command/base.rb, line 61 61: def find_agent(name,second=nil,third=nil) 62: name = (BrowserNicks.has_key?(name)) ? BrowserNicks[name] : name 63: return name unless @available_agents.has_key?(name) || name == "random" 64: 65: index = name 66: if (second && third) # i.e. opera-9-osx 67: os = (OperatingSystemNicks.has_key?(third)) ? OperatingSystemNicks[third] : third 68: index = "#{name}-#{second}-#{os}" 69: elsif(second && second.to_i > 0) # i.e. opera-9 70: index = "#{name}-#{second}" 71: elsif(second) # i.e. opera-osx 72: os = (OperatingSystemNicks.has_key?(second)) ? OperatingSystemNicks[second] : second 73: index = "#{name}-#{os}" 74: elsif(name == "random") 75: index = @available_agents.keys[ rand(@available_agents.keys.size) ] 76: end 77: 78: # Attempt to find a pool of user agents that match the supplied index 79: ua_pool = @available_agents[index] 80: 81: # In the event we don't find an agent above (which will only happen 82: # when the user provided a version), we'll take a random agent for 83: # the same browser and apply the version supplied by the user. We 84: # create the index using just the major version number so if the user 85: # supplies a specific verswion number, they will always end up here. 86: unless ua_pool 87: os = (OperatingSystemNicks.has_key?(third)) ? OperatingSystemNicks[third] : third 88: index = (os) ? "#{name}-#{os}" : name 89: ua_tmp = @available_agents[index][ rand(@available_agents[index].size) ] 90: ua_tmp.version = second if second.to_i > 0 91: ua_pool = [ua_tmp] 92: end 93: 94: ua = ua_pool[ rand(ua_pool.size) ] 95: 96: ua.to_s 97: 98: end
# File lib/stella/command/base.rb, line 41 41: def run_sleeper(duration) 42: remainder = duration % 1 43: duration.to_i.times { 44: Stella::LOGGER.info_print('.') 45: sleep 1 46: } 47: sleep remainder if remainder > 0 48: end
Generates a string of random alphanumeric characters These are used as IDs throughout the system
# File lib/stella/command/base.rb, line 104 104: def strand( len ) 105: chars = ("a".."z").to_a + ("0".."9").to_a 106: newpass = "" 107: 1.upto(len) { |i| newpass << chars[rand(chars.size-1)] } 108: return newpass 109: end