Is there a Python version of the submit-generic script?
No, and I'm not sure a python version of submit-generic
would be as helpful as a python version of one of the other scripts.
What I might do is make a simple Python example script
that shows how to submit a job through Rush.
A simple Python submit script would be brilliant...I'm afraid Perl sends
shivers up my spine.
I converted the "rush/examples/input-example.pl" program into python,
and attached it here.
There's already a .csh and .pl version of the script, so a .py file
rounds it out nicely ;)
I'm glad I did this experiment -- it made me look closely at Python.
I'm still new to it, so I know my knowledge is limited so far,
but I'm pretty sure I /won't/ be thinking 'gee, I should port
all the submit scripts to Python..!" ..it's not a good fit IMHO.
Though Python's capable, Python seems to be more of a programming language
than a scripting language.. ie. it's more like C++ than CSH or Perl;
it sticks to strict programming guidelines (which is good, if writing programs),
but lacks syntax that makes /scripting/ pleasant.
For instance, I miss the ability to 'easily' test for the existence of a file,
something scripts often do:
PERL PYTHON
if ( -e "/some/file" ) if ( os.path.exists("/some/file") ):
if ( ! -e "/some/file" ) if ( not os.path.exists("/some/file") ):
Also, the language is so OOP-y, it's like having to specify absolute paths
to everything.. makes for redundancy that clutters up code quickly:
if ( os.path.isdir(foo) ): ..
if ( os.path.isdir(bar) ): ..
if ( os.path.isdir(bla) ): ..
..all that "os.path" stuff seems redundant readability wise,
harder to read than the csh/perl equivalent:
if ( -d $foo ) ..
if ( -d $bar ) ..
if ( -d $bla ) ..
I also miss being able to easily embed variables in strings,
making commands with lots of arguments harder to read in Python:
$render -f $somefile $sfrm $efrm # Csh
system("$render -f $somefile $sfrm $efrm"); # Perl
os.system(render+" -f "+somefile+" "+str(sfrm)+" "+str(efrm)) # Python
..all those (")s and (+)s and str()s make scripting way more difficult
than it needs to be.
Also, I'd really miss being able to do assignments within conditionals
something I do often in Perl and C:
PERL/C PYTHON
while ( $foo = ReadStuff() ) .. while (1): foo = ReadStuff(); if ( not foo ): break; ..
if ( $foo = IsOkay() ) .. foo = IsOkay(); if ( foo ): ..
And all those icky ':'s on the end of if/else/while
seem unnecessary if line breaks are present. In a language where
white space is significant, I think it would help here.
I don't mind the whitespace indenting thing as much as I thought I would,
and not having to specify $ in front of variables is nice, though not nice enough
to loose the ability to embed variables in strings. Would be neat if Python
would allow '$'s to be used to expand variables in strings, instead of that
icky "%(var)s" syntax.
#!/usr/bin/env python
import sys
import os
#
# PYTHON EXAMPLE OF HOW TO USE THE 'input' PROGRAM
#
# The 'input' program comes with rush. The executable
# can be found, under UNIX: /usr/local/rush/examples/bin/input
# and under WINDOWS: c:/rush/examples/bin/input.exe
#
# Documentation for the input program's definition file
# can be found at http://seriss.com/rush-current/input/
# or refer to the submit-*.pl examples for actual working examples.
#
# FIND THE RUSH 'INPUT' PROGRAM
# Depends on the local OS.
#
input = "/usr/local/rush/examples/bin/input"
if ( not os.path.exists(input) ): input = "c:/rush/examples/bin/input"
# WHERE'S THE TMP DIR
tmp = "/var/tmp" # modern unix
if ( not os.path.isdir(tmp) ): tmp = "/usr/tmp" # old unix
if ( not os.path.isdir(tmp) ): tmp = "c:/temp" # windows
# WHERE'S THE TEXT EDITOR TO SHOW RESULTS (WHEN USER HITS 'VIEW')
# Depends on the OS.
#
editor = "/usr/bin/gedit" # linux
if ( not os.path.exists(editor) ): editor = "/usr/sbin/jot" # sgi
if ( not os.path.exists(editor) ): editor = "notepad" # windows
if ( os.path.isdir("/Applications") ): editor = input+" -phF " # darwin
# CREATE DEFINITION FILE NEEDED BY INPUT
# This file defines all the input fields for the GUI,
# and is passed to the input program with the -d argument.
#
inputdata = tmp + "/input-example.in"
f=open(inputdata, "w")
f.write("""
# CREATE A WINDOW
window
{
name "Test Input" # The title of the window
xysize 560 180 # The x/y size of the window
resizable 1 # Allow window to be resizable (optional)
menubar yes # Include the menubar at the top (optional)
scroll yes # Make a scroll bar if needed
}
# SET STARTING POSITION FOR FIRST FIELD
# The first input field will be started at this x/y position
# on the screen. Each subsequent field will be created below the last,
# unless you change the xy value.
#
xy 150 50
# CREATE AN INPUT FIELD FOR A PATHNAME
input
{
name "Enter Some Pathname:" # Prompt shown on screen
dbname "SomePathname" # Name of this field for output file
default "//tahoe/net/foo" # Default value (optional)
filebrowser yes # Include a 'Browse' button
xysize 280 24 # x/y size of the input box
help
{
This text shows up when the user hits the "?" button.
If this 'help' section is not specified, no "?" button will appear.
}
}
# CREATE ANOTHER INPUT FIELD
# This will be created below the above field automatically.
# We *could* specify a new 'xy' or 'xyinc' command to change
# the position, but in this case we want the fields stacked
# one above the other.
#
input
{
name "Enter Other Stuff:" # Prompt shown on screen
dbname "Stuff" # Name of this field for output file
default "stuff" # Default value (optional)
xysize 280 24 # x/y size of the input box
# No help specified; no "?" will appear
}
# CREATE A CHOOSER
# Again, this chooser will be placed directly below the last field.
#
choice
{
name "Pick Something:" # Prompt shown on screen
dbname "Toppings" # Name of this field for output file
option "pepperoni" # First option in chooser
option "sausage" # Second option in chooser
option "olives" # Third option in chooser
default "sausage" # Default value (must be one of above)
xysize 100 24 # x/y size of the chooser
help
{
pick something.
}
}
# CREATE A SUBMIT AND CANCEL BUTTON
# The 'Submit' button will save out what the user
# entered, passing its filename to the submitcmd,
# which is executed after the file is saved.
#
# The 'submitcmd' can be any executable, but it
# must return an exit code of 0 to indicate success,
# or an exit code of 1 to indicate failure.
#
# In the following, we execute 'notepad', or whatever
# text editor we determined (above), which will
# simply bring up the input program's output file
# in the text editor, so you can see what the user entered.
# In real life, you would make the 'submitcmd' your own
# script, so that it parses the user's entry, and does
# something with it.
#
# In this case, we want to offset the X position
# of these two buttons off to the right, so we
# use this 'xyinc' command, which adds the x/y values
# to the "current" x/y position
#
xyinc 200 0
submit
{
submitname "View"
cancelname "Cancel"
submitcolor 51 # submit button color (see color table in docs)
cancelcolor 51 # color of cancel button
submitcmd "%(editor)s" # command to run when the user hits 'Submit'
showfail 1 # if submitcmd fails, pop dialog to show error
}
""" % locals() ) # finished write() command
f.close()
# Create empty hist file if none exists
histfile = tmp+"/input-example.hist"
if ( not os.path.exists(histfile) ): open(histfile,"w").close()
# Invoke input
os.system(input + " -P -d " + inputdata + " -H " + histfile)
|