<s> import sys , os <EOL> import tree <EOL> import indexer <EOL> class NoProcessorError ( Exception ) : <EOL> pass <EOL> class ProcessingFailure ( Exception ) : <EOL> pass <EOL> cols = <NUM_LIT> <EOL> def dircount ( d ) : <EOL> return len ( [ <NUM_LIT:1> for el in d . split ( "<STR_LIT:/>" ) if el != '<STR_LIT:.>' ] ) <EOL> class Walker : <EOL> def __init__ ( self , df , fext , linkrel ) : <EOL> self . df = df <EOL> self . linkrel = linkrel <EOL> self . fext = fext <EOL> self . walked = [ ] <EOL> self . failures = [ ] <EOL> def walkdir ( self , topdir , prefix = '<STR_LIT>' ) : <EOL> self . basecount = dircount ( topdir ) <EOL> os . path . walk ( topdir , self . walk , prefix ) <EOL> def walk ( self , prefix , d , names ) : <EOL> linkrel = prefix + '<STR_LIT>' * ( dircount ( d ) - self . basecount ) <EOL> for name in names : <EOL> fullpath = os . path . join ( d , name ) <EOL> fext = os . path . splitext ( name ) [ <NUM_LIT:1> ] <EOL> if fext == self . fext : <EOL> self . walked . append ( ( linkrel , fullpath ) ) <EOL> def generate ( self ) : <EOL> i = <NUM_LIT:0> <EOL> indexer . clearEntries ( ) <EOL> tree . filenum = <NUM_LIT:0> <EOL> for linkrel , fullpath in self . walked : <EOL> linkrel = self . linkrel + linkrel <EOL> i += <NUM_LIT:1> <EOL> fname = os . path . splitext ( fullpath ) [ <NUM_LIT:0> ] <EOL> self . percentdone ( ( float ( i ) / len ( self . walked ) ) , fname ) <EOL> try : <EOL> self . df ( fullpath , linkrel ) <EOL> except ProcessingFailure , e : <EOL> self . failures . append ( ( fullpath , e ) ) <EOL> indexer . generateIndex ( ) <EOL> self . percentdone ( <NUM_LIT:1.> , None ) <EOL> def percentdone ( self , percent , fname ) : <EOL> proglen = <NUM_LIT> <EOL> hashes = int ( percent * proglen ) <EOL> spaces = proglen - hashes <EOL> progstat = "<STR_LIT>" % ( '<STR_LIT:#>' * hashes , '<STR_LIT:U+0020>' * spaces , fname or "<STR_LIT>" ) <EOL> progstat += ( cols - len ( progstat ) ) * '<STR_LIT:U+0020>' <EOL> progstat += '<STR_LIT:\r>' <EOL> sys . stdout . write ( progstat ) <EOL> sys . stdout . flush ( ) <EOL> if fname is None : <EOL> print <EOL> class PlainReportingWalker ( Walker ) : <EOL> def percentdone ( self , percent , fname ) : <EOL> if fname : <EOL> print fname <EOL> class NullReportingWalker ( Walker ) : <EOL> def percentdone ( self , percent , fname ) : <EOL> pass <EOL> def parallelGenerator ( originalFileName , outputExtension ) : <EOL> return os . path . splitext ( originalFileName ) [ <NUM_LIT:0> ] + outputExtension <EOL> def fooAddingGenerator ( originalFileName , outputExtension ) : <EOL> return os . path . splitext ( originalFileName ) [ <NUM_LIT:0> ] + "<STR_LIT:foo>" + outputExtension <EOL> def outputdirGenerator ( originalFileName , outputExtension , inputdir , outputdir ) : <EOL> originalFileName = os . path . abspath ( originalFileName ) <EOL> abs_inputdir = os . path . abspath ( inputdir ) <EOL> if os . path . commonprefix ( ( originalFileName , abs_inputdir ) ) != abs_inputdir : <EOL> raise ValueError ( "<STR_LIT>" + originalFileName + <EOL> "<STR_LIT>" + abs_inputdir + "<STR_LIT:'>" ) <EOL> adjustedPath = os . path . join ( outputdir , os . path . basename ( originalFileName ) ) <EOL> return tree . getOutputFileName ( adjustedPath , outputExtension ) <EOL> def getFilenameGenerator ( config , outputExt ) : <EOL> if config . get ( '<STR_LIT>' ) : <EOL> return ( lambda originalFileName , outputExtension : <EOL> outputdirGenerator ( originalFileName , outputExtension , <EOL> os . path . abspath ( config . get ( '<STR_LIT>' ) ) , <EOL> os . path . abspath ( config . get ( '<STR_LIT>' ) ) ) ) <EOL> else : <EOL> return tree . getOutputFileName <EOL> def getProcessor ( module , output , config ) : <EOL> try : <EOL> m = getattr ( module . factory , '<STR_LIT>' + output ) <EOL> except AttributeError : <EOL> raise NoProcessorError ( "<STR_LIT>" + output + "<STR_LIT>" ) <EOL> if config . get ( '<STR_LIT>' ) : <EOL> ext = config [ '<STR_LIT>' ] <EOL> else : <EOL> from default import htmlDefault <EOL> ext = htmlDefault [ '<STR_LIT>' ] <EOL> return m ( config , getFilenameGenerator ( config , ext ) ) </s>
