Package diffpy :: Package pdfgui :: Package control :: Module dumppdffit2script
[hide private]
[frames] | no frames]

Source Code for Module diffpy.pdfgui.control.dumppdffit2script

 1  #!/usr/bin/env python 
 2  ############################################################################## 
 3  # 
 4  # PDFgui            by DANSE Diffraction group 
 5  #                   Simon J. L. Billinge 
 6  #                   (c) 2006 trustees of the Michigan State University. 
 7  #                   All rights reserved. 
 8  # 
 9  # File coded by:    Pavol Juhas 
10  # 
11  # See AUTHORS.txt for a list of people who contributed. 
12  # See LICENSE.txt for license information. 
13  # 
14  ############################################################################## 
15   
16  """Create list of fits from pdffit2 script and pickle it to standard output. 
17  Usage: dumppdffit2script.py scriptfile.py [arg1] [arg2] ... 
18   
19  Returns exit code 0 if script was successfully read, 1 if an error occured 
20  and 2 if scriptfile.py does not exist 
21  """ 
22   
23  # version 
24  __id__ = "$Id: dumppdffit2script.py 2980 2009-04-02 00:14:33Z juhas $" 
25   
26  import sys 
27  import os 
28   
29  from diffpy.pdfgui.control.pdffitsandbox import PdfFitSandbox 
30  from diffpy.pdfgui.utils import safeCPickleDumps 
31   
32 -def main():
33 if len(sys.argv) < 2: 34 print >> sys.stderr, "scriptfile not specified." 35 sys.exit(2) 36 elif not os.path.isfile(sys.argv[1]): 37 print >> sys.stderr, "Cannot read %r" % sys.argv[1] 38 sys.exit(2) 39 scriptfile = sys.argv[1] 40 scriptbase = os.path.basename(scriptfile) 41 del sys.argv[1] 42 box = PdfFitSandbox() 43 try: 44 box.loadscript(scriptfile) 45 except: 46 exc_type, exc_value, exc_tb = sys.exc_info() 47 import traceback 48 for filename, lineno, fnc, line in traceback.extract_tb(exc_tb): 49 if os.path.basename(filename) != scriptbase: 50 continue 51 print >> sys.stderr, "%s:%i:%s" % (scriptfile, lineno, line) 52 print >> sys.stderr, exc_value 53 sys.exit(1) 54 # make sure reading from stderr will not hang, see 55 # http://www.python.org/doc/current/lib/popen2-flow-control.html 56 os.close(sys.stderr.fileno()) 57 # all is ready, dump it 58 sys.stdout.write( safeCPickleDumps(box.allfits()) ) 59 return
60 61 if __name__ == "__main__": 62 main() 63 64 # End of file 65