Module: SixUpdaterWeb
- Defined in:
- lib/six-updater-web/init.rb,
lib/six-updater-web/common.rb,
lib/six-updater-web/config/six-updater-web.rb
Overview
$stdout, $stderr = # File or String in Memory (any cleanup measures?) require ‘RubyGems’
Constant Summary collapse
- DEFAULT_PORT =
3000
- DEFAULT_IP =
"127.0.0.1"
- OPEN_BROWSER =
Automatically open the browser unless NO_BROWSER specified ARGV.include?(“NO_BROWSER=1”) ? ARGV -= [“NO_BROWSER=1”] : OPEN_BROWSER = true
true
- SIX_HOST =
DEFAULT_IP
- SIX_PORT =
DEFAULT_PORT
- OLDLOCATION =
if defined?(TAR2RUBYSCRIPT) oldlocation else ENV['BASE_PATH'] ? ENV['BASE_PATH'] : Dir.pwd end
- SPECIAL =
unless ENV
ENV['BASE_PATH'] = OLDLOCATION end
true
- SIX_ADMIN =
true
- VERSION =
"0.21.5"
- COMPONENT =
"six-updater-web"
- LOCAL_URL =
"http://#{SIX_HOST == "0.0.0.0" ? DEFAULT_IP : SIX_HOST}:#{SIX_PORT}"
- BASE_PATH =
bpath
- TOOL_PATH =
File.join(BASE_PATH, 'tools')
- DATA_PATH =
COMPONENT)
File.join(File.exists?(File.join(BASE_PATH, "legacy.txt")) ? BASE_PATH : HOME_PATH, "six-updater")
- PID_FILE =
File.join(DATA_PATH, "#{COMPONENT}.pid")
Class Method Summary collapse
- .after_initialize ⇒ Object
- .initialize(config) ⇒ Object
- .logger ⇒ Object
- .prepare_data_path ⇒ Object
- .print_info ⇒ Object
- .run_program(exec, startpath, cl) ⇒ Object
- .stamp(time) ⇒ Object
- .update_gamespy ⇒ Object
Class Method Details
.after_initialize ⇒ Object
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 |
# File 'lib/six-updater-web/config/six-updater-web.rb', line 232 def after_initialize if defined?(OLDLOCATION && SPECIAL) # Update data in tables; nah, rather start warning users on main page? #Six::Dbmanager.check case RUBY_PLATFORM when /-mingw32$/, /-mswin32$/ return unless defined?(OPEN_BROWSER) Thread.new() do file_to_use = "#{LOCAL_URL}/main" sleep 3 iron = File.join(BASE_PATH, "tools", "IronPortable", "IronPortable.exe") chrome = File.join(BASE_PATH, "tools", "GoogleChromePortable", "GoogleChromePortable.exe") if File.exists?(iron) Dir.chdir(File.dirname(iron)) do system "cmd /c \"#{iron}\" --app=#{file_to_use}" end elsif File.exists?(chrome) Dir.chdir(File.dirname(chrome)) do system "cmd /c \"#{chrome}\" --app=#{file_to_use}" end else system "start #{file_to_use}" end end =begin arguments = nil directory = nil operation = "OPEN" show = nil #begin shell = WIN32OLE.new('Shell.Application') shell.ShellExecute(file_to_use, arguments, directory, operation, show) #rescue => e #logger.warn "Unable to open browser: ERROR: #{e.class} #{e.message} #{e.backtrace.join("\n")}" #end =end end end end |
.initialize(config) ⇒ Object
219 220 221 222 223 |
# File 'lib/six-updater-web/config/six-updater-web.rb', line 219 def initialize(config) if defined?(OLDLOCATION) config.log_path = File.join(DATA_PATH, 'logs', 'six-updater-web.log') end end |
.logger ⇒ Object
210 211 212 |
# File 'lib/six-updater-web/config/six-updater-web.rb', line 210 def logger ActiveRecord::Base.logger end |
.prepare_data_path ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/six-updater-web/init.rb', line 36 def prepare_data_path # Arrange appdata! lf = File.join(DATA_PATH, "logs") FileUtils.mkdir_p(lf) unless File.directory?(lf) df = File.join(DATA_PATH, "db") FileUtils.mkdir_p(df) unless File.directory?(df) db = File.join(DATA_PATH, "db", "production.sqlite3") unless File.exists?(db) puts "Database Missing, creating and loading default schema and system data..." File.open(db, 'w') {|f| } Dir.chdir(File.dirname(__FILE__)) do system "ruby -rubygems \"_rake.rb\" db:migrate goldberg:migrate db:schema:dump sync:system" end #FileUtils.cp(File.join(BASE_PATH, "db", "production.sqlite3"), db) return true end false end |
.print_info ⇒ Object
225 226 227 228 229 230 |
# File 'lib/six-updater-web/config/six-updater-web.rb', line 225 def print_info puts "Six Updater Web (GUI) #{VERSION}, by Sickboy" puts "BASE: #{BASE_PATH}" puts "DATA: #{DATA_PATH}" puts "ARMA: #{DISTRO} PATH: #{ARMA_PATH}" end |
.run_program(exec, startpath, cl) ⇒ Object
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 |
# File 'lib/six-updater-web/config/six-updater-web.rb', line 273 def run_program(exec, startpath, cl) logger.info "Current Path: #{Dir.pwd}, BASE_PATH: #{BASE_PATH}, DATA_PATH: #{DATA_PATH}" logger.info "Starting with #{cl} from #{startpath}" # TODO: Cleanup startpath = "#{startpath}" begin case RUBY_PLATFORM when /-mingw32$/, /-mswin32$/ cl = "\"#{exec}\" #{cl}" cl = "/C #{cl}" logger.info "#{CMD_EXE} #{cl}" struct = Process.create( :app_name => CMD_EXE, :command_line => cl, :creation_flags => Process::DETACHED_PROCESS, :process_inherit => false, :thread_inherit => false, :cwd => startpath, :inherit => false #:environment => "" ) else Dir.chdir(startpath) do # TODO: Properly create seperate process like on windows.. or maybe this is fine just needs 2>&1 >> /dev/null ? # as logfiles deliver the feedback, or rather run integrated. However maybe when running in a desktop environment # maybe it's useful to open a new terminal window/tab .. p = Process.fork do logger.info "#{exec} #{cl}" system "#{exec} #{cl}" end end #logger.info "Unimplemented on current platform: #{RUBY_PLATFORM}" end rescue => e logger.info "WARNING: Something went wrong starting the app" logger.info "#{e.class}: #{e.message} #{e.backtrace.join("\n")}" end end |
.stamp(time) ⇒ Object
214 215 216 217 |
# File 'lib/six-updater-web/config/six-updater-web.rb', line 214 def stamp(time) (Time.now - time).to_s[/(.*\..?.?.?)/] $1 end |
.update_gamespy ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 |
# File 'lib/six-updater-web/config/six-updater-web.rb', line 137 def update_gamespy puts "Fetching server info..." geo = ENV['NOGEO'] ? "" : nil #geo = "" puts "Pings and Countries: #{geo.nil?}" puts "" ids = [] ["arma2oapc", "arma2pc"].each do |game| q = Six::Query::GamespyMaster.new(geo, game) h = q.process puts "" puts "Received #{h.size} servers" puts "" puts "Updating database..." i, saved = 0, 0 #hasj = Hash.new timestart = Time.now h.each_pair do |key, e| i += 1 time = Time.now r = Queryserver.import(e) next unless r if r[0].changed? #hasj[r[0].id] = r[1] saved += 1 r[0].save else ids << r[0].id end print "#{i} / #{h.keys.size}, took #{SixUpdaterWeb::stamp(time)}s\r" end puts "Saved: #{saved}, Unchanged: #{h.keys.size - saved}. Took: #{SixUpdaterWeb::stamp(timestart)}s" end =begin timestart = Time.now puts "Updating #{hasj.keys.size} records..." begin Queryserver.update(hasj.keys, hasj.values) unless hasj.keys.empty? rescue => e puts "#{e.class}: #{e.message} #{e.backtrace.join("\n")}" sleep 3 ensure puts "Took: #{SixUpdaterWeb::stamp(timestart)}s" end =end timestart = Time.now puts "Tagging... #{ids.size} records" begin Queryserver.update_all("updated_at = '#{Time.now}'", ["id in (?)",ids]) unless ids.empty? rescue => e puts "#{e.class}: #{e.message} #{e.backtrace.join("\n")}" ensure puts "Took: #{SixUpdaterWeb::stamp(timestart)}s" end puts "Pruning database..." timestart = Time.now Queryserver.prune puts "Took: #{SixUpdaterWeb::stamp(timestart)}s" puts "Cleaning database..." timestart = Time.now Queryserver.clean puts "Took: #{SixUpdaterWeb::stamp(timestart)}s" puts "" puts "Done!" end |