~webapps/unity-webapps-deviantart/trunk

« back to all changes in this revision

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

  • Committer: Alexandre Abreu
  • Date: 2013-09-24 16:15:29 UTC
  • Revision ID: alexandre.abreu@canonical.com-20130924161529-pr8xc70n272hxl7g
Add session migration script & desktop file for StartupWMClass

Show diffs side-by-side

added added

removed removed

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