예제 #1
0
파일: models.py 프로젝트: pavels/pootle
    def _detect_treestyle(self):
        try:
            dirlisting = os.walk(self.get_real_path())
            dirpath, dirnames, filenames = dirlisting.next()

            if not dirnames:
                # No subdirectories
                if filter(self.file_belongs_to_project, filenames):
                    # Translation files found, assume gnu
                    return "gnu"

            # There are subdirectories
            if filter(lambda dirname: dirname == 'templates' or
                      langcode_re.match(dirname), dirnames):
                # Found language dirs assume nongnu
                return "nongnu"

            # No language subdirs found, look for any translation file
            for dirpath, dirnames, filenames in os.walk(self.get_real_path()):
                if filter(self.file_belongs_to_project, filenames):
                    return "gnu"
        except:
            pass

        # Unsure
        return None
예제 #2
0
def _detect_treestyle_and_path(Config, Language, project, proj_trans_path):
    dirlisting = os.walk(proj_trans_path)
    dirpath_, dirnames, filenames = dirlisting.next()

    if not dirnames:
        # No subdirectories
        if filter(partial(_file_belongs_to_project, project), filenames):
            # Translation files found, assume gnu
            return "gnu", ""

    # There are subdirectories
    languages = set(Language.objects.values_list("code", flat=True))
    lang_mapping_config = Config.objects.filter(
        content_type__model="project",
        object_pk=project.pk,
        key="pootle.core.lang_mappings").values_list("value",
                                                     flat=True).first()
    if lang_mapping_config:
        languages |= set(json.loads(lang_mapping_config).keys())
    has_subdirs = filter(
        (lambda dirname: ((dirname == 'templates' or langcode_re.match(dirname)
                           ) and dirname in languages)), dirnames)
    if has_subdirs:
        return "nongnu", None

    # No language subdirs found, look for any translation file
    # in subdirs
    for dirpath_, dirnames, filenames in os.walk(proj_trans_path):
        if filter(partial(_file_belongs_to_project, project), filenames):
            return "gnu", dirpath_.replace(proj_trans_path, "")
    # Unsure
    return "nongnu", None
예제 #3
0
파일: models.py 프로젝트: lehmannro/pootle
    def get_treestyle(self):
        """returns the real treestyle, if treestyle is set to auto it
        checks the project directory and tries to guess if it is gnu
        style or nongnu style.

        we are biased towards nongnu because it makes managing project
        from the web easier"""

        if self.treestyle != "auto":
            return self.treestyle
        else:
            dirlisting = os.walk(self.get_real_path())
            dirpath, dirnames, filenames = dirlisting.next()

            if not dirnames:
                # no subdirectories
                if filter(self.file_belongs_to_project, filenames):
                    # translation files found, assume gnu
                    return "gnu"
                else:
                    # no subdirs and no translation files, assume nongnu
                    return "nongnu"
            else:
                # there are subdirectories
                if filter(lambda dirname: dirname == 'templates' or langcode_re.match(dirname), dirnames):
                    # found language dirs assume nongnu
                    return "nongnu"
                else:
                    # no language subdirs found, look for any translation file
                    for dirpath, dirnames, filenames in os.walk(self.get_real_path()):
                        if filter(self.file_belongs_to_project, filenames):
                            return "gnu"
            # when unsure assume nongnu
            return "nongnu"
예제 #4
0
def _detect_treestyle_and_path(project, proj_trans_path):
    dirlisting = os.walk(proj_trans_path)
    dirpath_, dirnames, filenames = dirlisting.next()

    if not dirnames:
        # No subdirectories
        if filter(partial(_file_belongs_to_project, project), filenames):
            # Translation files found, assume gnu
            return "gnu", ""

    # There are subdirectories
    has_subdirs = filter(
        (lambda dirname: dirname == 'templates'
         or langcode_re.match(dirname)),
        dirnames)
    if has_subdirs:
        return "nongnu", None

    # No language subdirs found, look for any translation file
    # in subdirs
    for dirpath_, dirnames, filenames in os.walk(proj_trans_path):
        if filter(partial(_file_belongs_to_project, project), filenames):
            return "gnu", dirpath_.replace(proj_trans_path, "")
    # Unsure
    return "nongnu", None
예제 #5
0
 def clean_code(self):
     if not self.cleaned_data['code'] == 'templates' and not langcode_re.match(self.cleaned_data['code']):
         raise forms.ValidationError(_('Language code does not follow the ISO convention'))
     return self.cleaned_data["code"]