示例#1
0
 def matched_components(self):
     """Return list of matched components."""
     result = {}
     for path, groups, mask in self.matches:
         if mask not in result:
             name = render_template(self.name_template, **groups)
             result[mask] = {
                 "files": {path},
                 "languages": {groups["language"]},
                 "files_langs": {(path, groups["language"])},
                 "base_file":
                 render_template(self.base_file_template, **groups),
                 "new_base":
                 render_template(self.new_base_template, **groups),
                 "intermediate":
                 render_template(self.intermediate_template, **groups),
                 "mask":
                 mask,
                 "name":
                 name,
                 "slug":
                 slugify(name),
             }
         else:
             result[mask]["files"].add(path)
             result[mask]["languages"].add(groups["language"])
             result[mask]["files_langs"].add((path, groups["language"]))
     return result
示例#2
0
 def matched_components(self):
     """Return list of matched components."""
     result = {}
     for path, groups, mask in self.matches:
         if mask not in result:
             name = render_template(self.name_template, **groups)
             result[mask] = {
                 'files': {path},
                 'languages': {groups['language']},
                 'files_langs': {(path, groups['language'])},
                 'base_file': render_template(
                     self.base_file_template, **groups
                 ),
                 'new_base': render_template(
                     self.new_base_template, **groups
                 ),
                 'mask': mask,
                 'name': name,
                 'slug': slugify(name),
             }
         else:
             result[mask]['files'].add(path)
             result[mask]['languages'].add(groups['language'])
             result[mask]['files_langs'].add((path, groups['language']))
     return result
示例#3
0
 def matched_components(self):
     """Return list of matched components."""
     result = {}
     for path, groups, mask in self.matches:
         if mask not in result:
             name = render_template(self.name_template, **groups)
             result[mask] = {
                 'files': {path},
                 'languages': {groups['language']},
                 'files_langs': {(path, groups['language'])},
                 'base_file': render_template(
                     self.base_file_template, **groups
                 ),
                 'new_base': render_template(
                     self.new_base_template, **groups
                 ),
                 'mask': mask,
                 'name': name,
                 'slug': slugify(name),
             }
         else:
             result[mask]['files'].add(path)
             result[mask]['languages'].add(groups['language'])
             result[mask]['files_langs'].add((path, groups['language']))
     return result
示例#4
0
def validate_render(value, **kwargs):
    """Validates rendered template."""
    try:
        render_template(value, **kwargs)
    except Exception as err:
        raise ValidationError(
            _('Failed to render template: {}').format(err)
        )
示例#5
0
def validate_render(value, **kwargs):
    """Validates rendered template."""
    try:
        render_template(value, **kwargs)
    except Exception as err:
        raise ValidationError(
            _('Failed to render template: {}').format(err)
        )
示例#6
0
 def pre_commit(self, translation):
     filename = os.path.join(
         self.instance.component.full_path,
         render_template(self.instance.configuration['filename'],
                         translation=translation))
     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)
示例#7
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
示例#8
0
 def test_parentdir_chain(self):
     self.assertEqual(
         render_template(
             "{{ value|parentdir|parentdir }}", value="foo/bar/weblate/test.po"
         ),
         "weblate/test.po",
     )
示例#9
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
示例#10
0
文件: git.py 项目: brezerk/weblate
 def get_merge_message(self):
     parts = render_template(
         settings.DEFAULT_PULL_MESSAGE, component=self.component
     ).split("\n\n", 1)
     if len(parts) == 1:
         parts.append("")
     return parts
示例#11
0
 def test_parentdir_chain(self):
     self.assertEqual(
         render_template(
             '{{ value|parentdir|parentdir }}',
             value='foo/bar/weblate/test.po'
         ),
         'weblate/test.po'
     )
示例#12
0
文件: base.py 项目: nijel/weblate
 def get_commit_message(self, component):
     return render_template(
         component.addon_message,
         # Compatibility with older
         hook_name=self.verbose,
         addon_name=self.verbose,
         component=component,
     )
示例#13
0
    def pre_commit(self, translation, author):
        self.run_script(translation=translation)

        if self.add_file:
            filename = os.path.join(
                self.instance.component.full_path,
                render_template(self.add_file, translation=translation))
            translation.addon_commit_files.append(filename)
示例#14
0
 def get_commit_message(self, component):
     return render_template(
         component.addon_message,
         # Compatibility with older
         hook_name=self.verbose,
         addon_name=self.verbose,
         component=component,
     )
示例#15
0
 def get_commit_message(self, component):
     return render_template(
         component.addon_message,
         hook_name=self.verbose,
         project_name=component.project.name,
         component_name=component.name,
         url=get_site_url(component.get_absolute_url())
     )
示例#16
0
 def pre_commit(self, translation, author):
     filename = os.path.join(
         self.instance.component.full_path,
         render_template(
             self.instance.configuration['filename'],
             translation=translation
         )
     )
     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)
示例#17
0
 def pre_commit(self, translation, author):
     filename = self.render_repo_filename(
         self.instance.configuration['filename'], translation)
     if not filename:
         return
     content = render_template(self.instance.configuration['template'],
                               translation=translation)
     with open(filename, 'w') as handle:
         handle.write(content)
     translation.addon_commit_files.append(filename)
示例#18
0
    def get_commit_message(self, author):
        """Format commit message based on project configuration."""
        if self.commit_template == 'add':
            template = self.component.add_message
            self.commit_template = ''
        elif self.commit_template == 'delete':
            template = self.component.delete_message
            self.commit_template = ''
        else:
            template = self.component.commit_message

        return render_template(template, translation=self, author=author)
示例#19
0
    def pre_commit(self, translation, author):
        self.run_script(translation=translation)

        if self.add_file:
            filename = os.path.join(
                self.instance.component.full_path,
                render_template(
                    self.add_file,
                    translation=translation
                )
            )
            translation.addon_commit_files.append(filename)
示例#20
0
    def get_commit_message(self, author, template=None, **kwargs):
        """Format commit message based on project configuration."""
        if template is None:
            if self.commit_template == "add":
                template = self.component.add_message
                self.commit_template = ""
            elif self.commit_template == "delete":
                template = self.component.delete_message
                self.commit_template = ""
            else:
                template = self.component.commit_message

        return render_template(template, translation=self, author=author, **kwargs)
示例#21
0
 def commit_and_push(self, component):
     repository = component.repository
     with repository.lock:
         if repository.needs_commit():
             files = [t.filename for t in component.translation_set.all()]
             repository.commit(render_template(
                 self.message,
                 hook_name=self.verbose,
                 project_name=component.project.name,
                 component_name=component.name,
                 url=get_site_url(component.get_absolute_url())),
                               files=files)
             component.push_if_needed(None)
示例#22
0
    def get_commit_message(self, author):
        """Format commit message based on project configuration."""
        if self.commit_template == 'add':
            template = self.component.add_message
            self.commit_template = ''
        elif self.commit_template == 'delete':
            template = self.component.delete_message
            self.commit_template = ''
        else:
            template = self.component.commit_message

        msg = render_template(template, translation=self, author=author)

        return msg
示例#23
0
文件: base.py 项目: dekoza/weblate
 def commit_and_push(self, component):
     repository = component.repository
     with repository.lock:
         if repository.needs_commit():
             files = [t.filename for t in component.translation_set.all()]
             repository.commit(
                 render_template(
                     self.message,
                     hook_name=self.verbose,
                     project_name=component.project.name,
                     component_name=component.name,
                     url=get_site_url(component.get_absolute_url())
                 ),
                 files=files
             )
             component.push_if_needed(None)
示例#24
0
    def get_commit_message(self, author):
        """Format commit message based on project configuration."""
        template = self.component.commit_message
        if self.commit_message == '__add__':
            template = self.component.add_message
            self.commit_message = ''
            self.save()
        elif self.commit_message == '__delete__':
            template = self.component.delete_message
            self.commit_message = ''
            self.save()

        msg = render_template(template, self, author=author)

        if self.commit_message:
            msg = '{0}\n\n{1}'.format(msg, self.commit_message)
            self.commit_message = ''
            self.save()

        return msg
示例#25
0
    def get_commit_message(self, author):
        """Format commit message based on project configuration."""
        template = self.component.commit_message
        if self.commit_message == '__add__':
            template = self.component.add_message
            self.commit_message = ''
            self.save()
        elif self.commit_message == '__delete__':
            template = self.component.delete_message
            self.commit_message = ''
            self.save()

        msg = render_template(template, self, author=author)

        if self.commit_message:
            msg = '{0}\n\n{1}'.format(msg, self.commit_message)
            self.commit_message = ''
            self.save()

        return msg
示例#26
0
 def test_parentdir(self):
     self.assertEqual(
         render_template('{{ value|parentdir }}', value='weblate/test.po'),
         'test.po')
示例#27
0
 def test_stripext(self):
     self.assertEqual(
         render_template('{{ value|stripext }}', value='weblate/test.po'),
         'weblate/test',
     )
示例#28
0
 def test_dirname(self):
     self.assertEqual(
         render_template('{{ value|dirname }}', value='weblate/test.po'),
         'weblate')
示例#29
0
 def test_replace(self):
     self.assertEqual(
         render_template('{% replace "a-string-with-dashes" "-" " " %}'),
         'a string with dashes',
     )
示例#30
0
 def test_stripext(self):
     self.assertEqual(
         render_template('{{ value|stripext }}', value='weblate/test.po'),
         'weblate/test'
     )
示例#31
0
 def test_float(self):
     self.assertEqual(
         render_template('{{ number }}', number=1.1),
         '1.1'
     )
示例#32
0
 def test_dirname(self):
     self.assertEqual(
         render_template('{{ value|dirname }}', value='weblate/test.po'),
         'weblate'
     )
示例#33
0
 def test_parentdir(self):
     self.assertEqual(
         render_template("{{ value|parentdir }}", value="weblate/test.po"), "test.po"
     )
示例#34
0
 def test_stripext(self):
     self.assertEqual(
         render_template("{{ value|stripext }}", value="weblate/test.po"),
         "weblate/test",
     )
示例#35
0
 def test_dirname(self):
     self.assertEqual(
         render_template("{{ value|dirname }}", value="weblate/test.po"), "weblate"
     )
示例#36
0
 def test_float(self):
     self.assertEqual(render_template("{{ number }}", number=1.1), "1.1")
示例#37
0
文件: git.py 项目: nijel/weblate
 def get_merge_message(self):
     lines = render_template(
         self.component.pull_message.strip(), component=self.component
     ).splitlines()
     return lines[0], "\n".join(lines[1:]).strip()
示例#38
0
 def test_parentdir_chain(self):
     self.assertEqual(
         render_template('{{ value|parentdir|parentdir }}',
                         value='foo/bar/weblate/test.po'),
         'weblate/test.po',
     )
示例#39
0
 def get_commit_message(self, author: str, template: str, **kwargs):
     """Format commit message based on project configuration."""
     return render_template(template, translation=self, author=author, **kwargs)
示例#40
0
 def test_replace(self):
     self.assertEqual(
         render_template('{% replace "a-string-with-dashes" "-" " " %}'),
         'a string with dashes'
     )
示例#41
0
 def get_merge_message(self):
     return render_template(settings.DEFAULT_PULL_MESSAGE,
                            component=self.component).split("\n\n", 1)
示例#42
0
 def test_float(self):
     self.assertEqual(render_template('{{ number }}', number=1.1), '1.1')
示例#43
0
文件: git.py 项目: CFPAOrg/weblate
    def get_merge_message(self):
        from weblate.utils.render import render_template

        return render_template(settings.DEFAULT_PULL_MESSAGE,
                               component=self.component)
示例#44
0
 def test_parentdir(self):
     self.assertEqual(
         render_template('{{ value|parentdir }}', value='weblate/test.po'),
         'test.po'
     )