source: trunk/makeLinux.py @ 4417

Last change on this file since 4417 was 3545, checked in by toby, 7 years ago

set keywords

  • 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()
32if __name__ == '__main__':
33    # find the main GSAS-II script if not on command line
34    if len(sys.argv) == 1:
35        script = os.path.abspath(os.path.join(
36            os.path.split(__file__)[0],
37            "GSASII.py"
38            ))
39    elif len(sys.argv) == 2:
40        script = os.path.abspath(sys.argv[1])
41    else:
42        Usage()
43    icon = os.path.join(os.path.split(script)[0], 'gsas2.png')
44
45    # make sure we found it
46    if not os.path.exists(script):
47        print("\nFile "+script+" not found")
48        Usage()
49    if not os.path.exists(icon):
50        print("\nWarning: File "+icon+" not found")
51        #Usage()
52    if os.path.splitext(script)[1].lower() != '.py':
53        print("\nScript "+script+" does not have extension .py")
54        Usage()
55    loc = os.path.expanduser('~/Desktop/')
56    if "XDG_DATA_HOME" in os.environ and os.path.exists(os.path.join(os.environ.get("XDG_DATA_HOME"),"applications")):
57        loc = os.path.join(os.environ.get("XDG_DATA_HOME"),"applications")
58    elif "HOME" in os.environ and os.path.exists(os.path.join(os.environ.get("HOME"),".local/share/applications")):
59        loc = os.path.join(os.environ.get("HOME"),".local/share/applications")
60    elif not os.path.exists(loc):
61        loc = os.path.expanduser('~/')
62    dfile = os.path.join(loc,'GSASII.desktop')
63    os.chmod(script, # make the .py file executable and readable
64             stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH)
65    try:
66        open(dfile,'w').write(desktop_template.format(sys.executable,script,icon))
67        os.chmod(
68            dfile,
69            stat.S_IWUSR | stat.S_IXUSR | stat.S_IRUSR | stat.S_IRGRP | stat.S_IXGRP | stat.S_IXOTH)
70        print("created GNOME/KDE desktop shortcut "+dfile)
71    except:
72        print("creation of file failed: "+dfile)
Note: See TracBrowser for help on using the repository browser.