schema icon indicating copy to clipboard operation
schema copied to clipboard

Order of tasks

Open c-holtermann opened this issue 12 years ago • 2 comments

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.

c-holtermann avatar Oct 24 '13 18:10 c-holtermann

Sorry for late response. I'm not sure I understand your question.

keleshev avatar Dec 03 '13 12:12 keleshev

@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?

sjakobi avatar Sep 25 '15 22:09 sjakobi