fix #627 create-desktop-icon.py fails when the name of the Desktop dir is localized

This commit is contained in:
Eric Le Lay 2019-06-02 18:25:03 +02:00
parent 3d6ea580f1
commit 63dc00ba76
1 changed files with 12 additions and 3 deletions

15
tools/create-desktop-icon.py Normal file → Executable file
View File

@ -5,6 +5,9 @@
import os
import sys
import gi
from gi.repository import GLib
BASE = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
TEMPLATE = """# Created by %(__file__)s
@ -16,14 +19,20 @@ Terminal=false
Type=Application
""" % locals()
DESTINATION = os.path.expanduser('~/Desktop/gpodder-git.desktop')
DESKTOP = GLib.get_user_special_dir(GLib.UserDirectory.DIRECTORY_DESKTOP)
if not os.path.exists(DESKTOP):
print("{} desktop folder doesn't exists, exiting".format(DESKTOP))
sys.exit(1)
DESTINATION = os.path.join(DESKTOP, 'gpodder-git.desktop')
if os.path.exists(DESTINATION):
print('%(DESTINATION)s already exists, not overwriting')
print('{} already exists, not overwriting'.format(DESTINATION))
sys.exit(1)
with open(DESTINATION, 'w') as fp:
fp.write(TEMPLATE)
os.chmod(DESTINATION, 0o755)
print('Wrote %(DESTINATION)s' % locals())
print('Wrote {}'.format(DESTINATION))