예제 #1
0
파일: site.py 프로젝트: pjv/cytoplasm
 def _copy_over(self, target_directory):
     """Copy the files and directories not beginning with '_' in the source
     directory to the build directory. If they match an interpreter,
     interpret them first.
     """
     files = ((f, os.path.join(self.source, f)) for f in 
             os.listdir(self.source) if not f.startswith(("_", ".")))
     for base, full in files:
         if os.path.isfile(full):
             destination = interpreters.interpreted_filename(base, self)
             interpreters.interpret(full, 
                     os.path.join(self.build_dir, destination), self)
         elif os.path.isdir(full):
             destination = os.path.join(self.build_dir, base)
             # if the directory exists in the build directory, delete it
             if os.path.exists(destination):
                 shutil.rmtree(destination)
             # and then copy it completely to the build directory
             shutil.copytree(full, destination)
예제 #2
0
 def _copy_over(self, target_directory):
     """Copy the files and directories not beginning with '_' in the source
     directory to the build directory. If they match an interpreter,
     interpret them first.
     """
     files = ((f, os.path.join(self.source, f))
              for f in os.listdir(self.source)
              if not f.startswith(("_", ".")))
     for base, full in files:
         if os.path.isfile(full):
             destination = interpreters.interpreted_filename(base, self)
             interpreters.interpret(
                 full, os.path.join(self.build_dir, destination), self)
         elif os.path.isdir(full):
             destination = os.path.join(self.build_dir, base)
             # if the directory exists in the build directory, delete it
             if os.path.exists(destination):
                 shutil.rmtree(destination)
             # and then copy it completely to the build directory
             shutil.copytree(full, destination)
예제 #3
0
 def test_page_controller(self):
     """Test that the template is correctly applied to each of the files
     in the source directory.
     """
     # a list of all the page controllers.
     controllers = [
         c for c in self.site.config.controllers if c[0] == "page"
     ]
     # for each of them...
     for controller, [source, build, templates] in controllers:
         # read the template.
         # assume the template in question is a mako template, too.
         with open(os.path.join(self.directory, templates,
                                "page.mako")) as f:
             template = f.read()
         # for the purposes of this test, assume there is no actual logic
         # going on, just interpolation. Get everything before and after
         # ${page.contents}.
         template_before, template_after = template.split(
             "${page.contents}")
         # figure out the beginning and ending parts of
         # for each of the source files:
         for file in os.listdir(os.path.join(self.directory, source)):
             # get the contents of the file.
             with open(os.path.join(self.directory, source, file)) as f:
                 source_contents = f.read()
             # get the contents of the built file
             shortened_filename = interpreted_filename(file, self.site)
             with open(
                     os.path.join(self.directory, build,
                                  shortened_filename)) as f:
                 build_contents = f.read()
             # make sure it starts with the first part of the template:
             assert build_contents.startswith(template_before)
             # make sure it contains the contents of the source file:
             assert source_contents.strip() in build_contents
             # make sure it ends with the last part of the template
             assert build_contents.endswith(template_after)
 def test_page_controller(self):
     """Test that the template is correctly applied to each of the files
     in the source directory.
     """
     # a list of all the page controllers.
     controllers = [c for c in self.site.config.controllers if
             c[0] == "page"]
     # for each of them...
     for controller, [source, build, templates] in controllers:
         # read the template.
         # assume the template in question is a mako template, too.
         with open(os.path.join(self.directory, templates,
             "page.mako")) as f:
             template = f.read()
         # for the purposes of this test, assume there is no actual logic
         # going on, just interpolation. Get everything before and after
         # ${page.contents}.
         template_before, template_after = template.split(
                 "${page.contents}")
         # figure out the beginning and ending parts of
         # for each of the source files:
         for file in os.listdir(os.path.join(self.directory, source)):
             # get the contents of the file.
             with open(os.path.join(self.directory, source, file)) as f:
                 source_contents = f.read()
             # get the contents of the built file
             shortened_filename = interpreted_filename(file, self.site)
             with open(os.path.join(self.directory, build,
                 shortened_filename)) as f:
                 build_contents = f.read()
             # make sure it starts with the first part of the template:
             assert build_contents.startswith(template_before)
             # make sure it contains the contents of the source file:
             assert source_contents.strip() in build_contents
             # make sure it ends with the last part of the template
             assert build_contents.endswith(template_after)