Пример #1
0
    def get_resource_files(self, resource):
        """
        Get a dict for all files assigned to a resource. First we calculate the
        files matching the file expression and then we apply all translation
        excpetions. The resulting dict will be in this format:

        { 'en': 'path/foo/en/bar.po', 'de': 'path/foo/de/bar.po', 'es': 'path/exceptions/es.po'}

        NOTE: All paths are relative to the root of the project
        """
        tr_files = {}
        if self.config.has_section(resource):
            try:
                file_filter = self.config.get(resource, "file_filter")
            except configparser.NoOptionError:
                file_filter = "$^"
            source_lang = self.config.get(resource, "source_lang")
            source_file = self.get_source_file(resource)
            expr_re = regex_from_filefilter(file_filter, self.root)
            expr_rec = re.compile(expr_re)
            for f_path in files_in_project(self.root):
                match = expr_rec.match(posix_path(f_path))
                if match:
                    lang = match.group(1)
                    if lang != source_lang:
                        f_path = os.path.relpath(f_path, self.root)
                        if f_path != source_file:
                            tr_files.update({lang: f_path})

            for (name, value) in self.config.items(resource):
                if name.startswith("trans."):
                    value = native_path(value)
                    lang = name.split('.')[1]
                    # delete language which has same file
                    if value in list(tr_files.values()):
                        keys = []
                        for k, v in six.iteritems(tr_files):
                            if v == value:
                                keys.append(k)
                        if len(keys) == 1:
                            del tr_files[keys[0]]
                        else:
                            raise Exception("Your configuration seems wrong."\
                                " You have multiple languages pointing to"\
                                " the same file.")
                    # Add language with correct file
                    tr_files.update({lang:value})

            return tr_files

        return None
Пример #2
0
    def get_resource_files(self, resource):
        """
        Get a dict for all files assigned to a resource. First we calculate the
        files matching the file expression and then we apply all translation
        excpetions. The resulting dict will be in this format:

        { 'en': 'path/foo/en/bar.po', 'de': 'path/foo/de/bar.po', 'es': 'path/exceptions/es.po'}

        NOTE: All paths are relative to the root of the project
        """
        tr_files = {}
        if self.config.has_section(resource):
            try:
                file_filter = self.config.get(resource, "file_filter")
            except configparser.NoOptionError:
                file_filter = "$^"
            source_lang = self.config.get(resource, "source_lang")
            source_file = self.get_source_file(resource)
            expr_re = regex_from_filefilter(file_filter, self.root)
            expr_rec = re.compile(expr_re)
            for f_path in files_in_project(self.root):
                match = expr_rec.match(posix_path(f_path))
                if match:
                    lang = match.group(1)
                    if lang != source_lang:
                        f_path = os.path.relpath(f_path, self.root)
                        if f_path != source_file:
                            tr_files.update({lang: f_path})

            for (name, value) in self.config.items(resource):
                if name.startswith("trans."):
                    value = native_path(value)
                    lang = name.split('.')[1]
                    # delete language which has same file
                    if value in list(tr_files.values()):
                        keys = []
                        for k, v in six.iteritems(tr_files):
                            if v == value:
                                keys.append(k)
                        if len(keys) == 1:
                            del tr_files[keys[0]]
                        else:
                            raise Exception("Your configuration seems wrong."\
                                " You have multiple languages pointing to"\
                                " the same file.")
                    # Add language with correct file
                    tr_files.update({lang: value})

            return tr_files

        return None
Пример #3
0
 def update(self, other=None, **kwargs):
     # Copied from python's UserDict.DictMixin code.
     # Make progressively weaker assumptions about "other"
     if other is None:
         pass
     elif hasattr(other, "items"):
         for k, v in six.iteritems(other):
             self[k] = v
     elif hasattr(other, "keys"):
         for k in list(other.keys()):
             self[k] = other[k]
     else:
         for k, v in other:
             self[k] = v
     if kwargs:
         self.update(kwargs)
Пример #4
0
 def update(self, other=None, **kwargs):
     # Copied from python's UserDict.DictMixin code.
     # Make progressively weaker assumptions about "other"
     if other is None:
         pass
     elif hasattr(other, 'items'):
         for k, v in six.iteritems(other):
             self[k] = v
     elif hasattr(other, 'keys'):
         for k in list(other.keys()):
             self[k] = other[k]
     else:
         for k, v in other:
             self[k] = v
     if kwargs:
         self.update(kwargs)
Пример #5
0
 def __init__(self, *args, **kw):
     self._flip = dict.__new__(self.__class__)
     setattr(self._flip, "_flip", self)
     for key, val in six.iteritems(dict(*args, **kw)):
         self[key] = val
Пример #6
0
 def __init__(self, *args, **kw):
     self._flip = dict.__new__(self.__class__)
     setattr(self._flip, "_flip", self)
     for key, val in six.iteritems(dict(*args, **kw)):
         self[key] = val