Size: 73
Comment:
|
Size: 1603
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 2: | Line 2: |
This tutorial covers the necessary steps to incorporate a e2program into the projectmanager. === Modifications to the e2program itself === Canonical e2programs must maintain the following standards 1. Options are handled via EMArgumentParser, which is a subclass of Python's argparse module (version 2.7 and higher). For more information on argparse, see the python documentation. [[http://docs.python.org/dev/library/argparse.html]] 1. Arguments are handled via EMArgumentParser. 1. A line usage = """blah, blah, blah...""" must be present to give help info on the e2program 1. A line progname = os.path.basename(sys.argv[0]) must be present To illustrate, here is an example program: {{{#!highlight python #!/usr/bin/env python from EMAN2 import * def main(): progname = os.path.basename(sys.argv[0]) usage = """prog arg1, arg2, [options] This is an exmaple program """ parser = EMArgumentParser(usage=usage,version=EMANVERSION) parser.add_argument("--option1",type=str,help="This is the first option",default="myvalue") parser.add_argument("--option2",type=int,help="This is the second option",default=1) parser.add_argument("--option3",type=float,help="This is the third option",default=3.14) parser.add_argument("--option4",action="store_true",help="This is the fourth option",default=False) (options, args) = parser.parse_args() print "Arguments are", args print "Options are", options if __name__ == __main__: main() }}} |
Tutorial to aid adding a new e2program to the e2projectmanager.py
This tutorial covers the necessary steps to incorporate a e2program into the projectmanager.
Modifications to the e2program itself
Canonical e2programs must maintain the following standards
Options are handled via EMArgumentParser, which is a subclass of Python's argparse module (version 2.7 and higher). For more information on argparse, see the python documentation. http://docs.python.org/dev/library/argparse.html
- Arguments are handled via EMArgumentParser.
- A line usage = """blah, blah, blah...""" must be present to give help info on the e2program
- A line progname = os.path.basename(sys.argv[0]) must be present
To illustrate, here is an example program:
1 #!/usr/bin/env python
2
3 from EMAN2 import *
4
5 def main():
6 progname = os.path.basename(sys.argv[0])
7 usage = """prog arg1, arg2, [options]
8 This is an exmaple program """
9
10 parser = EMArgumentParser(usage=usage,version=EMANVERSION)
11 parser.add_argument("--option1",type=str,help="This is the first option",default="myvalue")
12 parser.add_argument("--option2",type=int,help="This is the second option",default=1)
13 parser.add_argument("--option3",type=float,help="This is the third option",default=3.14)
14 parser.add_argument("--option4",action="store_true",help="This is the fourth option",default=False)
15
16 (options, args) = parser.parse_args()
17
18 print "Arguments are", args
19 print "Options are", options
20
21 if __name__ == __main__:
22 main()