示例#1
0
    def render_repo_filename(self, template, translation):
        component = translation.component

        # Render the template
        filename = render_template(template, translation=translation)

        # Validate filename (not absolute or linking to parent dir)
        try:
            validate_filename(filename)
        except ValidationError:
            return None

        # Absolute path
        filename = os.path.join(component.full_path, filename)

        # Check if parent directory exists
        dirname = os.path.dirname(filename)
        if not os.path.exists(dirname):
            os.makedirs(dirname)

        # Validate if there is not a symlink out of the tree
        try:
            component.repository.resolve_symlinks(dirname)
            if os.path.exists(filename):
                component.repository.resolve_symlinks(filename)
        except ValueError:
            component.log_error('refused to write out of repository: %s',
                                filename)
            return None

        return filename
示例#2
0
文件: base.py 项目: nijel/weblate
    def render_repo_filename(self, template, translation):
        component = translation.component

        # Render the template
        filename = render_template(template, translation=translation)

        # Validate filename (not absolute or linking to parent dir)
        try:
            validate_filename(filename)
        except ValidationError:
            return None

        # Absolute path
        filename = os.path.join(component.full_path, filename)

        # Check if parent directory exists
        dirname = os.path.dirname(filename)
        if not os.path.exists(dirname):
            os.makedirs(dirname)

        # Validate if there is not a symlink out of the tree
        try:
            component.repository.resolve_symlinks(dirname)
            if os.path.exists(filename):
                component.repository.resolve_symlinks(filename)
        except ValueError:
            component.log_error(
                'refused to write out of repository: %s', filename
            )
            return None

        return filename
示例#3
0
 def pre_commit(self, translation, author):
     filename = render_template(self.instance.configuration['filename'],
                                translation=translation)
     try:
         validate_filename(filename)
     except ValidationError:
         return
     filename = os.path.join(self.instance.component.full_path, filename)
     content = render_template(self.instance.configuration['template'],
                               translation=translation)
     dirname = os.path.dirname(filename)
     if not os.path.exists(dirname):
         os.makedirs(dirname)
     with open(filename, 'w') as handle:
         handle.write(content)
     translation.addon_commit_files.append(filename)
示例#4
0
文件: forms.py 项目: tdelmas/weblate
 def clean_filename(self):
     self.test_render(self.cleaned_data['filename'])
     validate_filename(self.cleaned_data['filename'])
     return self.cleaned_data['filename']
示例#5
0
 def test_empty(self):
     validate_filename("")
示例#6
0
 def test_simplification(self):
     with self.assertRaises(ValidationError):
         validate_filename("path/./file")
示例#7
0
 def test_good(self):
     validate_filename("path/file")
示例#8
0
 def test_absolute(self):
     with self.assertRaises(ValidationError):
         validate_filename("/path")
示例#9
0
 def test_parent(self):
     with self.assertRaises(ValidationError):
         validate_filename("../path")
示例#10
0
 def clean_path(self):
     self.test_render(self.cleaned_data["path"])
     validate_filename(self.cleaned_data["path"])
     return self.cleaned_data["path"]
示例#11
0
 def test_good(self):
     validate_filename('path/file')
示例#12
0
 def test_absolute(self):
     with self.assertRaises(ValidationError):
         validate_filename('/path')
示例#13
0
 def test_parent(self):
     with self.assertRaises(ValidationError):
         validate_filename('../path')
示例#14
0
文件: forms.py 项目: nijel/weblate
 def clean_filename(self):
     self.test_render(self.cleaned_data['filename'])
     validate_filename(self.cleaned_data['filename'])
     return self.cleaned_data['filename']