~ken-vandine/unity-webapps-bbcnews/lp1369208

« back to all changes in this revision

Viewing changes to scripts/update-desktop-file-unity-webapps-bbcnews.py

  • Committer: Ken VanDine
  • Date: 2015-09-29 15:58:25 UTC
  • Revision ID: ken.vandine@canonical.com-20150929155825-0m9jny90nt0ajz8v
dropped migration script, no longer needed

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/python
2
 
from gi.repository import Gio
3
 
from gi import module
4
 
import os
5
 
import glib
6
 
import glob
7
 
import re
8
 
 
9
 
APP_ID = 'BBCNewsbbccouk'
10
 
 
11
 
def get_local_applications_path():
12
 
    GLib = module.get_introspection_module('GLib')
13
 
    user_data_dir = GLib.get_user_data_dir()
14
 
    return os.path.join(user_data_dir, 'applications')
15
 
 
16
 
def update_desktop_file_startupwmclass():
17
 
    local_applications_path = get_local_applications_path()
18
 
    if not os.path.exists(local_applications_path) or not os.path.isdir(local_applications_path):
19
 
        return
20
 
 
21
 
    desktop_filename = os.path.join(local_applications_path, '{0}.desktop'.format(APP_ID))
22
 
    if not os.path.exists(desktop_filename) or not os.path.isfile(desktop_filename):
23
 
        return
24
 
 
25
 
    try:
26
 
        desktop_file_content = open(desktop_filename).read()
27
 
        start_idx = desktop_file_content.find('[Desktop Entry]')
28
 
        if start_idx != -1 and desktop_file_content.find('StartupWMClass') == -1:
29
 
            start_idx += len('[Desktop Entry]')
30
 
            updated_desktop_file_content = desktop_file_content[:start_idx] + '\nStartupWMClass={0}'.format(APP_ID) + desktop_file_content[start_idx:]
31
 
            open(desktop_filename, "w+").write(updated_desktop_file_content)
32
 
    except Exception, e:
33
 
        print 'Error while upgrading the desktop file: ', str(e)
34
 
 
35
 
if __name__ == "__main__":
36
 
    update_desktop_file_startupwmclass()
37