#1 automatically choose browser/profile

Open
gwen wants to merge 1 commits from gwen/master into mai/master
1 changed files with 14 additions and 11 deletions
  1. 14 11
      dcss-watch.py

+ 14 - 11
dcss-watch.py

@@ -7,26 +7,19 @@ import time
 from datetime import datetime
 import code
 import random
-from os import path
+from os import path, environ
 from selenium import webdriver
 from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
 from selenium.webdriver.common.keys import Keys
+from glob import glob
 
 
-if path.isfile('/usr/bin/icecat'):
-    ff_bin_location = '/usr/bin/icecat'
-elif path.isfile('/usr/bin/iceweasel'):
-    ff_bin_location = '/usr/bin/iceweasel'
-elif path.isfile('/usr/bin/firefox'):
-    ff_bin_location = '/usr/bin/firefox'
-
-
-ff_profile_location = '/home/main/.mozilla/icecat/vtz6h9c6.selenium'
 url = "https://crawl.kelbi.org"
 lobby_read_delay = 10
 interactive_mode = False
 ignore_other_spectators = True
 
+
 def tprint(string):
     print("[" + datetime.now().strftime("%Y-%m-%d %H:%M:%S") + "] " + string)
 
@@ -39,6 +32,16 @@ def determine_ff_profile():
 def get_server_list():
     print('todo')
 
+def browser_and_profile(prefix='/usr/bin/'):
+    ff_bin = None
+    for exe in ['icecat', 'iceweasel', 'firefox']:
+        if path.isfile(prefix + exe):
+            ff_bin = exe
+    if ff_bin == None:
+        raise RuntimeError("no browser")
+    ff_profile = glob(environ['HOME'] + '/.mozilla/' + ff_bin + '/*.selenium')[0]
+    return (prefix + ff_bin, ff_profile)
+
 def setup_webdriver(ff_bin_location, ff_profile_location):
     ffbin = FirefoxBinary(ff_bin_location)
     ffprofile = webdriver.FirefoxProfile(ff_profile_location)
@@ -118,7 +121,7 @@ def parse_html_lobby_table(html):
         random.shuffle(game_array)
     return game_array
 
-browser = setup_webdriver(ff_bin_location, ff_profile_location)
+browser = setup_webdriver(*browser_and_profile())
 lobby_html = connect_to_lobby(browser, url, lobby_read_delay)
 
 #code.interact(local=locals())