source: trunk/makeLinux.py

Last change on this file was 4736, checked in by toby, 9 months ago

more install work

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Author Revision URL Id
File size: 2.7 KB
Line 
1#!/usr/bin/env python
2'''
3*makeLinux: Create Linux Shortcuts*
4===================================
5
6This script creates a menu entry for Gnome & KDE desktop managers
7and puts it in a place where it can be "indexed."
8
9This is a work in progress as I learn more about shortcuts in Linux.
10
11Run this script with one optional argument, the path to the GSASII.py
12The script path may be specified relative to the current path or given
13an absolute path, but will be accessed via an absolute path.
14If no arguments are supplied, the GSASII.py script is assumed to be in the
15same directory as this file.
16
17'''
18import sys, os, os.path, stat, shutil, subprocess, plistlib
19desktop_template = """
20[Desktop Entry]
21Version=1.0
22Type=Application
23Terminal=false
24Exec=xterm -hold -e bash -c "{} {}"
25Name=GSAS-II
26Icon={}
27Categories=Science;
28"""
29def Usage():
30    print("\n\tUsage: python "+sys.argv[0]+" [<GSAS-II script>]\n")
31    sys.exit()
32
33if __name__ == '__main__' and sys.platform.startswith('linux'):
34    # find the main GSAS-II script if not on command line
35    if len(sys.argv) == 1:
36        script = os.path.abspath(os.path.join(
37            os.path.split(__file__)[0],
38            "GSASII.py"
39            ))
40    elif len(sys.argv) == 2:
41        script = os.path.abspath(sys.argv[1])
42    else:
43        Usage()
44    icon = os.path.join(os.path.split(script)[0], 'gsas2.png')
45
46    # make sure we found it
47    if not os.path.exists(script):
48        print("\nFile "+script+" not found")
49        Usage()
50    if not os.path.exists(icon):
51        print("\nWarning: File "+icon+" not found")
52        #Usage()
53    if os.path.splitext(script)[1].lower() != '.py':
54        print("\nScript "+script+" does not have extension .py")
55        Usage()
56    loc = os.path.expanduser('~/Desktop/')
57    if "XDG_DATA_HOME" in os.environ and os.path.exists(os.path.join(os.environ.get("XDG_DATA_HOME"),"applications")):
58        loc = os.path.join(os.environ.get("XDG_DATA_HOME"),"applications")
59    elif "HOME" in os.environ and os.path.exists(os.path.join(os.environ.get("HOME"),".local/share/applications")):
60        loc = os.path.join(os.environ.get("HOME"),".local/share/applications")
61    elif not os.path.exists(loc):
62        loc = os.path.expanduser('~/')
63    dfile = os.path.join(loc,'GSASII.desktop')
64    os.chmod(script, # make the .py file executable and readable
65             stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH)
66    try:
67        open(dfile,'w').write(desktop_template.format(sys.executable,script,icon))
68        os.chmod(
69            dfile,
70            stat.S_IWUSR | stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH)
71        print("created GNOME/KDE desktop shortcut "+dfile)
72    except:
73        print("creation of file failed: "+dfile)
Note: See TracBrowser for help on using the repository browser.