| 89 | | for root, dirs, files in os.walk('.'): |
|---|
| 90 | | |
|---|
| 91 | | # get the path directory |
|---|
| 92 | | ctx.path = path(root).abspath() |
|---|
| 93 | | ctx.relpath = path(basedir).relpathto(root) |
|---|
| 94 | | ctx.relpathparent = path(basedir).relpathto(ctx.path.parent) |
|---|
| 95 | | |
|---|
| | 90 | path_basedir = path(basedir) |
|---|
| | 91 | |
|---|
| | 92 | if rebuilddirs is not None: |
|---|
| | 93 | def f (): |
|---|
| | 94 | for p in rebuilddirs: |
|---|
| | 95 | for t in os.walk(p): |
|---|
| | 96 | yield t |
|---|
| | 97 | file_generator = f() |
|---|
| | 98 | else: |
|---|
| | 99 | file_generator = os.walk('.') |
|---|
| | 100 | for root, dirs, files in file_generator: |
|---|
| 121 | | |
|---|
| 122 | | # check to see if the current directory is in the rebuild dirs list |
|---|
| 123 | | matchesRebuildDir = False |
|---|
| 124 | | if rebuilddirs is not None: |
|---|
| 125 | | for rebuilddir in rebuilddirs: |
|---|
| 126 | | if ctx.relpath.startswith(rebuilddir): |
|---|
| 127 | | matchesRebuildDir = True |
|---|
| 128 | | break |
|---|
| 129 | | |
|---|
| 130 | | # check for nobuild |
|---|
| 131 | | nobuild = path(root) / 'NOBUILD' |
|---|
| 132 | | if nobuild.isfile(): |
|---|
| 133 | | utils.copytree(root, opjoin(OUTPUTDIR, root), |
|---|
| 134 | | nocopylist=['.svn']) |
|---|
| 135 | | continue |
|---|
| 136 | | |
|---|
| 137 | | |
|---|
| 138 | | if os.path.exists(cachepath) and partialbuild: |
|---|
| 139 | | ctx = pickle.load(open(cachepath)) |
|---|
| 140 | | ctx.partialbuild = True |
|---|
| | 138 | # Load cached data if it's available |
|---|
| | 139 | ctx.relpathparent = path_basedir.relpathto(ctx.path.parent) |
|---|
| | 140 | if os.path.exists(cachepathparent): |
|---|
| | 141 | ctx.data = pickle.load(open(cachepathparent)).data |
|---|
| | 142 | |
|---|
| | 143 | if ctx.verbose > 0: |
|---|
| | 144 | print '.. %s Built from Source Files' % str(ctx.relpath) |
|---|
| | 145 | |
|---|
| | 146 | ctx.partialbuild = False |
|---|
| | 147 | |
|---|
| | 148 | try: |
|---|
| | 149 | s = time.time() |
|---|
| 142 | | flatten(ctx.data[ctx.relpath]['index.yml'], ctx)]) |
|---|
| 143 | | file(opjoin(OUTPUTDIR, root, 'index.html'), 'w').write(html) |
|---|
| 144 | | else: |
|---|
| 145 | | if matchesRebuildDir: |
|---|
| 146 | | ctx.data = pickle.load(open(cachepathparent)).data |
|---|
| 147 | | |
|---|
| 148 | | if matchesRebuildDir or rebuilddirs is None: |
|---|
| 149 | | if ctx.verbose > 0: |
|---|
| 150 | | print '.. %s Built from Source Files' % str(ctx.relpath) |
|---|
| 151 | | |
|---|
| 152 | | ctx.partialbuild = False |
|---|
| 153 | | |
|---|
| 154 | | try: |
|---|
| 155 | | html = flat.flatten([DOCTYPE, |
|---|
| 156 | | flatten(Y.fragmentConstructor( |
|---|
| 157 | | opjoin(root, 'index.yml')), ctx)]) |
|---|
| 158 | | except KeyError: |
|---|
| 159 | | print '*'*80 |
|---|
| 160 | | print 'An error has occured building the %s page' % ( |
|---|
| 161 | | path(opjoin(OUTPUTDIR, root, 'index.html')).abspath()) |
|---|
| 162 | | print 'It is likely that an item of content is missing' |
|---|
| 163 | | print 'or malformed.' |
|---|
| 164 | | print 'The current data for this page is shown above' |
|---|
| 165 | | |
|---|
| 166 | | sys.exit() |
|---|
| 167 | | except (KeyboardInterrupt, SystemExit): # roll on Python2.5 |
|---|
| 168 | | raise |
|---|
| 169 | | except: |
|---|
| 170 | | print "While building %s:"%(opjoin(OUTPUTDIR, root)) |
|---|
| 171 | | if not keepgoing: |
|---|
| 172 | | raise |
|---|
| 173 | | else: |
|---|
| 174 | | ee, ev, et = sys.exc_info() |
|---|
| 175 | | traceback.print_exception(ee, ev, et, file=sys.stdout) |
|---|
| 176 | | print "keepgoing (-k) specified, continuing" |
|---|
| 177 | | continue |
|---|
| 178 | | |
|---|
| 179 | | file(opjoin(OUTPUTDIR, root, 'index.html'), 'w').write(html) |
|---|
| 180 | | if createcache: |
|---|
| 181 | | pickle.dump(ctx, open(cachepath, 'w')) |
|---|
| | 151 | flatten(Y.fragmentConstructor( |
|---|
| | 152 | opjoin(root, 'index.yml')), ctx)]) |
|---|
| | 153 | if ctx.verbose > 1: |
|---|
| | 154 | print 'Generation time:', time.time()-s |
|---|
| | 155 | except KeyError: |
|---|
| | 156 | print '*'*80 |
|---|
| | 157 | print 'An error has occurred building the %s page' % ( |
|---|
| | 158 | path(opjoin(OUTPUTDIR, root, 'index.html')).abspath()) |
|---|
| | 159 | print 'It is likely that an item of content is missing' |
|---|
| | 160 | print 'or malformed.' |
|---|
| | 161 | print 'The current data for this page is shown above' |
|---|
| | 162 | |
|---|
| | 163 | sys.exit() |
|---|
| | 164 | except (KeyboardInterrupt, SystemExit): # roll on Python2.5 |
|---|
| | 165 | raise |
|---|
| | 166 | except: |
|---|
| | 167 | print "While building %s:"%(opjoin(OUTPUTDIR, root)) |
|---|
| | 168 | if not keepgoing: |
|---|
| | 169 | raise |
|---|
| 183 | | if ctx.verbose > 1: |
|---|
| 184 | | print '.. %s Rebuilt from Cached Data' % str(ctx.relpath) |
|---|
| | 171 | ee, ev, et = sys.exc_info() |
|---|
| | 172 | traceback.print_exception(ee, ev, et, file=sys.stdout) |
|---|
| | 173 | print "keepgoing (-k) specified, continuing" |
|---|
| | 174 | continue |
|---|
| | 175 | |
|---|
| | 176 | file(opjoin(OUTPUTDIR, root, 'index.html'), 'w').write(html) |
|---|
| | 177 | if createcache: |
|---|
| | 178 | pickle.dump(ctx, open(cachepath, 'w')) |
|---|
| | 179 | print 'Writing cache file:', cachepath |
|---|