py2bat & license comment

arthurman at my-deja.com arthurman at my-deja.com
Wed Sep 27 11:21:07 EDT 2000


Hi, all

Some months back, on one of the mailing lists,
Michal at http://www.sabren.com
posted some code to enable running a Python
script as a DOS BAT file under the
DOS shell, a la the Perl pl2bat utility.  I'd
barely started to learn Perl when
I (oh-so-thankfully) discovered Python, but I did
sort of miss pl2bat, so I was
tickled to see Michal's posting.  I decided to
take it one step further and
write my own little utility to automate adding
Michal's code to any Python
script.  The result is below.

Anent the licensing issue: in my current
incarnation as a lawyer (mercifully
to terminate in the not-too-distant future via
retirement), I don't feel
comfortable releasing even the trivial script
below without some license -- at
least enough to support a liability disclaimer.
On the other hand, I can see,
unfortunately, a "battle of the licenses"
emerging in the open source movement.
That ain't good.  The best compromise may be to
pick one and stick with it.  I'm
no expert in intellectual property law, but
BeOpen's license seems as good as any
to me.  So to set a good example ;-), I'm
eschewing the temptation to write my own
license and am adopting BeOpen's license for the
following "poor thing, but
mine own."  FWIW, I think a choice-of-law clause
is a pretty darn good idea.

Hope-some-find-it-useful-feeback-welcome-ly yours,

Bob

A. Robert Thurman
bobthurman at worldnet.att.net
"Two wrongs do not make a right -- however, three
lefts do."

Snip
--------------------------------------------------
-----------------------------
"""                         pygobats.py
                Copyright © 2000 A. Robert Thurman

Script for converting Python scripts to enable
them to run as *.BAT files
under Microsoft DOS/Windows.

pygobats is licensed to all users thereof under
the identical terms and
conditions as set forth in the license,
incorporated herein by this reference,
between BeOpen.com and users of PythonLabs Python
v. 2.0, which terms may be
found at:

http://www.pythonlabs.com/products/python2.0/licen
se.html

with the exception that the licensor of pygobats
is A. Robert Thurman,
PMB 264, 2274 So. 1300 East #G8, Salt Lake City,
UT 84106, whose name and
address are substituted for those of BeOpen.com
in said license.
"""

import sys, string

def Batify():
    """Primary function -- reads in script, adds
cruft, writes out as BAT"""
    if len(sys.argv) < 2:      # check for file
name presence on command line
        Bugout("Usage: 'python pygobats.py <file
name>'\n", 1)
    flname = sys.argv[1]
    if len(string.split(flname, '.')) >
1:           # strip file name suffix
        flname = string.split(flname, '.')[0]
    try:
        ifl = open(flname + '.py', 'r')
    except:
        Bugout('Cannot find %s%s\n' %
(flname, '.py'), 1)
    try:
        ofl = open(flname + '.bat', 'w')
    except:
        Bugout('Cannot open %s%s\n' %
(flname, '.bat'), 1)
    ofl.write('@echo off\n')             # Python
execution will skip this line
    ofl.write('REM = """\n')      # from here
python will parse these lines ...
    ofl.write('REM %s.bat from %s.py by
pygobats\n\n' % (flname, flname))
    ofl.write('python -x %s.bat\n' % flname)  # -
x switch skips script 1st line
    ofl.write('goto end\n')
    ofl.write('"""\n\n')
# .... to here as a doc string
    while 1:                                 #
now add the whole Python script
        buf = ifl.readline()
        if not buf:
            break
        ofl.write(buf)
    ifl.close()
    ofl.write('\n\n"""\n')        # python thinks
this is another doc string --
    ofl.write(':end """\n') # and DOS shell ends
execution, having skipped rest
    ofl.close()
    Bugout('pygobats signing off -- conversion
completed.\n', 0)

def Bugout(msg, val):
    sys.stderr.write(msg)
    x = raw_input('Mash "Enter" to exit')
    sys.exit(val)

if __name__ == '__main__':
    Batify()


Sent via Deja.com http://www.deja.com/
Before you buy.



More information about the Python-list mailing list