~webapps/unity-webapps-googleplusgames/trunk

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
from gi.repository import Gio
import os
import glib
import glob
import re

APP_ID = 'GooglePlusGamesplusgooglecom'

def get_local_applications_path():
    return os.path.join(glib.get_user_data_dir(), 'applications')

def update_desktop_file_exec_line():
    local_applications_path = get_local_applications_path()
    if not os.path.exists(local_applications_path) or not os.path.isdir(local_applications_path):
        return

    desktop_filename = os.path.join(local_applications_path, '{0}.desktop'.format(APP_ID))
    if not os.path.exists(desktop_filename) or not os.path.isfile(desktop_filename):
        return

    try:
        desktop_file_content = open(desktop_filename).read()
        if desktop_file_content.find('unity-webapps-runner') != -1:
            updated_desktop_file_content = re.sub(r"Exec\s*=\s*unity-webapps-runner\s*-n\s*'([^\s]*)'.*%u",
                                                  r"Exec=webbrowser-app --chromeless --webapp='' --app-id='{0}'".format(APP_ID),
                                                  desktop_file_content)
            open(desktop_filename, "w+").write(updated_desktop_file_content)
    except Exception, e:
        print 'Error while upgrading the desktop file: ', str(e)

if __name__ == "__main__":
    update_desktop_file_exec_line()