schema
schema copied to clipboard
Order of tasks
def setInputHocrFile( fileName ):
global inputHocrFileName
inputHocrFileName = fileName
print fileName
return True
def addInputImageFile( fileName ):
global inputImageFileNames
inputImageFileNames.append( fileName )
print fileName
return True
...
schema = Schema({
'<inputHocrFile>': And(setInputHocrFile, Use(open, error="Can't open <inputHocrFile>") ) ,
'--help': bool,
'-I': bool,
'-b': bool,
'-m': bool,
'-n': bool,
'-t': bool,
'<inputImageFile>': [ And(Use(open, error="Can't open <inputImageFile>"), addInputImageFile) ],
'<outputPdfFile>': str })
The goal is to do some things depending on the command line arguments.
The print command in addInputImageFile returned an open file object, while setInputHocrFile returns the filename as was the original value of key 'setInputHocrFile'.
I just wonder if it is intended that a function like open changes the value of the variable to be tested.
Sorry for late response. I'm not sure I understand your question.
@c-holtermann: Not sure if you're still interested in this issue, but here goes:
In the line
And(Use(open, error="Can't open <inputImageFile>"), addInputImageFile)
the validate method of the Use object calls open on whatever the given input is and returns the resulting file handle. Then And passes that file handle on to addInputImageFile.
If you want to call addInputImageFile on the filename and then generate the file handle, you should write And(addInputImageFile, Use(open, …)) instead, just as you did with <inputHocrFile>.
Does this answer your question?