mailr20218 - /branches/relax_disp/lib/software/grace.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by edward on June 19, 2013 - 16:19:
Author: bugman
Date: Wed Jun 19 16:19:54 2013
New Revision: 20218

URL: http://svn.gna.org/viewcvs/relax?rev=20218&view=rev
Log:
Shifted from argparse to optparse in the grace2images.py scripts from 
relax_disp.plot_disp_curves.

This is associated with bug #20916 (https://gna.org/bugs/?20916) and the 
change suggested in the
post http://thread.gmane.org/gmane.science.nmr.relax.devel/3953/focus=4000.

The argparse module is only available from for Python 2.7.3 (the version with 
many Python 3 features
backported) and Python >= 3.2.  The module has been replaced with the similar 
optparse module as
used by relax, and which available in all Python version supported by relax.


Modified:
    branches/relax_disp/lib/software/grace.py

Modified: branches/relax_disp/lib/software/grace.py
URL: 
http://svn.gna.org/viewcvs/relax/branches/relax_disp/lib/software/grace.py?rev=20218&r1=20217&r2=20218&view=diff
==============================================================================
--- branches/relax_disp/lib/software/grace.py (original)
+++ branches/relax_disp/lib/software/grace.py Wed Jun 19 16:19:54 2013
@@ -43,33 +43,35 @@
     file.write("\n")
     file.write("import glob, os, sys\n")
     file.write("import shlex,subprocess\n")
-    file.write("import argparse\n")
-    file.write("from itertools import chain\n")
+    file.write("import optparse\n")
+    file.write("\n")
+    file.write("# Define a callback function, for a multiple input of 
PNG,EPS,SVG\n")
+    file.write("def foo_callback(option, opt, value, parser):\n")
+    file.write("    setattr(parser.values, option.dest, value.split(','))\n")
     file.write("\n")
     file.write("# Add functioning for argument parsing\n")
-    file.write("parser = argparse.ArgumentParser(description='Process grace 
files to images')\n")
+    file.write("parser = optparse.OptionParser(description='Process grace 
files to images')\n")
     file.write("# Add argument type. Destination instance is set to 
types.\n")
-    file.write("parser.add_argument('-g', action='store_true', 
dest='relax_gui', help='Make it possible to run script through relax GUI. Run 
by using User-functions -> script')\n")
-    file.write("parser.add_argument('-l', nargs='+', action='append', 
dest='l', help='Make in possible to run scriptif relax has logfile turned on. 
Run by using User-functions -> script')\n")
-    file.write("parser.add_argument('-t', nargs='+', action='append', 
dest='types', help='List image types for conversion. Execute script with: 
python %s -t PNG EPS ...'%(sys.argv[0]), default=[])\n")
-    file.write("\n")
-    file.write("# Lets stop the execution and print help if no arguments are 
passed\n")
-    file.write("if len(sys.argv)==1:\n")
+    file.write("parser.add_option('-g', action='store_true', 
dest='relax_gui', default=False, help='Make it possible to run script through 
relax GUI. Run by using User-functions -> script')\n")
+    file.write("parser.add_option('-l', action='callback', 
callback=foo_callback, dest='l', type=\"string\", default=False, help='Make 
in possible to run scriptif relax has logfile turned on. Run by using 
User-functions -> script')\n")
+    file.write("parser.add_option('-t', action='callback', 
callback=foo_callback, dest='types', type=\"string\", default=[], help='List 
image types for conversion. Execute script with: python %s -t PNG,EPS 
...'%(sys.argv[0]))\n")
+    file.write("\n")
+    file.write("# Parse the arguments to a Class instance object\n")
+    file.write("args = parser.parse_args()\n")
+    file.write("\n")
+    file.write("# Lets print help if no arguments are passed\n")
+    file.write("if len(sys.argv)==1 or len(args[0].types)==0:\n")
     file.write("    print('system argument is:',sys.argv)\n")
     file.write("    parser.print_help()\n")
     file.write("    print('Performing a default PNG conversion')\n")
-    file.write("\n")
-    file.write("# Parse the arguments to a Class instance object\n")
-    file.write("args = parser.parse_args()\n")
+    file.write("    # If no input arguments, we make a default PNG option\n")
+    file.write("    args[0].types = ['PNG']\n")
+    file.write("\n")
     file.write("# If we run through the GUI, we cannot pass input arguments, 
so we make a default PNG option\n")
-    file.write("if args.relax_gui:\n")
-    file.write("    args.types = [['PNG']]\n")
-    file.write("# If no input arguments, we make a default PNG option\n")
-    file.write("if len(args.types) == 0:\n")
-    file.write("    args.types = [['PNG']]\n")
-    file.write("\n")
-    file.write("# The instance object will contain a list of lists. We 
convert this to one list.\n")
-    file.write("types = list(chain.from_iterable(args.types))\n")
+    file.write("if args[0].relax_gui:\n")
+    file.write("    args[0].types = ['PNG']\n")
+    file.write("\n")
+    file.write("types = list(args[0].types)\n")
     file.write("\n")
     file.write("# A easy search for files with *.agr, is to use glob, which 
is pathnames matching a specified pattern according to the rules used by the 
Unix shell, not opening a shell\n")
     file.write("gracefiles = glob.glob(\"*.agr\")\n")




Related Messages


Powered by MHonArc, Updated Wed Jun 19 16:40:02 2013