2
from gi.repository import Gio
9
APP_ID = 'BBCNewsbbccouk'
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')
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):
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):
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)
33
print 'Error while upgrading the desktop file: ', str(e)
35
if __name__ == "__main__":
36
update_desktop_file_startupwmclass()