qsequence.py a component of openallure.py
Parses separate content file into question sequence object
Usage
QSequence( filename ) returns a question sequence object
filename can be either a local file or a URL containing preformatted text
An input file is a plain text file with the format:
[ configuration overrides ]
Question part1
[ optional Question part2 ]
[ optional blank line ]
Answer 1 <separator> Response 1
Answer 2 <separator> Response 2
etc ...
up to 6 answers
[ blank line ]
Next question ...
where configuration overrides can be:
smile image to use for smiling avatar
talk image to use for talking avatar
listen image to use for listening avatar
where Answer can be:
[link label] to open link in separate browser when label is selected
[input] to enable user input
[next] to enable user input, but only until an automatic "page turn"
where <separator> can be:
; no action
;; or ;1 or ;+1 advance to next question
;-1 return to prior question ( in order exposed in sequence )
;;; or ;2 or ;+2 advance two questions
;[filename] advance to first question found in filename
;[url] advance to first question found in text marked <pre> </pre> at URL (webpage)
Output
List of lists:
# [ The whole sequence of questions is outermost list,
# so seq[ 0 ] is everything about the first question
# [ The parts of the a question including the question set, answer set, response set and action/destination sets are the next level list,
# so seq[ ][ 0 ] is the question set
# seq[ ][ 1 ] is the answer set
# seq[ ][ 2 ] is the response set
# seq[ ][ 3 ] is the action set
# seq[ ][ 4 ] is the action set destinations (Response-side filenames or URLs for new questions)
# seq[ ][ 5 ] is the links set (Answer-side filenames or URLs to open in browser)
# seq[ ][ 6 ] is the input set
# [ The parts of the question are the next level list,
# so seq[ ][ 0 ][ 0 ] is the first part of the question, for example "What color"
# and seq[ ][ 0 ][ 1 ] is the next part of the question, for example "is the sky?" ],
# [ The answers are the next list,
# so seq[ ][ 1 ][ 0 ] is the first answer, for example "Black"
# and seq[ ][ 1 ][ 1 ] is the second answer, for example "Blue" ],
# [ The response are the next list,
# so seq[ ][ 2 ][ 0 ] is the first response, for example "Yes, at night."
# and seq[ ][ 2 ][ 1 ] is the second response, for example "Yes, during the day." ],
# [ The actions are the next list,
# so seq[ ][ 3 ][ 0 ] is the first action, for example 0 ( meaning take no action )
# and seq[ ][ 3 ][ 1 ] is the second action, for example 1 ( meaning advance one question ) ],
# [ The destinations are the next list,
# so seq[ ][ 4 ][ 0 ] is the first destination, for example 'secondSetOfQuestions.txt'
# and seq[ ][ 4 ][ 1 ] is the second destination, for example 'http://bit.ly/openalluretest' ]]]
# [ The links are the next list,
# so seq[ ][ 5 ][ 0 ] is the first link, for example 'http://movieToWatch'
# and seq[ ][ 5 ][ 1 ] is the second link, for example 'slidecastToWatch' ]]]
# [ The inputs are the next list,
# so seq[ ][ 6 ][ 0 ] is the first input, for example 0 (indicating no input on this answer)
# and seq[ ][ 6 ][ 1 ] is the second link, for example 1 (indicating input allowed on this answer)
# Special case for photos seq[0][ 7 ] is list of smile/talk/listen photo names
See Open Allure wiki for details and examples.
Copyright (c) 2010 John Graves
MIT License: see LICENSE.txt
A Question Sequence contains (multiple) question blocks consisting of a question with answers/responses/actions
Create list of string types:
Identify strings which contain new line only ( type N )
# or which contain ; or ;; markers ( type indicated by offset of separator
# between Answer ; Response )
# or else mark as question ( type Q )