Ejemplo n.º 1
0
 def _file_permissions_copy(self, template_file, output_file):
     true_template_file = template_file
     for a_template_dir in self.template_dirs:
         true_template_file = os.path.join(a_template_dir, template_file)
         if os.path.exists(true_template_file):
             break
     utils.file_permissions_copy(true_template_file, output_file)
Ejemplo n.º 2
0
def test_file_permission_copy():
    test_source = "test_file_permission_copy1"
    test_dest = "test_file_permission_copy2"
    create_file(test_source, 0o046)
    create_file(test_dest, 0o646)
    file_permissions_copy(test_source, test_dest)
    eq_(
        stat.S_IMODE(os.lstat(test_source).st_mode),
        stat.S_IMODE(os.lstat(test_dest).st_mode),
    )
    os.unlink(test_source)
    os.unlink(test_dest)
Ejemplo n.º 3
0
 def _apply_template(self, template, data, output):
     rendered_content = template.render(**data)
     rendered_content = utils.strip_off_trailing_new_lines(rendered_content)
     rendered_content = rendered_content.encode("utf-8")
     flag = HASH_STORE.is_file_changed(output, rendered_content,
                                       template.filename)
     if flag:
         utils.write_file_out(output,
                              rendered_content,
                              strip=False,
                              encode=False)
         utils.file_permissions_copy(template.filename, output)
     return flag
Ejemplo n.º 4
0
def test_file_permission_copy():
    if sys.platform == "win32":
        raise SkipTest("No actual chmod on windows")
    test_source = "test_file_permission_copy1"
    test_dest = "test_file_permission_copy2"
    create_file(test_source, 0o046)
    create_file(test_dest, 0o646)
    file_permissions_copy(test_source, test_dest)
    eq_(
        stat.S_IMODE(os.lstat(test_source).st_mode),
        stat.S_IMODE(os.lstat(test_dest).st_mode),
    )
    os.unlink(test_source)
    os.unlink(test_dest)
Ejemplo n.º 5
0
 def apply_template(self, template_abs_path, template, data, output_file):
     rendered_content = self.engine.apply_template(template, data,
                                                   output_file)
     rendered_content = utils.strip_off_trailing_new_lines(rendered_content)
     rendered_content = rendered_content.encode("utf-8")
     flag = HASH_STORE.is_file_changed(output_file, rendered_content,
                                       template_abs_path)
     if flag:
         utils.write_file_out(output_file,
                              rendered_content,
                              strip=False,
                              encode=False)
         utils.file_permissions_copy(template_abs_path, output_file)
     return flag
Ejemplo n.º 6
0
    def apply_template(self, template_abs_path, template, data, output_file):
        rendered_content = self.engine.apply_template(template, data,
                                                      output_file)
        if PY3_ABOVE:
            if not isinstance(rendered_content, bytes):
                rendered_content = rendered_content.encode("utf-8")

        try:
            flag = HASH_STORE.is_file_changed(output_file, rendered_content,
                                              template_abs_path)
            if flag:
                utils.write_file_out(output_file, rendered_content)
                utils.file_permissions_copy(template_abs_path, output_file)
            return flag
        except exceptions.FileNotFound:
            utils.write_file_out(output_file, rendered_content)
            return True