Home | Trees | Indices | Help |
---|
|
1 """ 2 Class that implements reading vom a pickled file. Every utility that 3 gets input from a pipe should use it 4 """ 5 from optparse import OptionGroup 6 7 from PyFoam.ThirdParty.six.moves import cPickle as pickle 8 from PyFoam.ThirdParty.six import print_ 9 10 import sys 1113 """ The class that defines the options for reading from a pickled plot 14 """ 1573 74 # Should work with Python3 and Python2 7517 pickled=OptionGroup(self.parser, 18 "Pickled file reading", 19 "Options for reading from a pickled file") 20 self.parser.add_option_group(pickled) 21 pickled.add_option("--pickled-file", 22 action="store", 23 default=None, 24 dest="pickledFileRead", 25 help=""" 26 File from which the pickled data should be read. If this is set to 27 'stdin' then the data is read from the standard-input to allow using 28 the pipe into it. If unset and stdin is not a terminal, then it is 29 automatically chosen""") 30 31 pickled.add_option("--print-data", 32 action="store_true", 33 default=False, 34 dest="printPickledData", 35 help="print the pickled data after is has been read") 36 37 pickled.add_option("--print-stdout", 38 action="store_true", 39 default=False, 40 dest="printStdout", 41 help="Print the standard-output (if it has been safed into the pickled file)")4244 if "inputData" in self: 45 if self.opts.pickledFileRead: 46 self.error("--pickled-file specified, when input data was provided via the Python-API") 47 data=self["inputData"] 48 else: 49 if not self.opts.pickledFileRead: 50 if sys.stdin.isatty(): 51 self.error("The option --pickled-file has to be set") 52 else: 53 self.opts.pickledFileRead="stdin" 54 55 if self.opts.pickledFileRead=="stdin": 56 pick=pickle.Unpickler(sys.stdin) 57 else: 58 pick=pickle.Unpickler(open(self.opts.pickledFileRead)) 59 data=pick.load() 60 del pick 61 62 if self.opts.printStdout: 63 try: 64 print_(data["stdout"]) 65 except KeyError: 66 print_("<No stdout in data>") 67 if self.opts.printPickledData: 68 import pprint 69 printer=pprint.PrettyPrinter() 70 printer.pprint(data) 71 72 return data
Home | Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Mon Nov 24 20:56:36 2014 | http://epydoc.sourceforge.net |