Changeset 168
- Timestamp:
- 03/22/06 12:58:45 (3 years ago)
- Files:
-
- trunk/pyramid/build.py (modified) (9 diffs)
- trunk/pyramid/dictutils.py (modified) (2 diffs)
- trunk/pyramid/test/tests.py (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/pyramid/build.py
r167 r168 25 25 class Dumper(syck.Dumper): 26 26 def represent_pyramid_path_path(self, object): 27 return syck.Scalar(object, 27 return syck.Scalar(object, 28 28 tag="tag:python.yaml.org,2002:object:pyramid.path.path") 29 29 def represent_nevow_stan_xml(self, object): … … 33 33 34 34 35 def build(data, out, verbose=0, resourcedirs=[], rebuilddirs=None, 36 partialbuild=False, constants=None, update=False, 35 def build(data, out, verbose=0, resourcedirs=[], rebuilddirs=None, 36 partialbuild=False, constants=None, update=False, 37 37 createcache=False): 38 38 … … 63 63 for resourcedir in resourcedirs: 64 64 dir, name = os.path.split(resourcedir) 65 utils.copytree(resourcedir, opjoin(OUTPUTDIR, name), 65 utils.copytree(resourcedir, opjoin(OUTPUTDIR, name), 66 66 nocopylist=['.svn']) 67 67 … … 72 72 # initialise a context 73 73 ctx = Context() 74 # set the root data key to an empty dictionary (the first level acquires 74 # set the root data key to an empty dictionary (the first level acquires 75 75 # from this) 76 76 ctx.data = { '': {} } … … 126 126 nobuild = path(root) / 'NOBUILD' 127 127 if nobuild.isfile(): 128 utils.copytree(root, opjoin(OUTPUTDIR, root), 128 utils.copytree(root, opjoin(OUTPUTDIR, root), 129 129 nocopylist=['.svn']) 130 130 continue … … 134 134 ctx = pickle.load(open(cachepath)) 135 135 ctx.partialbuild = True 136 html = flat.flatten( [DOCTYPE, 136 html = flat.flatten( [DOCTYPE, 137 137 flatten(ctx.data[ctx.relpath]['index.yml'], ctx)] ) 138 138 file(opjoin(OUTPUTDIR, root, 'index.html'), 'w').write(html) … … 148 148 149 149 try: 150 html = flat.flatten( [DOCTYPE, 150 html = flat.flatten( [DOCTYPE, 151 151 flatten(Y.fragmentConstructor( 152 152 opjoin(root, 'index.yml')), ctx)] ) … … 193 193 194 194 195 build(options.data, options.out, verbose=options.verbose, 196 resourcedirs=resourcedirs, rebuilddirs=rebuilddirs, 197 constants=constants, update=options.update, 195 build(options.data, options.out, verbose=options.verbose, 196 resourcedirs=resourcedirs, rebuilddirs=rebuilddirs, 197 constants=constants, update=options.update, 198 198 createcache=options.createcache) 199 199 … … 201 201 def parseOptions(): 202 202 parser = OptionParser() 203 parser.add_option("-d", "--data", dest="data", 204 help="directory in which the fragment data is stored", 203 parser.add_option("-d", "--data", dest="data", 204 help="directory in which the fragment data is stored", 205 205 metavar="DATA") 206 parser.add_option("-o", "--out", dest="out", 207 help="directory in which to save output (will be emptied)", 206 parser.add_option("-o", "--out", dest="out", 207 help="directory in which to save output (will be emptied)", 208 208 metavar="OUT") 209 parser.add_option("-r", "--resources", dest="resources", 210 help="comma separated list of resource directories to copy", 209 parser.add_option("-r", "--resources", dest="resources", 210 help="comma separated list of resource directories to copy", 211 211 metavar="RESOURCES") 212 parser.add_option("-v", "--verbose", action="store_const", 213 dest="verbose", default=0, const=1, 212 parser.add_option("-v", "--verbose", action="store_const", 213 dest="verbose", default=0, const=1, 214 214 help="print status messages to stdout") 215 parser.add_option("-V", "--veryverbose", action="store_const", 215 parser.add_option("-V", "--veryverbose", action="store_const", 216 216 dest="verbose", default=0, const=2, help="print all data to stdout") 217 parser.add_option("-W", "--veryveryverbose", action="store_const", 217 parser.add_option("-W", "--veryveryverbose", action="store_const", 218 218 dest="verbose", default=0, const=3, help="print all data to stdout") 219 parser.add_option("-R", "--rebuilddirs", dest="rebuilddirs", 220 help="only rebuild below these comma separated directories", 219 parser.add_option("-R", "--rebuilddirs", dest="rebuilddirs", 220 help="only rebuild below these comma separated directories", 221 221 metavar="REBUILDDIRS") 222 parser.add_option("-C", "--createcache", action="store_true", 223 dest="createcache", default=False, help="recreate the cache files", 222 parser.add_option("-C", "--createcache", action="store_true", 223 dest="createcache", default=False, help="recreate the cache files", 224 224 metavar="CREATECACHE") 225 parser.add_option("-c", "--constants", dest="constants", 226 help="pass in the names constants (e.g. PDO=/root/pdo,PSF=/psf", 225 parser.add_option("-c", "--constants", dest="constants", 226 help="pass in the names constants (e.g. PDO=/root/pdo,PSF=/psf", 227 227 metavar="CONSTANTS") 228 parser.add_option("-U", "--update", action="store_true", dest="update", 229 default=False, 228 parser.add_option("-U", "--update", action="store_true", dest="update", 229 default=False, 230 230 help="NOT WORKING DO NOT USE try to build only those pages that have changed") 231 231 (options, args) = parser.parse_args() trunk/pyramid/dictutils.py
r166 r168 5 5 def merge(a, b, dir=None, partialbuild=False): 6 6 7 if (isinstance(a, Y.sectionnav) and 7 if (isinstance(a, Y.sectionnav) and 8 8 isinstance(b, Y.sectionnav) and dir is not None): 9 # special case. If b is the same as a, it has been inhereited - 9 # special case. If b is the same as a, it has been inhereited - 10 10 # sectionnav's should not inherit in this fashion however 11 # TODO: this fix might cause problems in the future. e.g. if 11 # TODO: this fix might cause problems in the future. e.g. if 12 12 # the second level nav were exactly the same as the first level nav? 13 13 if a == b: … … 21 21 for bkey in b.keys(): 22 22 if a.has_key(bkey): 23 a[bkey] = merge(a[bkey], b[bkey], dir, 23 a[bkey] = merge(a[bkey], b[bkey], dir, 24 24 partialbuild=partialbuild) 25 25 else: trunk/pyramid/test/tests.py
r162 r168 22 22 if os.path.exists(dir): 23 23 removeTemp(dir) 24 os.mkdir(dir) 24 os.mkdir(dir) 25 25 26 26 def tree_from_stream(stream, … … 96 96 fh1 = StringIO(text1) 97 97 fh2 = StringIO(text2) 98 98 99 99 # convert xml files to tree 100 100 try: … … 133 133 except ImportError: 134 134 from logilab.xmldiff.ezs import EzsCorrector 135 135 136 136 strategy = EzsCorrector(formatter) 137 137 else: … … 175 175 print filetext2 176 176 print '#'*80 177 print '%s\n Differences in generated output for %s\n%s' % ('='*70,relpath / file,'='*70) 177 print '%s\n Differences in generated output for %s\n%s' % ('='*70,relpath / file,'='*70) 178 178 from pprint import pprint 179 179 pprint(result) … … 183 183 184 184 class test_yamlRegistry(unittest.TestCase): 185 186 def test_url(self): 185 186 def test_url(self): 187 187 """ url constructor 188 188 """ … … 190 190 expected = {'href':Y.ahref('/link'), 'label':'My Link'} 191 191 self.assertEqual(data,expected) 192 192 193 193 194 194 class test_flatteners(unittest.TestCase): 195 196 def test_ahref(self): 195 196 def test_ahref(self): 197 197 """ absolute href 198 198 """ … … 201 201 self.assertEqual(flatteners.flatten(data,ctx), '/about') 202 202 203 def test_rhref(self): 203 def test_rhref(self): 204 204 """ relative href 205 205 """ … … 208 208 self.assertEqual(flatteners.flatten(data,ctx), '/about') 209 209 210 211 def test_url(self): 210 211 def test_url(self): 212 212 """ url 213 213 """ … … 216 216 expected = {'href':'/link', 'label':'My Link'} 217 217 self.assertEqual(flatteners.flatten(data,ctx),expected) 218 218 219 219 220 220 class test_build(unittest.TestCase): 221 221 222 222 buildtestroot = 'build_tests' 223 223 buildtestpath = path.path(os.getcwd()) / 'pyramid' / 'test' / testdatadir / buildtestroot 224 224 225 225 def setUp(self): 226 226 """ Create test folders … … 228 228 makeAndCleanTemp(TEMPFOLDER) 229 229 230 230 231 231 def test_basic(self): 232 232 """ … … 234 234 skipdirs = ['.svn'] 235 235 tests = [d for d in os.listdir(self.buildtestpath) if d != '.svn'] 236 236 237 237 for buildtest in tests: 238 238 print 'testing %s' % buildtest … … 240 240 checkedresultpath = self.buildtestpath / buildtest / 'expected' 241 241 build.build(datapath,TEMPFOLDER / buildtest,createcache=True) 242 242 243 243 self.assertEqual(compareDirs(TEMPFOLDER / buildtest,checkedresultpath,skipdirs,['.cache.dump']),True) 244 244 self.assertEqual(compareDirs(TEMPFOLDER / buildtest,checkedresultpath,skipdirs),True) 245 245 246 246 247 247 configfilename = self.buildtestpath / buildtest / 'config.yml' … … 251 251 self.assertEqual(compareDirs(TEMPFOLDER / buildtest,checkedresultpath,skipdirs,['.cache.dump']),True) 252 252 self.assertEqual(compareDirs(TEMPFOLDER / buildtest,checkedresultpath,skipdirs),True) 253 254 253 254 255 255 def tearDown(self): 256 256 """ remove all test folders 257 257 """ 258 #removeTemp(TEMPFOLDER) 259 258 #removeTemp(TEMPFOLDER) 259 260 260 if __name__ == "__main__": 261 unittest.main() 261 unittest.main()
