Index: remoting/tools/me2me_virtual_host.py |
diff --git a/remoting/tools/me2me_virtual_host.py b/remoting/tools/me2me_virtual_host.py |
index c1eaa99b7cb9a59de5b2b79660e60c7014f5e7dd..fac470d59c103a9e0a3149fa33d165bbcafb9647 100755 |
--- a/remoting/tools/me2me_virtual_host.py |
+++ b/remoting/tools/me2me_virtual_host.py |
@@ -52,8 +52,9 @@ else: |
CHROME_REMOTING_GROUP_NAME = "chrome-remote-desktop" |
-CONFIG_DIR = os.path.expanduser("~/.config/chrome-remote-desktop") |
HOME_DIR = os.environ["HOME"] |
+CONFIG_DIR = HOME_DIR + "/.config/chrome-remote-desktop" |
Lambros
2014/02/12 20:50:32
Use os.path.join instead of string concatenation?
Sergey Ulanov
2014/02/13 02:25:44
Done.
|
+SESSION_FILE_PATH = HOME_DIR + "/.chrome-remote-desktop-session" |
X_LOCK_FILE_TEMPLATE = "/tmp/.X%d-lock" |
FIRST_X_DISPLAY_NUMBER = 20 |
@@ -75,6 +76,28 @@ MAX_LAUNCH_FAILURES = SHORT_BACKOFF_THRESHOLD + 10 |
g_desktops = [] |
g_host_hash = hashlib.md5(socket.gethostname()).hexdigest() |
+def load_lsb_release_file(): |
Lambros
2014/02/12 20:50:32
optional: I've just found out about Python's "plat
Sergey Ulanov
2014/02/13 02:25:44
actually platform.dist() is deprecated in 2.6. Th
|
+ result = {} |
+ try: |
+ for line in open('/etc/lsb-release').readlines(): |
+ parts = (line.split('#', 2)[0]).split('=', 2) |
+ if len(parts) == 2: |
+ result[parts[0].strip()] = parts[1].strip() |
+ except IOError as e: |
+ logging.error('Failed to load /etc/lsb-release: ' + str(e)) |
+ return result |
+ |
+def is_supported_platform(): |
+ # Always assume that the system is supported if the config directory or |
+ # session file exist. |
+ if os.path.isdir(CONFIG_DIR) or os.path.isfile(SESSION_FILE_PATH): |
+ return True |
+ |
+ # The host has been tested only on Ubuntu. |
+ lsb_release = load_lsb_release_file() |
+ return (lsb_release.has_key('DISTRIB_ID') and |
+ lsb_release['DISTRIB_ID'] == 'Ubuntu') |
+ |
class Config: |
def __init__(self, path): |
self.path = path |
@@ -502,7 +525,7 @@ def choose_x_session(): |
# session instead of looking for custom .xsession files in the home directory. |
# So it's necessary to test for these files here. |
XSESSION_FILES = [ |
- "~/.chrome-remote-desktop-session", |
+ SESSION_FILE_PATH, |
"~/.xsession", |
"~/.Xsession" ] |
for startup_file in XSESSION_FILES: |
@@ -902,6 +925,9 @@ Web Store: https://chrome.google.com/remotedesktop""" |
parser.add_option("-k", "--stop", dest="stop", default=False, |
action="store_true", |
help="Stop the daemon currently running.") |
+ parser.add_option("", "--get-status", dest="get_status", default=False, |
+ action="store_true", |
+ help="Prints host status") |
parser.add_option("", "--check-running", dest="check_running", default=False, |
action="store_true", |
help="Return 0 if the daemon is running, or 1 otherwise.") |
@@ -923,6 +949,19 @@ Web Store: https://chrome.google.com/remotedesktop""" |
options.config = os.path.join(CONFIG_DIR, "host#%s.json" % g_host_hash) |
# Check for a modal command-line option (start, stop, etc.) |
+ |
+ if options.get_status: |
+ pid = get_daemon_pid() |
+ if pid != 0: |
+ print "STARTED" |
+ elif is_supported_platform(): |
+ print "STOPPED" |
+ else: |
+ print "NOT_IMPLEMENTED" |
+ return 0 |
+ |
+ # TODO(sergeyu): Remove --check-running once NPAPI plugin and NM host are |
+ # updated to always use get-status flag instead. |
if options.check_running: |
pid = get_daemon_pid() |
return 0 if pid != 0 else 1 |