Ticket #11602: trac_11602-delta.patch

File trac_11602-delta.patch, 4.4 KB (added by John Palmieri, 11 years ago)

for reference only; do not apply

  • sage/misc/dist.py

    diff --git a/sage/misc/dist.py b/sage/misc/dist.py
    a b import os 
    77def install_scripts(directory=None, ignore_existing=False):
    88    r"""
    99    Running ``install_scripts(directory)`` creates scripts in the
    10     given directory that, independently of Sage, run various software
    11     components included with Sage: 'gap', 'gp', 'singular', 'maxima',
    12     'M2', 'kash', 'mwrank', 'ipython', 'hg', 'R'.
     10    given directory that run various software components included with
     11    Sage: 'gap', 'gp', 'singular', 'maxima', 'M2', 'kash', 'mwrank',
     12    'ipython', 'hg', 'R'.
    1313   
    1414    This command:
    1515   
    def install_scripts(directory=None, igno 
    2424       scripts
    2525
    2626    - ``ignore_existing`` - bool (optional, default False): if True,
    27       install a shortcut to Sage's version of a program even if
    28       another version is in your path.
     27      install script even if another version of the program is in your
     28      path.
    2929
    3030    OUTPUT: Verbosely prints what it is doing and creates files in
    3131    ``directory`` that are world executable and readable.
    def install_scripts(directory=None, igno 
    3535       You may need to run Sage as root in order to run
    3636       ``install_scripts`` successfully, since the user running Sage
    3737       will need write permissions on ``directory``.  Note that
    38        one good candidate for ``directory`` is "/usr/local/bin".
     38       one good candidate for ``directory`` is ``'/usr/local/bin'``.
     39
     40    .. note::
    3941
    4042       Running ``install_scripts(directory)`` will be most helpful if
    4143       ``directory`` is in your path.
    def install_scripts(directory=None, igno 
    4648
    4749    - Arthur Gaer: design
    4850
     51    - John Palmieri: revision, 2011-07 (trac ticket #11602)
     52
    4953    EXAMPLES::
    5054
    5155        sage: install_scripts(SAGE_TMP, ignore_existing=True)
    def install_scripts(directory=None, igno 
    6266        return
    6367   
    6468    if not (os.path.exists(directory) and os.path.isdir(directory)):
    65         raise RuntimeError, "'%s' must exist and be a directory"%directory
     69        raise OSError, "'%s' must exist and be a directory"%directory
     70
     71    script_created = False
    6672
    6773    for cmd in ['gap', 'gp', 'singular', 'maxima', 'M2', 'kash', \
    6874              'mwrank', 'ipython', 'hg', 'R']:
    def install_scripts(directory=None, igno 
    7985                         and not os.path.samefile(d, SAGE_BIN)])
    8086        cmd_outside_sage = have_program(cmd, path=PATH)
    8187        if not cmd_inside_sage:
    82             print "The command '%s' is not available as part of Sage; not adding shortcut." % cmd
     88            print "The command '%s' is not available as part " %cmd \
     89                  + "of Sage; not creating script."
    8390            print
    8491            continue
    8592        if cmd_outside_sage:
    8693            print "The command '%s' is installed outside of Sage;" % cmd,
    8794            if not ignore_existing:
    88                 print "not adding shortcut."
     95                print "not creating script."
    8996                print
    9097                continue
    91             else:
    92                 print "trying to add shortcut anyway."
     98            print "trying to create script anyway..."
     99        else:
     100            print "Creating script for '%s'..." % cmd
    93101        # Install shortcut.
    94102        target = os.path.join(directory, cmd)
    95103        if os.path.exists(target):
    96             print "The file '%s' already exists; not adding shortcut."%(target)
     104            print "The file '%s' already exists; not adding script."%(target)
    97105        else:
    98106            o = open(target,'w')
    99107            o.write('#!/bin/sh\n')
    def install_scripts(directory=None, igno 
    101109            o.close()
    102110            print "Created script '%s'"%target
    103111            os.system('chmod a+rx %s'%target)
     112            script_created = True
    104113        print
    105            
    106     print "Finished creating scripts."
    107     print
    108     print "You need not do this again even if you upgrade or move Sage."
    109     print "The only requirement is that your PATH contains both"
    110     print "%s and the directory containing the command 'sage'." % directory
     114
     115    if script_created:
     116        print "Finished creating scripts."
     117        print
     118        print "You need not do this again even if you upgrade or move Sage."
     119        print "The only requirement is that your PATH contains both"
     120        print "'%s' and the directory containing the command 'sage'." % directory
     121    else:
     122        print "No scripts created."