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.24.15"
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

Class Method Details

.after_initializeObject



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
# File 'lib/six-updater-web/config/six-updater-web.rb', line 244

def after_initialize
  if defined?(OLDLOCATION && SPECIAL)
    # Open the browser
    return unless defined?(OPEN_BROWSER)
    case RUBY_PLATFORM
      when /-mingw32$/, /-mswin32$/
        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
    end
  end
end

.initialize(config) ⇒ Object



231
232
233
234
235
# File 'lib/six-updater-web/config/six-updater-web.rb', line 231

def initialize(config)
  if defined?(OLDLOCATION)
    config.log_path = File.join(DATA_PATH, 'logs', 'six-updater-web.log')
  end
end

.loggerObject



222
223
224
# File 'lib/six-updater-web/config/six-updater-web.rb', line 222

def logger
  ActiveRecord::Base.logger
end

.mirror_priorityObject



213
214
215
216
217
218
219
220
# File 'lib/six-updater-web/config/six-updater-web.rb', line 213

def mirror_priority
  puts "Checking mirror latencies, please be patient..."
  repos = Repository.rank(true)
  puts
  repos.each do |rep|
    puts "#{rep.priority} - #{rep.ping_value} - #{rep.url}"
  end
end

.prepare_data_pathObject



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


237
238
239
240
241
242
# File 'lib/six-updater-web/config/six-updater-web.rb', line 237

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



320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
# File 'lib/six-updater-web/config/six-updater-web.rb', line 320

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



226
227
228
229
# File 'lib/six-updater-web/config/six-updater-web.rb', line 226

def stamp(time)
  (Time.now - time).to_s[/(.*\..?.?.?)/]
  $1
end

.update_gamespy(nogeo = nil) ⇒ Object



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
209
210
211
# File 'lib/six-updater-web/config/six-updater-web.rb', line 139

def update_gamespy(nogeo = nil)
  puts "Fetching server info..."
  geo = ENV['NOGEO'] || nogeo ? "" : nil
  #geo = ""
  types = ENV['GAMESPY_TYPES'].split(",")
  puts "Pings and Countries: #{geo.nil?}"
  puts ""

  ids = []
  types.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

.update_site_controllersObject



271
272
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
311
312
313
314
315
316
317
318
# File 'lib/six-updater-web/config/six-updater-web.rb', line 271

def update_site_controllers
  from_classes = Goldberg::SiteController.classes
  from_db = Goldberg::SiteController.find(:all,
                                :order => 'name')
  known = Hash.new
  missing = Array.new
  for dbc in from_db do
    if from_classes.has_key? dbc.name
      known[dbc.name] = dbc
    else
      missing << dbc
    end
  end

  unknown = Hash.new
  app = Array.new
  builtin = Array.new

  for name in from_classes.keys.sort do
    if known.has_key? name
      if known[name].builtin == 1
        builtin << known[name]
      else
        app << known[name]
      end
    else
      unknown[name] = from_classes[name]
    end
  end

  saved = false
  logger.info "Unknown: #{unknown.inspect}"
  unknown.keys.each do |name|
    h = Hash.new
    h[:name] = name
    h[:permission_id] = 1 # TODO: Search for it instead?
    h[:builtin] = 0    
    site_controller = Goldberg::SiteController.new(h)
    if site_controller.save
      #flash[:notice] = 'SiteController was successfully created.'
      saved = true
    else
      #foreign
      #render :action => 'new'
    end
  end
  Goldberg::Role.rebuild_cache if saved
end