rem
stringlengths
0
322k
add
stringlengths
0
2.05M
context
stringlengths
8
228k
getRecipeStores = os.popen("/bin/sh -c '. " + file +" 2> /dev/null; for i in ${getRecipeStores[@]}; do echo $i; done'").read().strip('\n').split() if getRecipeStores :
getRecipeStores = os.popen("/bin/sh -c '. " + file +" 2> /dev/null; for i in \"${getRecipeStores[@]}\"; do echo $i; done'").read().strip('\n').split('\n') if getRecipeStores and getRecipeStores[0] :
def getCompileOptions() : import os goboSettings = getGoboVariable('goboSettings') goboPrograms = getGoboVariable('goboPrograms') goboCompileDefaults = goboPrograms+'/Compile/Current/Resources/Defaults/Settings/' compileSettingsFiles = [ "~/.Settings/Compile/Compile.conf", goboSettings + "/Compile/Compile.conf", goboCompileDefaults+"/Compile/Compile.conf" ] try : compileRecipeDirs = os.environ['compileRecipeDirs'].strip('\n').split() except : for file in compileSettingsFiles : compileRecipeDirs = os.popen("/bin/sh -c '. " +file+" 2> /dev/null; for i in ${compileRecipeDirs[@]}; do echo $i; done'").read().strip('\n').split() if compileRecipeDirs : break try : getRecipeStores = os.environ['getRecipeStores'].strip('\n').split('\n') except : for file in compileSettingsFiles : getRecipeStores = os.popen("/bin/sh -c '. " + file +" 2> /dev/null; for i in ${getRecipeStores[@]}; do echo $i; done'").read().strip('\n').split() if getRecipeStores : break #import sys #sys.stderr.write(str(compileRecipeDirs)) #sys.stderr.write(str(getRecipeStores)) import os.path return (map(os.path.expanduser,compileRecipeDirs), getRecipeStores)
return (v+'-'+r).strip('-')
if r : return v+'-'+r else : return v
def Join_Version_Revision(v, r) : return (v+'-'+r).strip('-')
os.environ[name] = os.popen("/bin/sh -c '. " + file +" 2> /dev/null; echo -n $"+name+"'").read()
os.environ[name] = os.popen("/bin/sh -c '. " + file +" 2> /dev/null; for i in ${"+name+"[@]}; do echo $i; done'").read().strip('\n')
def getGoboVariable(name, filename = 'GoboPath', isList = False) : if filename != 'GoboPath' : goboSettings = getGoboVariable('goboSettings') goboPrograms = getGoboVariable('goboPrograms') goboScriptsDefaults = goboPrograms+'/Scripts/Current/Resources/Defaults/Settings/' goboManagerDefaults = goboPrograms+'/Manager/Current/Resources/Defaults/Settings/' files = [ "~/.Settings/"+filename, goboSettings + "/"+filename, goboScriptsDefaults + "/"+filename, goboManagerDefaults+"/"+filename, filename] else : files = [ filename] if not isList : try : return os.environ[name] except : for file in files : value = os.popen('. '+file+' 2> /dev/null; echo -n $'+name).read() if value : break os.environ[name] = value return value else : try : return os.environ[name].split() except : for file in files : os.environ[name] = os.popen("/bin/sh -c '. " + file +" 2> /dev/null; echo -n $"+name+"'").read() if os.environ[name] : break return os.environ[name].split()
compileRecipeDirs = os.environ['compileRecipeDirs'].split()
compileRecipeDirs = os.environ['compileRecipeDirs'].strip('\n').split()
def getCompileOptions() : import os goboSettings = getGoboVariable('goboSettings') goboPrograms = getGoboVariable('goboPrograms') goboCompileDefaults = goboPrograms+'/Compile/Current/Resources/Defaults/Settings/' compileSettingsFiles = [ "~/.Settings/Compile/Compile.conf", goboSettings + "/Compile/Compile.conf", goboCompileDefaults+"/Compile/Compile.conf" ] try : compileRecipeDirs = os.environ['compileRecipeDirs'].split() except : for file in compileSettingsFiles : compileRecipeDirs = os.popen("/bin/sh -c '. " +file+" 2> /dev/null; for i in ${compileRecipeDirs[@]}; do echo $i; done'").readlines() if compileRecipeDirs : break try : getRecipeStores = os.environ['getRecipeStores'].split() except : for file in compileSettingsFiles : getRecipeStores = os.popen("/bin/sh -c '. " + file +" 2> /dev/null; for i in ${getRecipeStores[@]}; do echo $i; done'").readlines() if getRecipeStores : break import os.path return (map(os.path.expanduser,compileRecipeDirs), getRecipeStores)
compileRecipeDirs = os.popen("/bin/sh -c '. " +file+" 2> /dev/null; for i in ${compileRecipeDirs[@]}; do echo $i; done'").readlines()
compileRecipeDirs = os.popen("/bin/sh -c '. " +file+" 2> /dev/null; for i in ${compileRecipeDirs[@]}; do echo $i; done'").read().strip('\n').split()
def getCompileOptions() : import os goboSettings = getGoboVariable('goboSettings') goboPrograms = getGoboVariable('goboPrograms') goboCompileDefaults = goboPrograms+'/Compile/Current/Resources/Defaults/Settings/' compileSettingsFiles = [ "~/.Settings/Compile/Compile.conf", goboSettings + "/Compile/Compile.conf", goboCompileDefaults+"/Compile/Compile.conf" ] try : compileRecipeDirs = os.environ['compileRecipeDirs'].split() except : for file in compileSettingsFiles : compileRecipeDirs = os.popen("/bin/sh -c '. " +file+" 2> /dev/null; for i in ${compileRecipeDirs[@]}; do echo $i; done'").readlines() if compileRecipeDirs : break try : getRecipeStores = os.environ['getRecipeStores'].split() except : for file in compileSettingsFiles : getRecipeStores = os.popen("/bin/sh -c '. " + file +" 2> /dev/null; for i in ${getRecipeStores[@]}; do echo $i; done'").readlines() if getRecipeStores : break import os.path return (map(os.path.expanduser,compileRecipeDirs), getRecipeStores)
getRecipeStores = os.environ['getRecipeStores'].split()
getRecipeStores = os.environ['getRecipeStores'].strip('\n').split('\n')
def getCompileOptions() : import os goboSettings = getGoboVariable('goboSettings') goboPrograms = getGoboVariable('goboPrograms') goboCompileDefaults = goboPrograms+'/Compile/Current/Resources/Defaults/Settings/' compileSettingsFiles = [ "~/.Settings/Compile/Compile.conf", goboSettings + "/Compile/Compile.conf", goboCompileDefaults+"/Compile/Compile.conf" ] try : compileRecipeDirs = os.environ['compileRecipeDirs'].split() except : for file in compileSettingsFiles : compileRecipeDirs = os.popen("/bin/sh -c '. " +file+" 2> /dev/null; for i in ${compileRecipeDirs[@]}; do echo $i; done'").readlines() if compileRecipeDirs : break try : getRecipeStores = os.environ['getRecipeStores'].split() except : for file in compileSettingsFiles : getRecipeStores = os.popen("/bin/sh -c '. " + file +" 2> /dev/null; for i in ${getRecipeStores[@]}; do echo $i; done'").readlines() if getRecipeStores : break import os.path return (map(os.path.expanduser,compileRecipeDirs), getRecipeStores)
getRecipeStores = os.popen("/bin/sh -c '. " + file +" 2> /dev/null; for i in ${getRecipeStores[@]}; do echo $i; done'").readlines()
getRecipeStores = os.popen("/bin/sh -c '. " + file +" 2> /dev/null; for i in ${getRecipeStores[@]}; do echo $i; done'").read().strip('\n').split()
def getCompileOptions() : import os goboSettings = getGoboVariable('goboSettings') goboPrograms = getGoboVariable('goboPrograms') goboCompileDefaults = goboPrograms+'/Compile/Current/Resources/Defaults/Settings/' compileSettingsFiles = [ "~/.Settings/Compile/Compile.conf", goboSettings + "/Compile/Compile.conf", goboCompileDefaults+"/Compile/Compile.conf" ] try : compileRecipeDirs = os.environ['compileRecipeDirs'].split() except : for file in compileSettingsFiles : compileRecipeDirs = os.popen("/bin/sh -c '. " +file+" 2> /dev/null; for i in ${compileRecipeDirs[@]}; do echo $i; done'").readlines() if compileRecipeDirs : break try : getRecipeStores = os.environ['getRecipeStores'].split() except : for file in compileSettingsFiles : getRecipeStores = os.popen("/bin/sh -c '. " + file +" 2> /dev/null; for i in ${getRecipeStores[@]}; do echo $i; done'").readlines() if getRecipeStores : break import os.path return (map(os.path.expanduser,compileRecipeDirs), getRecipeStores)
def controller_scan(directory):
def controller_scan(directory=None):
def controller_scan(directory): """ Scan a directory for python files and use them as controllers """ def find_controllers(dirname, prefix=''): controllers = [] for fname in os.listdir(dirname): filename = os.path.join(dirname, fname) if os.path.isfile(filename) and re.match('^[^_]{1,1}.*\.py$', fname): controllers.append(prefix + fname[:-3]) elif os.path.isdir(filename): controllers.extend(find_controllers(filename, prefix=prefix+fname+'/')) return controllers def longest_first(a, b): return cmp(len(b), len(a)) controllers = find_controllers(directory) controllers.sort(longest_first) return controllers
(reg, gaps) = self.buildnextreg(self.routelist, clist) print reg
(reg, noreqs, allblank) = self.buildnextreg(self.routelist, clist)
def makeregexp(self, clist): """ Create a regular expression for matching purposes, this MUST be called before match can function properly. clist should be a list of valid controller strings that can be matched, for this reason makeregexp should be called by the web framework after it knows all available controllers that can be utilized """ (reg, gaps) = self.buildnextreg(self.routelist, clist) print reg if not reg: reg = '/' reg = '^' + reg + '$' self.regexp = reg self.regmatch = re.compile(reg)
default = '[^/]+'
def buildnextreg(self, path, clist): default = '[^/]+' part = path[0] reg = '' (rest, moregaps) = ('', False) if len(path[1:]) > 0: (rest, moregaps) = self.buildnextreg(path[1:], clist) gaps = False if part.startswith(':'): var = part[1:] partreg = '' if self.reqs.has_key(var) and self.defaults.has_key(var) and not moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')?' reg = reg + rest elif self.reqs.has_key(var) and self.defaults.has_key(var) and moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + rest elif self.reqs.has_key(var) and not self.defaults.has_key(var) and moregaps: reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + '(' + rest + ')?' if self.reqs.has_key(var): gaps = True partreg = '(?P<' + var + '>' + self.reqs[var] + ')' elif var == 'controller': gaps = True partreg = '(?P<' + var + '>' + '|'.join(clist) + ')' else: partreg = '(?P<' + var + '>' + default + ')' if self.defaults.has_key(var) and not moregaps: reg = '(/' + partreg + ')?' else: reg = '/' + partreg elif part.startswith('*'): var = part[1:] reg = '(/' + '(?P<' + var + '>.*))*' else: gaps = True reg = '/' + part if moregaps and gaps: reg = '(' + reg + rest + ')?' else: reg = reg + rest return (reg, gaps)
(rest, moregaps) = ('', False)
(rest, noreqs, allblank) = ('', True, True)
def buildnextreg(self, path, clist): default = '[^/]+' part = path[0] reg = '' (rest, moregaps) = ('', False) if len(path[1:]) > 0: (rest, moregaps) = self.buildnextreg(path[1:], clist) gaps = False if part.startswith(':'): var = part[1:] partreg = '' if self.reqs.has_key(var) and self.defaults.has_key(var) and not moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')?' reg = reg + rest elif self.reqs.has_key(var) and self.defaults.has_key(var) and moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + rest elif self.reqs.has_key(var) and not self.defaults.has_key(var) and moregaps: reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + '(' + rest + ')?' if self.reqs.has_key(var): gaps = True partreg = '(?P<' + var + '>' + self.reqs[var] + ')' elif var == 'controller': gaps = True partreg = '(?P<' + var + '>' + '|'.join(clist) + ')' else: partreg = '(?P<' + var + '>' + default + ')' if self.defaults.has_key(var) and not moregaps: reg = '(/' + partreg + ')?' else: reg = '/' + partreg elif part.startswith('*'): var = part[1:] reg = '(/' + '(?P<' + var + '>.*))*' else: gaps = True reg = '/' + part if moregaps and gaps: reg = '(' + reg + rest + ')?' else: reg = reg + rest return (reg, gaps)
(rest, moregaps) = self.buildnextreg(path[1:], clist) gaps = False
(rest, noreqs, allblank) = self.buildnextreg(path[1:], clist)
def buildnextreg(self, path, clist): default = '[^/]+' part = path[0] reg = '' (rest, moregaps) = ('', False) if len(path[1:]) > 0: (rest, moregaps) = self.buildnextreg(path[1:], clist) gaps = False if part.startswith(':'): var = part[1:] partreg = '' if self.reqs.has_key(var) and self.defaults.has_key(var) and not moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')?' reg = reg + rest elif self.reqs.has_key(var) and self.defaults.has_key(var) and moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + rest elif self.reqs.has_key(var) and not self.defaults.has_key(var) and moregaps: reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + '(' + rest + ')?' if self.reqs.has_key(var): gaps = True partreg = '(?P<' + var + '>' + self.reqs[var] + ')' elif var == 'controller': gaps = True partreg = '(?P<' + var + '>' + '|'.join(clist) + ')' else: partreg = '(?P<' + var + '>' + default + ')' if self.defaults.has_key(var) and not moregaps: reg = '(/' + partreg + ')?' else: reg = '/' + partreg elif part.startswith('*'): var = part[1:] reg = '(/' + '(?P<' + var + '>.*))*' else: gaps = True reg = '/' + part if moregaps and gaps: reg = '(' + reg + rest + ')?' else: reg = reg + rest return (reg, gaps)
if self.reqs.has_key(var) and self.defaults.has_key(var) and not moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')?' reg = reg + rest elif self.reqs.has_key(var) and self.defaults.has_key(var) and moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + rest elif self.reqs.has_key(var) and not self.defaults.has_key(var) and moregaps: reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + '(' + rest + ')?'
def buildnextreg(self, path, clist): default = '[^/]+' part = path[0] reg = '' (rest, moregaps) = ('', False) if len(path[1:]) > 0: (rest, moregaps) = self.buildnextreg(path[1:], clist) gaps = False if part.startswith(':'): var = part[1:] partreg = '' if self.reqs.has_key(var) and self.defaults.has_key(var) and not moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')?' reg = reg + rest elif self.reqs.has_key(var) and self.defaults.has_key(var) and moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + rest elif self.reqs.has_key(var) and not self.defaults.has_key(var) and moregaps: reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + '(' + rest + ')?' if self.reqs.has_key(var): gaps = True partreg = '(?P<' + var + '>' + self.reqs[var] + ')' elif var == 'controller': gaps = True partreg = '(?P<' + var + '>' + '|'.join(clist) + ')' else: partreg = '(?P<' + var + '>' + default + ')' if self.defaults.has_key(var) and not moregaps: reg = '(/' + partreg + ')?' else: reg = '/' + partreg elif part.startswith('*'): var = part[1:] reg = '(/' + '(?P<' + var + '>.*))*' else: gaps = True reg = '/' + part if moregaps and gaps: reg = '(' + reg + rest + ')?' else: reg = reg + rest return (reg, gaps)
gaps = True
def buildnextreg(self, path, clist): default = '[^/]+' part = path[0] reg = '' (rest, moregaps) = ('', False) if len(path[1:]) > 0: (rest, moregaps) = self.buildnextreg(path[1:], clist) gaps = False if part.startswith(':'): var = part[1:] partreg = '' if self.reqs.has_key(var) and self.defaults.has_key(var) and not moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')?' reg = reg + rest elif self.reqs.has_key(var) and self.defaults.has_key(var) and moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + rest elif self.reqs.has_key(var) and not self.defaults.has_key(var) and moregaps: reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + '(' + rest + ')?' if self.reqs.has_key(var): gaps = True partreg = '(?P<' + var + '>' + self.reqs[var] + ')' elif var == 'controller': gaps = True partreg = '(?P<' + var + '>' + '|'.join(clist) + ')' else: partreg = '(?P<' + var + '>' + default + ')' if self.defaults.has_key(var) and not moregaps: reg = '(/' + partreg + ')?' else: reg = '/' + partreg elif part.startswith('*'): var = part[1:] reg = '(/' + '(?P<' + var + '>.*))*' else: gaps = True reg = '/' + part if moregaps and gaps: reg = '(' + reg + rest + ')?' else: reg = reg + rest return (reg, gaps)
partreg = '(?P<' + var + '>' + default + ')' if self.defaults.has_key(var) and not moregaps: reg = '(/' + partreg + ')?'
partreg = '(?P<' + var + '>[^/]+)' if self.reqs.has_key(var): noreqs = False if noreqs: if self.reqs.has_key(var) and self.defaults.has_key(var): reg = '(/' + partreg + rest + ')?' elif self.reqs.has_key(var): allblank = False reg = '(/' + partreg + ')' + rest elif self.defaults.has_key(var): reg = '(/' + partreg + ')?' + rest else: allblank = False reg = '(/' + partreg + ')' + rest
def buildnextreg(self, path, clist): default = '[^/]+' part = path[0] reg = '' (rest, moregaps) = ('', False) if len(path[1:]) > 0: (rest, moregaps) = self.buildnextreg(path[1:], clist) gaps = False if part.startswith(':'): var = part[1:] partreg = '' if self.reqs.has_key(var) and self.defaults.has_key(var) and not moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')?' reg = reg + rest elif self.reqs.has_key(var) and self.defaults.has_key(var) and moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + rest elif self.reqs.has_key(var) and not self.defaults.has_key(var) and moregaps: reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + '(' + rest + ')?' if self.reqs.has_key(var): gaps = True partreg = '(?P<' + var + '>' + self.reqs[var] + ')' elif var == 'controller': gaps = True partreg = '(?P<' + var + '>' + '|'.join(clist) + ')' else: partreg = '(?P<' + var + '>' + default + ')' if self.defaults.has_key(var) and not moregaps: reg = '(/' + partreg + ')?' else: reg = '/' + partreg elif part.startswith('*'): var = part[1:] reg = '(/' + '(?P<' + var + '>.*))*' else: gaps = True reg = '/' + part if moregaps and gaps: reg = '(' + reg + rest + ')?' else: reg = reg + rest return (reg, gaps)
reg = '/' + partreg
if allblank and self.defaults.has_key(var): reg = '(/' + partreg + rest + ')?' else: reg = '/' + partreg + rest
def buildnextreg(self, path, clist): default = '[^/]+' part = path[0] reg = '' (rest, moregaps) = ('', False) if len(path[1:]) > 0: (rest, moregaps) = self.buildnextreg(path[1:], clist) gaps = False if part.startswith(':'): var = part[1:] partreg = '' if self.reqs.has_key(var) and self.defaults.has_key(var) and not moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')?' reg = reg + rest elif self.reqs.has_key(var) and self.defaults.has_key(var) and moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + rest elif self.reqs.has_key(var) and not self.defaults.has_key(var) and moregaps: reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + '(' + rest + ')?' if self.reqs.has_key(var): gaps = True partreg = '(?P<' + var + '>' + self.reqs[var] + ')' elif var == 'controller': gaps = True partreg = '(?P<' + var + '>' + '|'.join(clist) + ')' else: partreg = '(?P<' + var + '>' + default + ')' if self.defaults.has_key(var) and not moregaps: reg = '(/' + partreg + ')?' else: reg = '/' + partreg elif part.startswith('*'): var = part[1:] reg = '(/' + '(?P<' + var + '>.*))*' else: gaps = True reg = '/' + part if moregaps and gaps: reg = '(' + reg + rest + ')?' else: reg = reg + rest return (reg, gaps)
reg = '(/' + '(?P<' + var + '>.*))*'
reg = '(/' + '(?P<' + var + '>.*))*' + rest
def buildnextreg(self, path, clist): default = '[^/]+' part = path[0] reg = '' (rest, moregaps) = ('', False) if len(path[1:]) > 0: (rest, moregaps) = self.buildnextreg(path[1:], clist) gaps = False if part.startswith(':'): var = part[1:] partreg = '' if self.reqs.has_key(var) and self.defaults.has_key(var) and not moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')?' reg = reg + rest elif self.reqs.has_key(var) and self.defaults.has_key(var) and moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + rest elif self.reqs.has_key(var) and not self.defaults.has_key(var) and moregaps: reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + '(' + rest + ')?' if self.reqs.has_key(var): gaps = True partreg = '(?P<' + var + '>' + self.reqs[var] + ')' elif var == 'controller': gaps = True partreg = '(?P<' + var + '>' + '|'.join(clist) + ')' else: partreg = '(?P<' + var + '>' + default + ')' if self.defaults.has_key(var) and not moregaps: reg = '(/' + partreg + ')?' else: reg = '/' + partreg elif part.startswith('*'): var = part[1:] reg = '(/' + '(?P<' + var + '>.*))*' else: gaps = True reg = '/' + part if moregaps and gaps: reg = '(' + reg + rest + ')?' else: reg = reg + rest return (reg, gaps)
gaps = True reg = '/' + part if moregaps and gaps: reg = '(' + reg + rest + ')?' else: reg = reg + rest return (reg, gaps)
noreqs = False allblank = False reg = '/' + part + rest return (reg, noreqs, allblank)
def buildnextreg(self, path, clist): default = '[^/]+' part = path[0] reg = '' (rest, moregaps) = ('', False) if len(path[1:]) > 0: (rest, moregaps) = self.buildnextreg(path[1:], clist) gaps = False if part.startswith(':'): var = part[1:] partreg = '' if self.reqs.has_key(var) and self.defaults.has_key(var) and not moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')?' reg = reg + rest elif self.reqs.has_key(var) and self.defaults.has_key(var) and moregaps: gaps = True reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + rest elif self.reqs.has_key(var) and not self.defaults.has_key(var) and moregaps: reg = '(/(?P<' + var + '>' + self.reqs[var] + ')' reg = reg + '(' + rest + ')?' if self.reqs.has_key(var): gaps = True partreg = '(?P<' + var + '>' + self.reqs[var] + ')' elif var == 'controller': gaps = True partreg = '(?P<' + var + '>' + '|'.join(clist) + ')' else: partreg = '(?P<' + var + '>' + default + ')' if self.defaults.has_key(var) and not moregaps: reg = '(/' + partreg + ')?' else: reg = '/' + partreg elif part.startswith('*'): var = part[1:] reg = '(/' + '(?P<' + var + '>.*))*' else: gaps = True reg = '/' + part if moregaps and gaps: reg = '(' + reg + rest + ')?' else: reg = reg + rest return (reg, gaps)
if environ.get('SERVER_PORT', 80) != 80: self.__shared_state.host += ':' + environ['SERVER_PORT']
self.__shared_state.host += port_info
def load_wsgi_environ(self, environ): """ Load the protocol/server info from the environ and store it. Also, match the incoming URL if there's already a mapper, and store the resulting match dict in mapper_dict. """ if environ.get('HTTPS'): self.__shared_state.protocol = 'https' else: self.__shared_state.protocol = 'http' if hasattr(self, 'mapper'): self.mapper.environ = environ if 'PATH_INFO' in environ and hasattr(self, 'mapper'): mapper = self.mapper path = environ['PATH_INFO'] self.__shared_state.mapper_dict = mapper.match(path) host = environ.get('HTTP_HOST') or environ.get('SERVER_NAME') self.__shared_state.host = host.split(':')[0] if environ.get('SERVER_PORT', 80) != 80: self.__shared_state.host += ':' + environ['SERVER_PORT']
primary = (method != 'GET' and lst.pop(0)) or None
if method not in ['POST', 'GET', 'any']: primary = lst.pop(0) else: primary = None
def requirements_for(meth): """Returns a new dict to be used for all route creation as the route options""" opts = options.copy() if method != 'any': opts['conditions'] = {'method':[meth]} return opts
return self.not_found(environ, start_response)
match = {}
def __call__(self, environ, start_response): config = request_config() config.mapper = self.mapper old_method = None if self.use_method_override: req = WSGIRequest(environ) if '_method' in environ.get('QUERY_STRING', '') and '_method' in req.GET: old_method = environ['REQUEST_METHOD'] environ['REQUEST_METHOD'] = req.GET['_method'] elif environ['REQUEST_METHOD'] == 'POST' and '_method' in req.POST: old_method = environ['REQUEST_METHOD'] environ['REQUEST_METHOD'] = req.POST['_method'] config.environ = environ match = config.mapper_dict if old_method: environ['REQUEST_METHOD'] = old_method if not match: return self.not_found(environ, start_response) for k,v in match.iteritems(): if v: match[k] = urllib.unquote_plus(v) environ['wsgiorg.routing_args'] = ((), match)
def not_found(self, environ, start_response): start_response('404 Not Found', [('Content-type', 'text/plain')]) return ['Not found']
def __call__(self, environ, start_response): config = request_config() config.mapper = self.mapper old_method = None if self.use_method_override: req = WSGIRequest(environ) if '_method' in environ.get('QUERY_STRING', '') and '_method' in req.GET: old_method = environ['REQUEST_METHOD'] environ['REQUEST_METHOD'] = req.GET['_method'] elif environ['REQUEST_METHOD'] == 'POST' and '_method' in req.POST: old_method = environ['REQUEST_METHOD'] environ['REQUEST_METHOD'] = req.POST['_method'] config.environ = environ match = config.mapper_dict if old_method: environ['REQUEST_METHOD'] = old_method if not match: return self.not_found(environ, start_response) for k,v in match.iteritems(): if v: match[k] = urllib.unquote_plus(v) environ['wsgiorg.routing_args'] = ((), match)
self.conditions['method'] != environ.get('HTTP_METHOD'):
self.conditions['method'] != environ.get('REQUEST_METHOD'):
def match(self, url, environ=None): """Match a url to our regexp. While the regexp might match, this operation isn't guaranteed as there's other factors that can cause a match to fail even though the regexp succeeds (Default that was relied on wasn't given, requirement regexp doesn't pass, etc.). Therefore the calling function shouldn't assume this will return a valid dict, the other possible return is False if a match doesn't work out. """ # Static routes don't match, they generate only if self.static: return False if url.endswith('/') and len(url) > 1: url = url[:-1] m = self.regmatch.match(url) if not m: return False if not environ: environ = {} if self.conditions: if self.conditions.has_key('method') and \ self.conditions['method'] != environ.get('HTTP_METHOD'): return False matchdict = m.groupdict() result = {} extras = frozenset(self.defaults.keys()) - frozenset(matchdict.keys()) for key,val in matchdict.iteritems(): if not val and self.defaults.has_key(key) and self.defaults[key]: result[key] = self.defaults[key] else: result[key] = val for key in extras: result[key] = self.defaults[key] # If there's a function, call it with environ and expire if it # returns False if self.conditions and self.conditions.has_key('function') and \ not self.conditions['function'](environ, result): return False return result
for key in self.reqs.keys(): if key not in matchdict.keys() or matchdict[key] is None: try: result[key] = self.defaults[key] except: return False else: value = matchdict[key] or (self.defaults.has_key(key) and self.defaults[key]) or '' if not re.compile('^' + self.reqs[key] + '$').match(value): return False
def match(self, url): """Match a url to our regexp. While the regexp might match, this operation isn't guaranteed as there's other factors that can cause a match to fail even though the regexp succeeds (Default that was relied on wasn't given, requirement regexp doesn't pass, etc.). Therefore the calling function shouldn't assume this will return a valid dict, the other possible return is False if a match doesn't work out. """ # Static routes don't match, they generate only if self.static: return False if url.endswith('/') and len(url) > 1: url = url[:-1] m = self.regmatch.match(url) if m: matchdict = m.groupdict() result = {} extras = frozenset(self.defaults.keys()) - frozenset(matchdict.keys()) for key in self.reqs.keys(): if key not in matchdict.keys() or matchdict[key] is None: try: result[key] = self.defaults[key] except: return False else: value = matchdict[key] or (self.defaults.has_key(key) and self.defaults[key]) or '' if not re.compile('^' + self.reqs[key] + '$').match(value): return False for key,val in matchdict.iteritems(): if not val and self.defaults.has_key(key) and self.defaults[key]: result[key] = self.defaults[key] else: result[key] = val for key in extras: result[key] = self.defaults[key] return result else: return False
if match: return (match, route) return None
if self.debug: matchlog.append(dict(route=route, regexp=bool(match))) if match: return (match, route, matchlog) return (None, None, matchlog)
def _match(self, url): """Internal Route matcher Matches a URL against a route, and returns a tuple of the match dict and the route object if a match is successfull, otherwise it returns empty. For internal use only. """ if not self._created_regs and self.controller_scan: self.create_regs() elif not self._created_regs: raise RouteException, "You must generate the regular expressions before matching." if self.always_scan: self.create_regs() for route in self.matchlist: if self.prefix: if re.match(self._regprefix, url): url = re.sub(self._regprefix, r'\1', url) else: continue match = route.match(url) if match: return (match, route) return None
if result:
if self.debug: return result[0], result[1], result[2] if result[0]:
def match(self, url): """Match a URL against against one of the routes contained. Will return None if no valid match is found. resultdict = m.match('/joe/sixpack') """ result = self._match(url) if result: return result[0] return None
if result:
if self.debug: return result[0], result[1], result[2] if result[0]:
def routematch(self, url): """Match a URL against against one of the routes contained. Will return None if no valid match is found, otherwise a result dict and a route object is returned. resultdict, route_obj = m.match('/joe/sixpack') """ result = self._match(url) if result: return result[0], result[1] return None
self.connect("formatted_" + route_name, "%s.:(format);%s")
self.connect("formatted_" + route_name, "%s.:(format);%s" % (collection_path, action))
def requirements_for(meth): """Returns a new dict to be used for all route creation as the route options""" opts = options.copy() if method != 'any': opts['conditions'] = {'method':[meth.upper()]} return opts
controllers.sort(cmp=longest_first)
controllers.sort(longest_first)
def longest_first(a, b): return cmp(len(b), len(a))
if environ.get('SERVER_PORT') != '80':
if environ.get('SERVER_PORT', '80') != '80':
def load_wsgi_environ(self, environ): """ Load the protocol/server info from the environ and store it. Also, match the incoming URL if there's already a mapper, and store the resulting match dict in mapper_dict. """ port_info = '' if environ.get('HTTPS'): self.__shared_state.protocol = 'https' if environ.get('SERVER_PORT') != '443': port_info += ':' + environ['SERVER_PORT'] else: self.__shared_state.protocol = 'http' if environ.get('SERVER_PORT') != '80': port_info += ':' + environ.get('SERVER_PORT', '80') if hasattr(self, 'mapper'): self.mapper.environ = environ if 'PATH_INFO' in environ and hasattr(self, 'mapper'): mapper = self.mapper path = environ['PATH_INFO'] self.__shared_state.mapper_dict = mapper.match(path) host = environ.get('HTTP_HOST') or environ.get('SERVER_NAME') self.__shared_state.host = host.split(':')[0] self.__shared_state.host += port_info
if meth: kargs['_method'] = meth if meth not in self.conditions.get('method', [meth]): return False
if meth: kargs['_method'] = meth
def generate(self,**kargs): """Generate a URL from ourself given a set of keyword arguments Toss an exception if this set of keywords would cause a gap in the url. """ # Verify that our args pass any regexp requirements for key in self.reqs.keys(): val = kargs.get(key) if val and not self.req_regs[key].match(str(val)): return False # Verify that if we have a method arg, its in the method accept list. Also, method # will be changed to _method for route generation meth = kargs.pop('method', None) if meth: kargs['_method'] = meth if meth not in self.conditions.get('method', [meth]): return False routelist = self.routebackwards urllist = [] gaps = False for part in routelist: if isinstance(part, dict) and part['type'] == ':': arg = part['name'] # For efficiency, check these just once has_arg = kargs.has_key(arg) has_default = self.defaults.has_key(arg) # Determine if we can leave this part off # First check if the default exists and wasn't provided in the call (also no gaps) if has_default and not has_arg and not gaps: continue # Now check to see if there's a default and it matches the incoming call arg if (has_default and has_arg) and str(kargs[arg]) == str(self.defaults[arg]) and not gaps: continue # We need to pull the value to append, if the arg is None and we have a default, use that if has_arg and kargs[arg] is None and has_default and not gaps: continue # Otherwise if we do have an arg, use that elif has_arg: val = kargs[arg] elif has_default and self.defaults[arg] is not None: val = self.defaults[arg] # No arg at all? This won't work else: return False urllist.append(url_quote(val)) if has_arg: del kargs[arg] gaps = True elif isinstance(part, dict) and part['type'] == '*': arg = part['name'] kar = kargs.get(arg) if kar is not None: urllist.append(url_quote(kar)) gaps = True elif part.endswith('/'): if not gaps and part == '/': continue elif not gaps: urllist.append(part[:-1]) gaps = True else: gaps = True urllist.append(part) else: gaps = True urllist.append(part) urllist.reverse() url = ''.join(urllist) if not url.startswith('/'): url = '/' + url extras = frozenset(kargs.keys()) - self.maxkeys if extras: url += '?' url += urllib.urlencode([(key, kargs[key]) for key in extras if key != 'action' or key != 'controller']) return url
new_path = path_prefix + "/new" member_path = path_prefix + "/:id"
new_path = path + "/new" member_path = path + "/:(id)"
def swap(dct, newdct): for key, val in dct.iteritems(): newdct.setdefault(val, []).append(key) return newdct
opts['conditions'] = {'method':meth}
opts['conditions'] = {'method':[meth]}
def requirements_for(meth): opts = options.copy() if method != 'any': opts['conditions'] = {'method':meth} return opts
self.connect("formatted_" + route_name, "%s.:(format);%s")
self.connect("formatted_" + route_name, "%s\.:(format);%s")
def requirements_for(meth): opts = options.copy() if method != 'any': opts['conditions'] = {'method':meth} return opts
self.connect("%s.:(format)" % collection_path, **route_options)
self.connect("%s\.:(format)" % collection_path, **route_options)
def requirements_for(meth): opts = options.copy() if method != 'any': opts['conditions'] = {'method':meth} return opts
conditions={'method':'GET'}, **options)
conditions={'method':['GET']}, **options)
def requirements_for(meth): opts = options.copy() if method != 'any': opts['conditions'] = {'method':meth} return opts
collection_path + ".:(format)", action='index', conditions={'method':'GET'}, **options)
collection_path + "\.:(format)", action='index', conditions={'method':['GET']}, **options)
def requirements_for(meth): opts = options.copy() if method != 'any': opts['conditions'] = {'method':meth} return opts
path = (action == 'new' and action + '.:(format)') or \ "%s.:(format);%s" % (new_path, action)
path = (action == 'new' and new_path + '\.:(format)') or \ "%s\.:(format);%s" % (new_path, action)
def requirements_for(meth): opts = options.copy() if method != 'any': opts['conditions'] = {'method':meth} return opts
"%s.:(format);%s" % (member_path, action), **route_options)
"%s\.:(format);%s" % (member_path, action), **route_options)
def requirements_for(meth): opts = options.copy() if method != 'any': opts['conditions'] = {'method':meth} return opts
hostmatch = config.environ['HTTP_HOST'].split(':')
fullhost = config.environ.get('HTTP_HOST') or config.environ.get('SERVER_NAME') hostmatch = fullhost.split(':')
def _subdomain_check(config, kargs): if config.mapper.sub_domains: subdomain = kargs.pop('sub_domain', None) hostmatch = config.environ['HTTP_HOST'].split(':') host = hostmatch[0] port = '' if len(hostmatch) > 1: port += ':' + hostmatch[1] sub_match = re.compile('^.+?\.(%s)$' % config.mapper.domain_match) domain = re.sub(sub_match, r'\1', host) if subdomain and not host.startswith(subdomain) and \ subdomain not in config.mapper.sub_domains_ignore: kargs['_host'] = subdomain + '.' + domain + port elif (subdomain in config.mapper.sub_domains_ignore or subdomain is None) and domain != host: kargs['_host'] = domain + port return kargs else: return kargs
controllers.extend(find_controllers(filename, prefix=fname+'/'))
controllers.extend(find_controllers(filename, prefix=prefix+fname+'/'))
def find_controllers(dirname, prefix=''): controllers = [] for fname in os.listdir(dirname): filename = dirname + '/' + fname if os.path.isfile(filename) and re.match('^[^_]{1,1}.*\.py$', fname): controllers.append(prefix + fname[:-3]) elif os.path.isdir(filename): controllers.extend(find_controllers(filename, prefix=fname+'/')) return controllers
class RouteConfig(threadinglocal.local): pass
def keysort(a, b): am = a.minkeys a = a.maxkeys b = b.maxkeys lendiffa = len(keys^a) lendiffb = len(keys^b) # If they both match, don't switch them if lendiffa == 0 and lendiffb == 0: return 0 # First, if a matches exactly, use it if lendiffa == 0: return -1 # Or b matches exactly, use it if lendiffb == 0: return 1 # Neither matches exactly, return the one with the most in common if cmp(lendiffa,lendiffb) != 0: return cmp(lendiffa,lendiffb) # Neither matches exactly, but if they both have just as much in common if len(keys&b) == len(keys&a): return cmp(len(a),len(b)) # Then we return the shortest of the two # Otherwise, we return the one that has the most in common else: return cmp(len(keys&b), len(keys&a))
_shared_state = RouteConfig()
__shared_state = threadinglocal.local()
def keysort(a, b): am = a.minkeys a = a.maxkeys b = b.maxkeys lendiffa = len(keys^a) lendiffb = len(keys^b) # If they both match, don't switch them if lendiffa == 0 and lendiffb == 0: return 0 # First, if a matches exactly, use it if lendiffa == 0: return -1 # Or b matches exactly, use it if lendiffb == 0: return 1 # Neither matches exactly, return the one with the most in common if cmp(lendiffa,lendiffb) != 0: return cmp(lendiffa,lendiffb) # Neither matches exactly, but if they both have just as much in common if len(keys&b) == len(keys&a): return cmp(len(a),len(b)) # Then we return the shortest of the two # Otherwise, we return the one that has the most in common else: return cmp(len(keys&b), len(keys&a))
return self._shared_state.__getattr__(name)
return self.__shared_state.__getattr__(name)
def __getattr__(self, name): return self._shared_state.__getattr__(name)
return self._shared_state.__setattr__(name, value)
return self.__shared_state.__setattr__(name, value)
def __setattr__(self, name, value): return self._shared_state.__setattr__(name, value)
newargs = route.defaults.copy() host = newargs.pop('host', '') protocol = newargs.pop('protocol', '') del newargs['_static'] newargs.update(kargs) url = route.generate(_ignore_req_list=True, **newargs) if not url: url = '' kargs = None
url = route.routepath
def url_for(*args, **kargs): """Generates a URL All keys given to url_for are sent to the Routes Mapper instance for generation except for:: anchor specified the anchor name to be appened to the path host overrides the default (current) host if provided protocol overrides the default (current) protocol if provided The URL is generated based on the rest of the keys. When generating a new URL, values will be used from the current request's parameters (if present). The following rules are used to determine when and how to keep the current requests parameters: * If the controller is present and begins with '/', no defaults are used * If the controller is changed, action is set to 'index' unless otherwise specified For example, if the current request yielded a dict of {'controller': 'blog', 'action': 'view', 'id': 2}, with the standard ':controller/:action/:id' route, you'd get the following results:: url_for(id=4) => '/blog/view/4', url_for(controller='/admin') => '/admin', url_for(controller='admin') => '/admin/index/4' url_for(action='edit') => '/blog/post/4', url_for(action='list', id=None) => '/blog/list' **Static and Named Routes** If there is a string present as the first argument, a lookup is done against the named routes table to see if there's any matching routes. The keyword defaults used with static routes will be sent in as GET query arg's if a route matches. If no route by that name is found, the string is assumed to be a raw URL. Should the raw URL begin with ``/`` then appropriate SCRIPT_NAME data will be added if present, otherwise the string will be used as the url with keyword args becoming GET query args. """ anchor = kargs.get('anchor') host = kargs.get('host') protocol = kargs.get('protocol') # Remove special words from kargs, convert placeholders for key in ['anchor', 'host', 'protocol']: if kargs.get(key): del kargs[key] if kargs.has_key(key+'_'): kargs[key] = kargs[key+'_'] del kargs[key+'_'] config = request_config() route = None static = False url = '' if len(args) > 0: route = config.mapper._routenames.get(args[0]) if route and route.defaults.has_key('_static'): static = True newargs = route.defaults.copy() host = newargs.pop('host', '') protocol = newargs.pop('protocol', '') del newargs['_static'] newargs.update(kargs) url = route.generate(_ignore_req_list=True, **newargs) if not url: url = '' kargs = None #url = route.routepath # No named route found, assume the argument is a relative path if not route: static = True url = args[0] if url.startswith('/') and hasattr(config, 'environ') \ and config.environ.get('SCRIPT_NAME'): url = config.environ.get('SCRIPT_NAME') + url if static: if kargs: url += '?' url += urllib.urlencode(kargs) if not static: if route: newargs = route.defaults.copy() newargs.update(kargs) # If this route has a filter, apply it if route.filter: newargs = route.filter(newargs) else: newargs = _screenargs(kargs) url = config.mapper.generate(**newargs) if config.mapper.append_slash and not url.endswith('/'): url += '/' if anchor: url += '#' + _url_quote(anchor) if host or protocol: if not host: host = config.host if not protocol: protocol = config.protocol url = protocol + '://' + host + url return url
if isinsance(use_sd, list) and sub_domain not in use_sd:
if isinstance(use_sd, list) and sub_domain not in use_sd:
def match(self, url, environ=None, sub_domains=False, sub_domains_ignore=None, domain_match=''): """Match a url to our regexp. While the regexp might match, this operation isn't guaranteed as there's other factors that can cause a match to fail even though the regexp succeeds (Default that was relied on wasn't given, requirement regexp doesn't pass, etc.). Therefore the calling function shouldn't assume this will return a valid dict, the other possible return is False if a match doesn't work out. """ # Static routes don't match, they generate only if self.static: return False if url.endswith('/') and len(url) > 1: url = url[:-1] m = self.regmatch.match(url) if not m: return False if not environ: environ = {} sub_domain = None if environ.get('HTTP_HOST') and sub_domains: host = environ['HTTP_HOST'].split(':')[0] sub_match = re.compile('^(.+?)\.%s$' % domain_match) subdomain = re.sub(sub_match, r'\1', host) if subdomain not in sub_domains_ignore and host != subdomain: sub_domain = subdomain if self.conditions: if self.conditions.has_key('method') and \ environ.get('REQUEST_METHOD') not in self.conditions['method']: return False # Check sub-domains? use_sd = self.conditions.get('sub_domain') if use_sd and not sub_domain: return False if isinsance(use_sd, list) and sub_domain not in use_sd: return False matchdict = m.groupdict() result = {} extras = frozenset(self.defaults.keys()) - frozenset(matchdict.keys()) for key,val in matchdict.iteritems(): if not val and self.defaults.has_key(key) and self.defaults[key]: result[key] = self.defaults[key] else: result[key] = val for key in extras: result[key] = self.defaults[key] # If there's a function, call it with environ and expire if it # returns False if self.conditions and self.conditions.has_key('function') and \ not self.conditions['function'](environ, result): return False if sub_domain: result['sub_domain'] = sub_domain return result
var = part['name']
var = re.escape(part['name'])
def buildnextreg(self, path, clist): """Recursively build our regexp given a path, and a controller list. Returns the regular expression string, and two booleans that can be ignored as they're only used internally by buildnextreg """ if path: part = path[0] else: part = '' reg = '' # noreqs will remember whether the remainder has either a string match, or a non-defaulted # regexp match on a key, allblank remembers if the rest could possible be completely empty (rest, noreqs, allblank) = ('', True, True) if len(path[1:]) > 0: (rest, noreqs, allblank) = self.buildnextreg(path[1:], clist) if isinstance(part, dict) and part['type'] == ':': var = part['name'] partreg = '' # First we plug in the proper part matcher if self.reqs.has_key(var): partreg = '(?P<' + var + '>' + self.reqs[var] + ')' elif var == 'controller': partreg = '(?P<' + var + '>' + '|'.join(clist) + ')' else: if len(path) > 1: partreg = '(?P<' + var + '>[^' + path[1][0] +']+)' else: partreg = '(?P<' + var + '>[^/]+)' if self.reqs.has_key(var): noreqs = False if not self.defaults.has_key(var): allblank = False noreqs = False # Now we determine if its optional, or required. This changes depending on what is in # the rest of the match. If noreqs is true, then its possible the entire thing is optional # as there's no reqs or string matches. if noreqs: # The rest is optional, but now we have an optional with a regexp. Wrap to ensure that if we match # anything, we match our regexp first. It's still possible we could be completely blank as we have # a default if self.reqs.has_key(var) and self.defaults.has_key(var): reg = '(' + partreg + rest + ')?' # Or we have a regexp match with no default, so now being completely blank form here on out isn't # possible elif self.reqs.has_key(var): allblank = False reg = partreg + rest # Or we have a default with no regexp, don't touch the allblank elif self.defaults.has_key(var): reg = partreg + '?' + rest # Or we have a key with no default, and no reqs. Not possible to be all blank from here else: allblank = False reg = partreg + rest # In this case, we have something dangling that might need to be matched else: # If they can all be blank, and we have a default here, we know its # safe to make everything from here optional. Since something else in # the chain does have req's though, we have to make the partreg here # required to continue matching if allblank and self.defaults.has_key(var): reg = '(' + partreg + rest + ')?' # Same as before, but they can't all be blank, so we have to require it all to ensure # our matches line up right else: reg = partreg + rest elif isinstance(part, dict) and part['type'] == '*': var = part['name'] if noreqs: if self.defaults.has_key(var): reg = '(?P<' + var + '>.*)' + rest else: reg = '(?P<' + var + '>.*)' + rest allblank = False noreqs = False else: if allblank and self.defaults.has_key(var): reg = '(?P<' + var + '>.*)' + rest elif self.defaults.has_key(var): reg = '(?P<' + var + '>.*)' + rest else: allblank = False noreqs = False reg = '(?P<' + var + '>.*)' + rest elif part.endswith('/'): if allblank: reg = part[:-1] + '(/' + rest + ')?' else: allblank = False reg = part + rest # We have a normal string here, this is a req, and it prevents us from being all blank else: noreqs = False allblank = False reg = part + rest return (reg, noreqs, allblank)
partreg = '(?P<' + var + '>' + '|'.join(clist) + ')'
partreg = '(?P<' + var + '>' + '|'.join(map(re.escape, clist)) + ')'
def buildnextreg(self, path, clist): """Recursively build our regexp given a path, and a controller list. Returns the regular expression string, and two booleans that can be ignored as they're only used internally by buildnextreg """ if path: part = path[0] else: part = '' reg = '' # noreqs will remember whether the remainder has either a string match, or a non-defaulted # regexp match on a key, allblank remembers if the rest could possible be completely empty (rest, noreqs, allblank) = ('', True, True) if len(path[1:]) > 0: (rest, noreqs, allblank) = self.buildnextreg(path[1:], clist) if isinstance(part, dict) and part['type'] == ':': var = part['name'] partreg = '' # First we plug in the proper part matcher if self.reqs.has_key(var): partreg = '(?P<' + var + '>' + self.reqs[var] + ')' elif var == 'controller': partreg = '(?P<' + var + '>' + '|'.join(clist) + ')' else: if len(path) > 1: partreg = '(?P<' + var + '>[^' + path[1][0] +']+)' else: partreg = '(?P<' + var + '>[^/]+)' if self.reqs.has_key(var): noreqs = False if not self.defaults.has_key(var): allblank = False noreqs = False # Now we determine if its optional, or required. This changes depending on what is in # the rest of the match. If noreqs is true, then its possible the entire thing is optional # as there's no reqs or string matches. if noreqs: # The rest is optional, but now we have an optional with a regexp. Wrap to ensure that if we match # anything, we match our regexp first. It's still possible we could be completely blank as we have # a default if self.reqs.has_key(var) and self.defaults.has_key(var): reg = '(' + partreg + rest + ')?' # Or we have a regexp match with no default, so now being completely blank form here on out isn't # possible elif self.reqs.has_key(var): allblank = False reg = partreg + rest # Or we have a default with no regexp, don't touch the allblank elif self.defaults.has_key(var): reg = partreg + '?' + rest # Or we have a key with no default, and no reqs. Not possible to be all blank from here else: allblank = False reg = partreg + rest # In this case, we have something dangling that might need to be matched else: # If they can all be blank, and we have a default here, we know its # safe to make everything from here optional. Since something else in # the chain does have req's though, we have to make the partreg here # required to continue matching if allblank and self.defaults.has_key(var): reg = '(' + partreg + rest + ')?' # Same as before, but they can't all be blank, so we have to require it all to ensure # our matches line up right else: reg = partreg + rest elif isinstance(part, dict) and part['type'] == '*': var = part['name'] if noreqs: if self.defaults.has_key(var): reg = '(?P<' + var + '>.*)' + rest else: reg = '(?P<' + var + '>.*)' + rest allblank = False noreqs = False else: if allblank and self.defaults.has_key(var): reg = '(?P<' + var + '>.*)' + rest elif self.defaults.has_key(var): reg = '(?P<' + var + '>.*)' + rest else: allblank = False noreqs = False reg = '(?P<' + var + '>.*)' + rest elif part.endswith('/'): if allblank: reg = part[:-1] + '(/' + rest + ')?' else: allblank = False reg = part + rest # We have a normal string here, this is a req, and it prevents us from being all blank else: noreqs = False allblank = False reg = part + rest return (reg, noreqs, allblank)
reg = part[:-1] + '(/' + rest + ')?'
reg = re.escape(part[:-1]) + '(/' + rest + ')?'
def buildnextreg(self, path, clist): """Recursively build our regexp given a path, and a controller list. Returns the regular expression string, and two booleans that can be ignored as they're only used internally by buildnextreg """ if path: part = path[0] else: part = '' reg = '' # noreqs will remember whether the remainder has either a string match, or a non-defaulted # regexp match on a key, allblank remembers if the rest could possible be completely empty (rest, noreqs, allblank) = ('', True, True) if len(path[1:]) > 0: (rest, noreqs, allblank) = self.buildnextreg(path[1:], clist) if isinstance(part, dict) and part['type'] == ':': var = part['name'] partreg = '' # First we plug in the proper part matcher if self.reqs.has_key(var): partreg = '(?P<' + var + '>' + self.reqs[var] + ')' elif var == 'controller': partreg = '(?P<' + var + '>' + '|'.join(clist) + ')' else: if len(path) > 1: partreg = '(?P<' + var + '>[^' + path[1][0] +']+)' else: partreg = '(?P<' + var + '>[^/]+)' if self.reqs.has_key(var): noreqs = False if not self.defaults.has_key(var): allblank = False noreqs = False # Now we determine if its optional, or required. This changes depending on what is in # the rest of the match. If noreqs is true, then its possible the entire thing is optional # as there's no reqs or string matches. if noreqs: # The rest is optional, but now we have an optional with a regexp. Wrap to ensure that if we match # anything, we match our regexp first. It's still possible we could be completely blank as we have # a default if self.reqs.has_key(var) and self.defaults.has_key(var): reg = '(' + partreg + rest + ')?' # Or we have a regexp match with no default, so now being completely blank form here on out isn't # possible elif self.reqs.has_key(var): allblank = False reg = partreg + rest # Or we have a default with no regexp, don't touch the allblank elif self.defaults.has_key(var): reg = partreg + '?' + rest # Or we have a key with no default, and no reqs. Not possible to be all blank from here else: allblank = False reg = partreg + rest # In this case, we have something dangling that might need to be matched else: # If they can all be blank, and we have a default here, we know its # safe to make everything from here optional. Since something else in # the chain does have req's though, we have to make the partreg here # required to continue matching if allblank and self.defaults.has_key(var): reg = '(' + partreg + rest + ')?' # Same as before, but they can't all be blank, so we have to require it all to ensure # our matches line up right else: reg = partreg + rest elif isinstance(part, dict) and part['type'] == '*': var = part['name'] if noreqs: if self.defaults.has_key(var): reg = '(?P<' + var + '>.*)' + rest else: reg = '(?P<' + var + '>.*)' + rest allblank = False noreqs = False else: if allblank and self.defaults.has_key(var): reg = '(?P<' + var + '>.*)' + rest elif self.defaults.has_key(var): reg = '(?P<' + var + '>.*)' + rest else: allblank = False noreqs = False reg = '(?P<' + var + '>.*)' + rest elif part.endswith('/'): if allblank: reg = part[:-1] + '(/' + rest + ')?' else: allblank = False reg = part + rest # We have a normal string here, this is a req, and it prevents us from being all blank else: noreqs = False allblank = False reg = part + rest return (reg, noreqs, allblank)
reg = part + rest
reg = re.escape(part) + rest
def buildnextreg(self, path, clist): """Recursively build our regexp given a path, and a controller list. Returns the regular expression string, and two booleans that can be ignored as they're only used internally by buildnextreg """ if path: part = path[0] else: part = '' reg = '' # noreqs will remember whether the remainder has either a string match, or a non-defaulted # regexp match on a key, allblank remembers if the rest could possible be completely empty (rest, noreqs, allblank) = ('', True, True) if len(path[1:]) > 0: (rest, noreqs, allblank) = self.buildnextreg(path[1:], clist) if isinstance(part, dict) and part['type'] == ':': var = part['name'] partreg = '' # First we plug in the proper part matcher if self.reqs.has_key(var): partreg = '(?P<' + var + '>' + self.reqs[var] + ')' elif var == 'controller': partreg = '(?P<' + var + '>' + '|'.join(clist) + ')' else: if len(path) > 1: partreg = '(?P<' + var + '>[^' + path[1][0] +']+)' else: partreg = '(?P<' + var + '>[^/]+)' if self.reqs.has_key(var): noreqs = False if not self.defaults.has_key(var): allblank = False noreqs = False # Now we determine if its optional, or required. This changes depending on what is in # the rest of the match. If noreqs is true, then its possible the entire thing is optional # as there's no reqs or string matches. if noreqs: # The rest is optional, but now we have an optional with a regexp. Wrap to ensure that if we match # anything, we match our regexp first. It's still possible we could be completely blank as we have # a default if self.reqs.has_key(var) and self.defaults.has_key(var): reg = '(' + partreg + rest + ')?' # Or we have a regexp match with no default, so now being completely blank form here on out isn't # possible elif self.reqs.has_key(var): allblank = False reg = partreg + rest # Or we have a default with no regexp, don't touch the allblank elif self.defaults.has_key(var): reg = partreg + '?' + rest # Or we have a key with no default, and no reqs. Not possible to be all blank from here else: allblank = False reg = partreg + rest # In this case, we have something dangling that might need to be matched else: # If they can all be blank, and we have a default here, we know its # safe to make everything from here optional. Since something else in # the chain does have req's though, we have to make the partreg here # required to continue matching if allblank and self.defaults.has_key(var): reg = '(' + partreg + rest + ')?' # Same as before, but they can't all be blank, so we have to require it all to ensure # our matches line up right else: reg = partreg + rest elif isinstance(part, dict) and part['type'] == '*': var = part['name'] if noreqs: if self.defaults.has_key(var): reg = '(?P<' + var + '>.*)' + rest else: reg = '(?P<' + var + '>.*)' + rest allblank = False noreqs = False else: if allblank and self.defaults.has_key(var): reg = '(?P<' + var + '>.*)' + rest elif self.defaults.has_key(var): reg = '(?P<' + var + '>.*)' + rest else: allblank = False noreqs = False reg = '(?P<' + var + '>.*)' + rest elif part.endswith('/'): if allblank: reg = part[:-1] + '(/' + rest + ')?' else: allblank = False reg = part + rest # We have a normal string here, this is a req, and it prevents us from being all blank else: noreqs = False allblank = False reg = part + rest return (reg, noreqs, allblank)
self.connect("formatted_" + route_name, "%s\.:(format);%s")
self.connect("formatted_" + route_name, "%s.:(format);%s")
def requirements_for(meth): """Returns a new dict to be used for all route creation as the route options""" opts = options.copy() if method != 'any': opts['conditions'] = {'method':[meth]} return opts
self.connect("%s\.:(format)" % collection_path, **route_options)
self.connect("%s.:(format)" % collection_path, **route_options)
def requirements_for(meth): """Returns a new dict to be used for all route creation as the route options""" opts = options.copy() if method != 'any': opts['conditions'] = {'method':[meth]} return opts
collection_path + "\.:(format)", action='index',
collection_path + ".:(format)", action='index',
def requirements_for(meth): """Returns a new dict to be used for all route creation as the route options""" opts = options.copy() if method != 'any': opts['conditions'] = {'method':[meth]} return opts
path = (action == 'new' and new_path + '\.:(format)') or \ "%s\.:(format);%s" % (new_path, action)
path = (action == 'new' and new_path + '.:(format)') or \ "%s.:(format);%s" % (new_path, action)
def requirements_for(meth): """Returns a new dict to be used for all route creation as the route options""" opts = options.copy() if method != 'any': opts['conditions'] = {'method':[meth]} return opts
"%s\.:(format);%s" % (member_path, action), **route_options)
"%s.:(format);%s" % (member_path, action), **route_options)
def requirements_for(meth): """Returns a new dict to be used for all route creation as the route options""" opts = options.copy() if method != 'any': opts['conditions'] = {'method':[meth]} return opts
for extrastyle in list(layer.wmsextrastyles):
for extrastyle in [layer.wmsdefaultstyle] + list(layer.wmsextrastyles):
def __init__(self, conf, mapfactory, opsonlineresource): self.conf = conf self.mapfactory = mapfactory if self.conf.has_option('service', 'epsg'): self.crs = CRS('EPSG', self.conf.get('service', 'epsg')) else: ServerConfigurationError('EPSG code not properly configured.')
self._set_servers()
def __init__(self): """Init database""" #Get repos present on machine self.repos = os.listdir("/var/lib/pacman")
return def _set_servers(self): conf_file = open("/etc/pacman.conf", "r").read() self.servers = {} for repo in self.repos: if repo == "foreigners": continue self.servers[repo] = [] self._get_repo_servers(repo, conf_file) continue return def _get_repo_servers(self, repo, conf_file): try: begin = conf_file.index("[%s]" %repo) + len("[%s]" %repo) except ValueError: return end = conf_file.index("[", begin) current_section = conf_file[begin:end].strip() current_lines = current_section.splitlines() current_options = {} for line in current_lines: if not line or line.startswith(" continue opt, value = line.split(" = ") current_options[opt] = value continue for key in current_options.keys(): if key == "Include": servers = open(current_options[key], "r").readlines() for server in servers: server = server.strip() if not server or server.startswith(" continue self.servers[repo].append(server.split(" = ")[1]) continue elif key == "Server": server = current_options[key].split(" = ")[1] self.servers[repo].append(server) continue
def _set_filelist(self, pac, path): """Set installed files list for the given pac""" if not pac.installed: return _("%s is not installed") %pac.name files = open("%s/files" %path).read() begin = files.index("%FILES%") + len("%FILES%") end = files.find("%", begin) - len("%") filelist = files[begin:end].strip() pac.filelist = filelist return
self.show_all()
self.show()
def run(self): self.show_all() self.terminal.fork_command() self.terminal.feed_child("pacman -Sy;exit\n")
self.vbox.show_all() self.close_button.hide()
def _setup_layout(self):
def close(self, widget): self.destroy()
def run(self):
self.show_all()
self.show()
def run(self): self.show_all() self.terminal.do_upgrade()
if self.database["foreigners"]:
try:
def _setup_pacs_models(self): self.models = {}
self.models["foreigners"] = installed_list(self.database["foreigners"])
if self.database["foreigners"]: self.models["foreigners"] = installed_list(self.database["foreigners"])
def _setup_pacs_models(self): self.models = {}
elif keyword.count("+"): keys = keyword.split("+")
elif keywords.count("+"): keys = keywords.split("+")
def get_by_keywords(self, keywords): """Return pacs which have keywords as name or in description""" keys = [] #Split keywords by '+' or spaces if keywords.count("+") and keywords.count(" "): keys_1 = keywords.split("+") for key in keys_1: keys = key.split(" ") elif keywords.count(" "): keys = keywords.split() elif keyword.count("+"): keys = keyword.split("+") else: keys = keywords
self.pages["all"].toggle_renderer.connect("toggled", self.add_install)
def _setup_notebook(self): """Setup the notebook""" notebook = self.gld.get_widget("notebook")
self.pages["local"]["node"].toggle_renderer.connect("toggled", self.add_install)
def _setup_notebook(self): """Setup the notebook""" notebook = self.gld.get_widget("notebook")
self.pages["remote"][repo].toggle_renderer.connect("toggled", self.add_install )
def _setup_notebook(self): """Setup the notebook""" notebook = self.gld.get_widget("notebook")
self.pages["local"][repo].toggle_renderer.connect("toggled", self.add_install)
def _setup_notebook(self): """Setup the notebook""" notebook = self.gld.get_widget("notebook")
def _get_selected_page(self, repo_tree):
def _get_selected_page(self, repo_tree, toggle=None):
def _get_selected_page(self, repo_tree): model, tree_iter = repo_tree.get_selection().get_selected() if tree_iter is None: tree_iter = model.get_iter_from_string("0")
def add_install(self, widget, data=None):
def add_install(self, widget=None, data=None):
def add_install(self, widget, data=None): repos_tree = self.gld.get_widget("treeview") page = self._get_selected_page(repos_tree)
return def remove_install(self, widget, data=None):
installed = model.get_value(l_iter, 0) if installed == "yellow" or installed == "green": model.set_value(l_iter, 1, STOCK_GO_UP) else: model.set_value(l_iter, 1, STOCK_ADD) self.queued[name] = (model, l_iter) return def remove_install(self, widget=None, data=None):
def add_install(self, widget, data=None): repos_tree = self.gld.get_widget("treeview") page = self._get_selected_page(repos_tree)
return def add_remove(self, widget, data=None):
model.set_value(l_iter, 1, "") self.queued.pop(name) return def add_remove(self, widget=None, data=None):
def remove_install(self, widget, data=None): repos_tree = self.gld.get_widget("treeview") page = self._get_selected_page(repos_tree)
return def remove_remove(self, widget, data=None):
model.set_value(l_iter, 1, STOCK_REMOVE) self.queued[name] = (model, l_iter) return def remove_remove(self, widget=None, data=None):
def add_remove(self, widget, data=None): repos_tree = self.gld.get_widget("treeview") page = self._get_selected_page(repos_tree)
self.toggle_renderer = CellRendererToggle() self.toggle_renderer.activatable = True
action_renderer = CellRendererPixbuf()
def _setup_columns(self):
first_col.pack_start(self.toggle_renderer)
first_col.pack_start(action_renderer)
def _setup_columns(self):
first_col.set_attributes(self.toggle_renderer, active=1)
first_col.set_attributes(action_renderer, stock_id=1)
def _setup_columns(self):
ListStore.__init__(self, str, bool, str, str, str)
ListStore.__init__(self, str, str, str, str, str)
def __init__(self, packages, repo, node):
self.gld.get_widget("main_win").show_all()
self._setup_prog_bar()
def __init__(self, fname, icons): """Create the XML Object and connect handlers, then setup notebook""" self.gld = XML(fname, "main_win")
self.repos = os.listdir("/var/lib/pacman") self.repos.remove("local") try: self.repos.remove("wget-log") except ValueError: pass
self.repos = self._get_repos()
def __init__(self): """Init database""" #Get repos present on machine self.repos = os.listdir("/var/lib/pacman")
print "Found a target: " + str(target) + ", for pattern: " + str(pattern)
def matchTargets(self): rePatternedTargets = {} for pattern in self.patternedTargets.keys(): rePatternedTargets[pattern] = re.compile(pattern)
print "Processing: " + str(path)
def filterNodes(self, seedsIn, seedsOut = None, allInBetween = False):
if allInBetween: for i in range(len(path)): if i < (len(path) - 1): nodes.setdefault(path[i], []) if path[i + 1] not in nodes[path[i]]: nodes[path[i]].append(path[i + 1]) else: if dep not in nodes[path[0]]: nodes[path[0]].append(dep)
print "Matching path: " + str(newpath) if allInBetween: for i in range(len(newpath)): nodes.setdefault(newpath[i], []) if i < (len(newpath) - 1): if newpath[i + 1] not in nodes[newpath[i]]: nodes[newpath[i]].append(newpath[i + 1]) else: if dep not in nodes[path[0]]: nodes[path[0]].append(dep)
def filterNodes(self, seedsIn, seedsOut = None, allInBetween = False):
paths.append(path + [dep])
paths.append(newpath)
def filterNodes(self, seedsIn, seedsOut = None, allInBetween = False):
def DoxyfileParse(file_contents, dir, data = None):
def DoxyfileParse(file): data = DoxyfileParse_(file,{}) for (k,v) in data.items(): if not v : del data[k] elif k in ("INPUT", "FILE_PATTERNS", "EXCLUDE_PATTERNS", "@INCLUDE", "TAGFILES") : continue elif len(v)==1 : data[k] = v[0] return data def DoxyfileParse_(file, data):
def DoxyfileParse(file_contents, dir, data = None): """ Parse a Doxygen source file and return a dictionary of all the values. Values will be strings and lists of strings. """ try: if data is None : data = {} import shlex lex = shlex.shlex(instream = file_contents, posix = True) lex.wordchars += "*+./-:" lex.whitespace = lex.whitespace.replace("\n", "") lex.escape = "" lineno = lex.lineno token = lex.get_token() key = None last_token = "" key_token = True next_key = False new_data = True def append_data(data, key, new_data, token): if new_data or len(data[key]) == 0: data[key].append(token) else: data[key][-1] += token while token: if token in ['\n']: if last_token not in ['\\']: key_token = True elif token in ['\\']: pass elif key_token: if key == '@' : key += token else : key = token if token != '@' : key_token = False else: if token == "+=" or (token == "=" and key == "@INCLUDE"): if not data.has_key(key): data[key] = list() elif token == "=": data[key] = list() else: append_data( data, key, new_data, token ) new_data = True if key == '@INCLUDE': inc = os.path.join(dir,data['@INCLUDE'][-1]) if os.path.exists(inc) : DoxyfileParse(open(inc).read(),dir,data) last_token = token token = lex.get_token() if last_token == '\\' and token != '\n': new_data = False append_data( data, key, new_data, '\\' ) # compress lists of len 1 into single strings for (k, v) in data.items(): if len(v) == 0: data.pop(k) # items in the following list will be kept as lists and not converted to strings if k in ["INPUT", "FILE_PATTERNS", "EXCLUDE_PATTERNS", "@INCLUDE", "TAGFILES"]: continue if len(v) == 1: data[k] = v[0] return data except: return {}
if data is None : data = {}
dir = os.path.dirname(file)
def DoxyfileParse(file_contents, dir, data = None): """ Parse a Doxygen source file and return a dictionary of all the values. Values will be strings and lists of strings. """ try: if data is None : data = {} import shlex lex = shlex.shlex(instream = file_contents, posix = True) lex.wordchars += "*+./-:" lex.whitespace = lex.whitespace.replace("\n", "") lex.escape = "" lineno = lex.lineno token = lex.get_token() key = None last_token = "" key_token = True next_key = False new_data = True def append_data(data, key, new_data, token): if new_data or len(data[key]) == 0: data[key].append(token) else: data[key][-1] += token while token: if token in ['\n']: if last_token not in ['\\']: key_token = True elif token in ['\\']: pass elif key_token: if key == '@' : key += token else : key = token if token != '@' : key_token = False else: if token == "+=" or (token == "=" and key == "@INCLUDE"): if not data.has_key(key): data[key] = list() elif token == "=": data[key] = list() else: append_data( data, key, new_data, token ) new_data = True if key == '@INCLUDE': inc = os.path.join(dir,data['@INCLUDE'][-1]) if os.path.exists(inc) : DoxyfileParse(open(inc).read(),dir,data) last_token = token token = lex.get_token() if last_token == '\\' and token != '\n': new_data = False append_data( data, key, new_data, '\\' ) # compress lists of len 1 into single strings for (k, v) in data.items(): if len(v) == 0: data.pop(k) # items in the following list will be kept as lists and not converted to strings if k in ["INPUT", "FILE_PATTERNS", "EXCLUDE_PATTERNS", "@INCLUDE", "TAGFILES"]: continue if len(v) == 1: data[k] = v[0] return data except: return {}
lex = shlex.shlex(instream = file_contents, posix = True) lex.wordchars += "*+./-:"
lex = shlex.shlex(instream=open(file), posix=True) lex.wordchars += "*+./-:@~"
def DoxyfileParse(file_contents, dir, data = None): """ Parse a Doxygen source file and return a dictionary of all the values. Values will be strings and lists of strings. """ try: if data is None : data = {} import shlex lex = shlex.shlex(instream = file_contents, posix = True) lex.wordchars += "*+./-:" lex.whitespace = lex.whitespace.replace("\n", "") lex.escape = "" lineno = lex.lineno token = lex.get_token() key = None last_token = "" key_token = True next_key = False new_data = True def append_data(data, key, new_data, token): if new_data or len(data[key]) == 0: data[key].append(token) else: data[key][-1] += token while token: if token in ['\n']: if last_token not in ['\\']: key_token = True elif token in ['\\']: pass elif key_token: if key == '@' : key += token else : key = token if token != '@' : key_token = False else: if token == "+=" or (token == "=" and key == "@INCLUDE"): if not data.has_key(key): data[key] = list() elif token == "=": data[key] = list() else: append_data( data, key, new_data, token ) new_data = True if key == '@INCLUDE': inc = os.path.join(dir,data['@INCLUDE'][-1]) if os.path.exists(inc) : DoxyfileParse(open(inc).read(),dir,data) last_token = token token = lex.get_token() if last_token == '\\' and token != '\n': new_data = False append_data( data, key, new_data, '\\' ) # compress lists of len 1 into single strings for (k, v) in data.items(): if len(v) == 0: data.pop(k) # items in the following list will be kept as lists and not converted to strings if k in ["INPUT", "FILE_PATTERNS", "EXCLUDE_PATTERNS", "@INCLUDE", "TAGFILES"]: continue if len(v) == 1: data[k] = v[0] return data except: return {}
if token in ['\n']: if last_token not in ['\\']:
if token=='\n': if last_token!='\\':
def append_data(data, key, new_data, token): if new_data or len(data[key]) == 0: data[key].append(token) else: data[key][-1] += token
elif token in ['\\']:
elif token=='\\':
def append_data(data, key, new_data, token): if new_data or len(data[key]) == 0: data[key].append(token) else: data[key][-1] += token
if key == '@' : key += token else : key = token if token != '@' : key_token = False
key = token key_token = False
def append_data(data, key, new_data, token): if new_data or len(data[key]) == 0: data[key].append(token) else: data[key][-1] += token
data[key] = list()
data[key] = []
def append_data(data, key, new_data, token): if new_data or len(data[key]) == 0: data[key].append(token) else: data[key][-1] += token
DoxyfileParse(open(inc).read(),dir,data)
DoxyfileParse_(inc,data)
def append_data(data, key, new_data, token): if new_data or len(data[key]) == 0: data[key].append(token) else: data[key][-1] += token
append_data( data, key, new_data, '\\' ) for (k, v) in data.items(): if len(v) == 0: data.pop(k) if k in ["INPUT", "FILE_PATTERNS", "EXCLUDE_PATTERNS", "@INCLUDE", "TAGFILES"]: continue if len(v) == 1: data[k] = v[0]
append_data(data, key, new_data, '\\')
def append_data(data, key, new_data, token): if new_data or len(data[key]) == 0: data[key].append(token) else: data[key][-1] += token
dep_add_keys = [
dep_add_keys = (
def DoxySourceScan(node, env, path): """ Doxygen Doxyfile source scanner. This should scan the Doxygen file and add any files used to generate docs to the list of source files. """ dep_add_keys = [ '@INCLUDE', 'HTML_HEADER', 'HTML_FOOTER', 'TAGFILES' ] default_file_patterns = [ '*.c', '*.cc', '*.cxx', '*.cpp', '*.c++', '*.java', '*.ii', '*.ixx', '*.ipp', '*.i++', '*.inl', '*.h', '*.hh ', '*.hxx', '*.hpp', '*.h++', '*.idl', '*.odl', '*.cs', '*.php', '*.php3', '*.inc', '*.m', '*.mm', '*.py', ] default_exclude_patterns = [ '*~', ] sources = [] basedir = str(node.dir) data = DoxyfileParse(node.get_contents(), basedir) recursive = ( data.get("RECURSIVE", "NO") == "YES" ) file_patterns = data.get("FILE_PATTERNS", default_file_patterns) exclude_patterns = data.get("EXCLUDE_PATTERNS", default_exclude_patterns) for i in data.get("INPUT", [ "." ]): input = os.path.normpath(os.path.join(basedir,i)) if os.path.isfile(input): sources.append(input) elif os.path.isdir(input): if recursive : entries = os.walk(input) else : entries = [ (input, [], os.listdir(input)) ] for root, dirs, files in entries: for f in files: filename = os.path.normpath(os.path.join(root, f)) if ( reduce(lambda x, y: x or fnmatch(filename, y), file_patterns, False) and not reduce(lambda x, y: x or fnmatch(filename, y), exclude_patterns, False) ): sources.append(filename) for key in dep_add_keys: if data.has_key(key): elt = data[key] if type(elt) is type ("") : elt = [ elt ] sources.extend([ os.path.normpath(os.path.join(basedir,f)) for f in elt ]) sources = map( lambda path: env.File(path), sources ) return sources
]
)
def DoxySourceScan(node, env, path): """ Doxygen Doxyfile source scanner. This should scan the Doxygen file and add any files used to generate docs to the list of source files. """ dep_add_keys = [ '@INCLUDE', 'HTML_HEADER', 'HTML_FOOTER', 'TAGFILES' ] default_file_patterns = [ '*.c', '*.cc', '*.cxx', '*.cpp', '*.c++', '*.java', '*.ii', '*.ixx', '*.ipp', '*.i++', '*.inl', '*.h', '*.hh ', '*.hxx', '*.hpp', '*.h++', '*.idl', '*.odl', '*.cs', '*.php', '*.php3', '*.inc', '*.m', '*.mm', '*.py', ] default_exclude_patterns = [ '*~', ] sources = [] basedir = str(node.dir) data = DoxyfileParse(node.get_contents(), basedir) recursive = ( data.get("RECURSIVE", "NO") == "YES" ) file_patterns = data.get("FILE_PATTERNS", default_file_patterns) exclude_patterns = data.get("EXCLUDE_PATTERNS", default_exclude_patterns) for i in data.get("INPUT", [ "." ]): input = os.path.normpath(os.path.join(basedir,i)) if os.path.isfile(input): sources.append(input) elif os.path.isdir(input): if recursive : entries = os.walk(input) else : entries = [ (input, [], os.listdir(input)) ] for root, dirs, files in entries: for f in files: filename = os.path.normpath(os.path.join(root, f)) if ( reduce(lambda x, y: x or fnmatch(filename, y), file_patterns, False) and not reduce(lambda x, y: x or fnmatch(filename, y), exclude_patterns, False) ): sources.append(filename) for key in dep_add_keys: if data.has_key(key): elt = data[key] if type(elt) is type ("") : elt = [ elt ] sources.extend([ os.path.normpath(os.path.join(basedir,f)) for f in elt ]) sources = map( lambda path: env.File(path), sources ) return sources
default_file_patterns = [
default_file_patterns = (
def DoxySourceScan(node, env, path): """ Doxygen Doxyfile source scanner. This should scan the Doxygen file and add any files used to generate docs to the list of source files. """ dep_add_keys = [ '@INCLUDE', 'HTML_HEADER', 'HTML_FOOTER', 'TAGFILES' ] default_file_patterns = [ '*.c', '*.cc', '*.cxx', '*.cpp', '*.c++', '*.java', '*.ii', '*.ixx', '*.ipp', '*.i++', '*.inl', '*.h', '*.hh ', '*.hxx', '*.hpp', '*.h++', '*.idl', '*.odl', '*.cs', '*.php', '*.php3', '*.inc', '*.m', '*.mm', '*.py', ] default_exclude_patterns = [ '*~', ] sources = [] basedir = str(node.dir) data = DoxyfileParse(node.get_contents(), basedir) recursive = ( data.get("RECURSIVE", "NO") == "YES" ) file_patterns = data.get("FILE_PATTERNS", default_file_patterns) exclude_patterns = data.get("EXCLUDE_PATTERNS", default_exclude_patterns) for i in data.get("INPUT", [ "." ]): input = os.path.normpath(os.path.join(basedir,i)) if os.path.isfile(input): sources.append(input) elif os.path.isdir(input): if recursive : entries = os.walk(input) else : entries = [ (input, [], os.listdir(input)) ] for root, dirs, files in entries: for f in files: filename = os.path.normpath(os.path.join(root, f)) if ( reduce(lambda x, y: x or fnmatch(filename, y), file_patterns, False) and not reduce(lambda x, y: x or fnmatch(filename, y), exclude_patterns, False) ): sources.append(filename) for key in dep_add_keys: if data.has_key(key): elt = data[key] if type(elt) is type ("") : elt = [ elt ] sources.extend([ os.path.normpath(os.path.join(basedir,f)) for f in elt ]) sources = map( lambda path: env.File(path), sources ) return sources
] default_exclude_patterns = [
) default_exclude_patterns = (
def DoxySourceScan(node, env, path): """ Doxygen Doxyfile source scanner. This should scan the Doxygen file and add any files used to generate docs to the list of source files. """ dep_add_keys = [ '@INCLUDE', 'HTML_HEADER', 'HTML_FOOTER', 'TAGFILES' ] default_file_patterns = [ '*.c', '*.cc', '*.cxx', '*.cpp', '*.c++', '*.java', '*.ii', '*.ixx', '*.ipp', '*.i++', '*.inl', '*.h', '*.hh ', '*.hxx', '*.hpp', '*.h++', '*.idl', '*.odl', '*.cs', '*.php', '*.php3', '*.inc', '*.m', '*.mm', '*.py', ] default_exclude_patterns = [ '*~', ] sources = [] basedir = str(node.dir) data = DoxyfileParse(node.get_contents(), basedir) recursive = ( data.get("RECURSIVE", "NO") == "YES" ) file_patterns = data.get("FILE_PATTERNS", default_file_patterns) exclude_patterns = data.get("EXCLUDE_PATTERNS", default_exclude_patterns) for i in data.get("INPUT", [ "." ]): input = os.path.normpath(os.path.join(basedir,i)) if os.path.isfile(input): sources.append(input) elif os.path.isdir(input): if recursive : entries = os.walk(input) else : entries = [ (input, [], os.listdir(input)) ] for root, dirs, files in entries: for f in files: filename = os.path.normpath(os.path.join(root, f)) if ( reduce(lambda x, y: x or fnmatch(filename, y), file_patterns, False) and not reduce(lambda x, y: x or fnmatch(filename, y), exclude_patterns, False) ): sources.append(filename) for key in dep_add_keys: if data.has_key(key): elt = data[key] if type(elt) is type ("") : elt = [ elt ] sources.extend([ os.path.normpath(os.path.join(basedir,f)) for f in elt ]) sources = map( lambda path: env.File(path), sources ) return sources
basedir = str(node.dir) data = DoxyfileParse(node.get_contents(), basedir) recursive = ( data.get("RECURSIVE", "NO") == "YES" )
basedir = node.dir.abspath data = DoxyfileParse(node.abspath) recursive = data.get("RECURSIVE", "NO").upper()=="YES"
def DoxySourceScan(node, env, path): """ Doxygen Doxyfile source scanner. This should scan the Doxygen file and add any files used to generate docs to the list of source files. """ dep_add_keys = [ '@INCLUDE', 'HTML_HEADER', 'HTML_FOOTER', 'TAGFILES' ] default_file_patterns = [ '*.c', '*.cc', '*.cxx', '*.cpp', '*.c++', '*.java', '*.ii', '*.ixx', '*.ipp', '*.i++', '*.inl', '*.h', '*.hh ', '*.hxx', '*.hpp', '*.h++', '*.idl', '*.odl', '*.cs', '*.php', '*.php3', '*.inc', '*.m', '*.mm', '*.py', ] default_exclude_patterns = [ '*~', ] sources = [] basedir = str(node.dir) data = DoxyfileParse(node.get_contents(), basedir) recursive = ( data.get("RECURSIVE", "NO") == "YES" ) file_patterns = data.get("FILE_PATTERNS", default_file_patterns) exclude_patterns = data.get("EXCLUDE_PATTERNS", default_exclude_patterns) for i in data.get("INPUT", [ "." ]): input = os.path.normpath(os.path.join(basedir,i)) if os.path.isfile(input): sources.append(input) elif os.path.isdir(input): if recursive : entries = os.walk(input) else : entries = [ (input, [], os.listdir(input)) ] for root, dirs, files in entries: for f in files: filename = os.path.normpath(os.path.join(root, f)) if ( reduce(lambda x, y: x or fnmatch(filename, y), file_patterns, False) and not reduce(lambda x, y: x or fnmatch(filename, y), exclude_patterns, False) ): sources.append(filename) for key in dep_add_keys: if data.has_key(key): elt = data[key] if type(elt) is type ("") : elt = [ elt ] sources.extend([ os.path.normpath(os.path.join(basedir,f)) for f in elt ]) sources = map( lambda path: env.File(path), sources ) return sources
data = DoxyfileParse(source[0].get_contents(), str(source[0].dir))
data = DoxyfileParse(source[0].abspath)
def DoxyEmitter(source, target, env): """Doxygen Doxyfile emitter""" # possible output formats and their default values and output locations output_formats = { "HTML": ("YES", "html"), "LATEX": ("YES", "latex"), "RTF": ("NO", "rtf"), "MAN": ("YES", "man"), "XML": ("NO", "xml"), } data = DoxyfileParse(source[0].get_contents(), str(source[0].dir)) targets = [] out_dir = data.get("OUTPUT_DIRECTORY", ".") # add our output locations for (k, v) in output_formats.items(): if data.get("GENERATE_" + k, v[0]) == "YES": # Grmpf ... need to use a File object here. The problem is, that # Dir.scan() is implemented to just return the directory entries # and does *not* invoke the source-file scanners .. ARGH !! dir = env.Dir( os.path.join(str(source[0].dir), out_dir, data.get(k + "_OUTPUT", v[1])) ) node = env.File( os.path.join(str(dir), ".stamp" ) ) env.Clean(node, dir) targets.append( node ) if data.has_key("GENERATE_TAGFILE"): targets.append(env.File( os.path.join(str(source[0].dir), data["GENERATE_TAGFILE"]) )) # don't clobber targets for node in targets: env.Precious(node) return (targets, source)