Package qb :: Package utils :: Module qbTokens
[hide private]
[frames] | no frames]

Source Code for Module qb.utils.qbTokens

 1  ''' 
 2     QB_* token regular expressions and functions 
 3  ''' 
 4   
 5  #======================================= 
 6  #  $Revision: #2 $ 
 7  #  $Change: 12099 $ 
 8  #======================================= 
 9   
10  import re 
11  import qb 
12   
13   
14  # only compile the cmdrange regex objects once 
15  QB_FRAME_TOKEN_RGX = [ 
16      re.compile('QB_FRAME_NUMBER'), 
17      re.compile('QB_FRAME_START'), 
18      re.compile('QB_FRAME_END'), 
19      re.compile('QB_FRAME_STEP'), 
20      re.compile('QB_FRAME_RANGE'), 
21  ] 
22   
23 -def evaluateQBTokens(cmd, fRange, padding=1):
24 ''' 25 Replace all QB_* tokens with the appropriate values from the object's frame range or job stage 26 27 fRange is either the job's frame range value, or the agenda item's specific frame range 28 29 @return: Both the cmd with all QB_FRAME* tokens evaluted, and a dictionary of all tokens and their values. 30 31 @rtype: C{tuple} 32 ''' 33 padding = int(padding) 34 fStep = 1 35 36 if not re.search('[-,]', fRange): 37 # find the trivial single-frame case, with neither a '-' nor a ',' 38 fEnd = fStart = fRange 39 40 elif fRange.count('-') and not fRange.count(','): 41 if not fRange.startswith('-'): 42 # most common case, simple frame range beginning with a positive number 43 (fStart, fEnd) = fRange.split('-', 1) 44 elif fRange.count('-') == 1: 45 # a single negative number 46 fStart = fEnd = fRange 47 else: 48 # rare, a frame range whose start is a negative number 49 m = re.search('(-\d+)-(-?\d+.*)', fRange) 50 (fStart, fEnd) = m.groups() 51 52 if fEnd.count('x'): 53 (fEnd, fStep) = fEnd.split('x') 54 else: 55 # a disjointed frame range containing a comma 56 fList = qb.rangesplit(fRange) 57 fStart = fList[0] 58 fEnd = fList[-1] 59 60 tokens = {} 61 tokens['QB_FRAME_START'] = tokens['QB_FRAME_NUMBER'] = str('%0*d' % (padding, int(fStart))) 62 tokens['QB_FRAME_END'] = str('%0*d' % (padding, int(fEnd))) 63 tokens['QB_FRAME_STEP'] = str(fStep) 64 tokens['QB_FRAME_RANGE'] = fRange 65 66 for rgx in QB_FRAME_TOKEN_RGX: 67 cmd = rgx.sub(tokens[rgx.pattern], cmd) 68 69 return (cmd, tokens)
70