~webapps/unity-webapps-googleplusgames/trunk

« back to all changes in this revision

Viewing changes to scripts/update-desktop-file-exec-line.py

  • Committer: Alexandre Abreu
  • Date: 2012-09-28 17:34:33 UTC
  • Revision ID: alexandre.abreu@canonical.com-20120928173433-k1rxa3wtmonhodrt
Update copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
#!/usr/bin/python
3
 
from gi.repository import Gio
4
 
import os
5
 
import glib
6
 
import glob
7
 
import re
8
 
 
9
 
APP_ID = 'GooglePlusGamesplusgooglecom'
10
 
 
11
 
def get_local_applications_path():
12
 
    return os.path.join(glib.get_user_data_dir(), 'applications')
13
 
 
14
 
def update_desktop_file_exec_line():
15
 
    local_applications_path = get_local_applications_path()
16
 
    if not os.path.exists(local_applications_path) or not os.path.isdir(local_applications_path):
17
 
        return
18
 
 
19
 
    desktop_filename = os.path.join(local_applications_path, '{0}.desktop'.format(APP_ID))
20
 
    if not os.path.exists(desktop_filename) or not os.path.isfile(desktop_filename):
21
 
        return
22
 
 
23
 
    try:
24
 
        desktop_file_content = open(desktop_filename).read()
25
 
        if desktop_file_content.find('unity-webapps-runner') != -1:
26
 
            updated_desktop_file_content = re.sub(r"Exec\s*=\s*unity-webapps-runner\s*-n\s*'([^\s]*)'.*%u",
27
 
                                                  r"Exec=webbrowser-app --chromeless --webapp='' --app-id='{0}'".format(APP_ID),
28
 
                                                  desktop_file_content)
29
 
            open(desktop_filename, "w+").write(updated_desktop_file_content)
30
 
    except Exception, e:
31
 
        print 'Error while upgrading the desktop file: ', str(e)
32
 
 
33
 
if __name__ == "__main__":
34
 
    update_desktop_file_exec_line()
35
 
    
 
 
b'\\ No newline at end of file'