コード例 #1
0
    def changed_locales_files(self):
        """
        Map of changed files and locales they were changed for.
        """
        files = {}

        # VCS changes
        for repo in self.db_project.translation_repositories():
            if repo.multi_locale:
                locales = self.repo_locales[
                    repo.
                    pk] if self.repo_locales else self.db_project.locales.all(
                    )
                for locale in locales:
                    changed_files = get_changed_files(
                        repo.type, repo.locale_checkout_path(locale),
                        repo.get_last_synced_revisions(locale.code))[0]

                    for path in changed_files:
                        files.setdefault(path, []).append(locale)
            else:
                changed_files = get_changed_files(
                    repo.type, repo.checkout_path,
                    repo.get_last_synced_revisions())[0]

                log.info('Changed files in {} repository, all: {}'.format(
                    self.db_project.name, changed_files))

                # Find relevant changes in repository by matching changed
                # paths against locale repository paths
                locale_path_locales = self.locale_path_locales(
                    repo.checkout_path)
                locale_paths = locale_path_locales.keys()

                for path in changed_files:
                    if is_hidden(path):
                        continue

                    for locale_path in locale_paths:
                        if path.startswith(locale_path):
                            locale = locale_path_locales[locale_path]
                            path = path[len(locale_path):].lstrip(os.sep)
                            files.setdefault(path, []).append(locale)
                            break

        log.info(
            'Changed files in {} repository, relevant for enabled locales: {}'.
            format(self.db_project.name, files))

        # DB changes
        vcs = files
        db = self.db_project.changed_resources
        for path in set(vcs.keys() + db.keys()):
            if path in vcs and path in db:
                vcs[path] = set(list(vcs[path]) + list(db[path]))

            else:
                vcs[path] = vcs[path] if path in vcs else db[path]

        return files
コード例 #2
0
ファイル: models.py プロジェクト: kostich/pontoon
    def changed_locales_files(self):
        """
        Map of changed files and locales they were changed for.
        """
        files = {}

        # VCS changes
        for repo in self.db_project.translation_repositories():
            if repo.multi_locale:
                locales = self.repo_locales[repo.pk] if self.repo_locales else self.db_project.locales.all()
                for locale in locales:
                    changed_files = get_changed_files(
                        repo.type,
                        repo.locale_checkout_path(locale),
                        repo.get_last_synced_revisions(locale.code)
                    )[0]

                    for path in changed_files:
                        files.setdefault(path, []).append(locale)
            else:
                changed_files = get_changed_files(
                    repo.type,
                    repo.checkout_path,
                    repo.get_last_synced_revisions()
                )[0]

                log.info('Changed files in {} repository, all: {}'.format(self.db_project.name, changed_files))

                # Find relevant changes in repository by matching changed
                # paths against locale repository paths
                locale_path_locales = self.locale_path_locales(repo.checkout_path)
                locale_paths = locale_path_locales.keys()

                for path in changed_files:
                    if is_hidden(path):
                        continue

                    for locale_path in locale_paths:
                        if path.startswith(locale_path):
                            locale = locale_path_locales[locale_path]
                            path = path[len(locale_path):].lstrip(os.sep)
                            files.setdefault(path, []).append(locale)
                            break

        log.info('Changed files in {} repository, relevant for enabled locales: {}'.format(self.db_project.name, files))

        # DB changes
        vcs = files
        db = self.db_project.changed_resources
        for path in set(vcs.keys() + db.keys()):
            if path in vcs and path in db:
                vcs[path] = set(list(vcs[path]) + list(db[path]))

            else:
                vcs[path] = vcs[path] if path in vcs else db[path]

        return files
コード例 #3
0
ファイル: models.py プロジェクト: sa-tasche/pontoon
    def resource_paths_with_config(self):
        """
        List of absolute paths for all supported source resources
        as specified through project configuration.
        """
        path = self.source_directory_path
        project_files = self.configuration.get_or_set_project_files(None)

        for root, dirnames, filenames in scandir.walk(path):
            if is_hidden(root):
                continue

            for filename in filenames:
                absolute_path = os.path.join(root, filename)
                if project_files.match(absolute_path):
                    yield absolute_path
コード例 #4
0
    def resources_for_path(self, path):
        """
        List of paths for all supported resources found within the given
        path.
        """
        for root, dirnames, filenames in scandir.walk(path):
            if is_hidden(root):
                continue

            # Ignore certain files in Mozilla repositories.
            if self.db_project.repository_url in MOZILLA_REPOS:
                filenames = [f for f in filenames if not f.endswith('region.properties')]

            for filename in filenames:
                if is_resource(filename):
                    yield os.path.join(root, filename)
コード例 #5
0
ファイル: models.py プロジェクト: kostich/pontoon
    def resources_for_path(self, path):
        """
        List of paths for all supported resources found within the given
        path.
        """
        for root, dirnames, filenames in os.walk(path):
            if is_hidden(root):
                continue

            # Ignore certain files in Mozilla repositories.
            if self.db_project.repository_url in MOZILLA_REPOS:
                filenames = [f for f in filenames if not f.endswith('region.properties')]

            for filename in filenames:
                if is_resource(filename):
                    yield os.path.join(root, filename)
コード例 #6
0
ファイル: models.py プロジェクト: Pike/pontoon
    def resource_paths_with_config(self):
        """
        List of absolute paths for all supported source resources
        as specified through project configuration.
        """
        path = self.source_directory_path
        project_files = self.configuration.get_or_set_project_files(None)

        for root, dirnames, filenames in scandir.walk(path):
            if is_hidden(root):
                continue

            for filename in filenames:
                absolute_path = os.path.join(root, filename)
                if project_files.match(absolute_path):
                    yield absolute_path
コード例 #7
0
    def changed_locales_files(self):
        """
        Map of changed files and locales they were changed for.
        """
        files = {}

        # VCS changes
        for repo in self.db_project.translation_repositories():
            if repo.multi_locale:
                for locale in self.db_project.locales.all():
                    changed_files = get_changed_files(
                        repo.type, repo.locale_checkout_path(locale),
                        repo.get_last_synced_revisions(locale.code))[0]

                    for path in changed_files:
                        files.setdefault(path, []).append(locale)
            else:
                changed_files = get_changed_files(
                    repo.type, repo.checkout_path,
                    repo.get_last_synced_revisions())[0]

                locale_path_locales = self.locale_path_locales()
                locale_paths = locale_path_locales.keys()

                for path in changed_files:
                    if is_hidden(path):
                        continue

                    for locale_path in locale_paths:
                        if path.startswith(locale_path):
                            locale = locale_path_locales[locale_path]
                            path = path[len(locale_path):].lstrip(os.sep)
                            files.setdefault(path, []).append(locale)
                            break

        # DB changes
        vcs = files
        db = self.db_project.changed_resources
        for path in set(vcs.keys() + db.keys()):
            if path in vcs and path in db:
                vcs[path] = set(list(vcs[path]) + list(db[path]))

            else:
                vcs[path] = vcs[path] if path in vcs else db[path]

        return files
コード例 #8
0
ファイル: models.py プロジェクト: Pike/pontoon
    def resource_paths_without_config(self):
        """
        List of absolute paths for all supported source resources
        found within the given path.
        """
        path = self.source_directory_path

        for root, dirnames, filenames in scandir.walk(path):
            if is_hidden(root):
                continue

            # Ignore certain files in Mozilla repositories.
            if self.db_project.repository_url in MOZILLA_REPOS:
                filenames = [f for f in filenames if not f.endswith('region.properties')]

            for filename in filenames:
                if is_resource(filename):
                    yield os.path.join(root, filename)
コード例 #9
0
    def get_path_info(self, path, repo):
        """
        Checks if path inside one of locale directories.
        Returns a tuple with information on given path or None if can't find any.
        Tuple contains:
        - path to the given file
        - path to the locale directory
        - locale code
        """
        if is_hidden(path):
            return None

        try:
            locale_path, locale = next((p, l) for p, l in self.locale_directories(repo).items() if path.startswith(p))
        except StopIteration:
            return None

        return path, locale_path, locale
コード例 #10
0
ファイル: models.py プロジェクト: sa-tasche/pontoon
    def resource_paths_without_config(self):
        """
        List of absolute paths for all supported source resources
        found within the given path.
        """
        path = self.source_directory_path

        for root, dirnames, filenames in scandir.walk(path):
            if is_hidden(root):
                continue

            # Ignore certain files in Mozilla repositories.
            if self.db_project.repository_url in MOZILLA_REPOS:
                filenames = [
                    f for f in filenames if not f.endswith("region.properties")
                ]

            for filename in filenames:
                if is_resource(filename):
                    yield os.path.join(root, filename)
コード例 #11
0
ファイル: models.py プロジェクト: sa-tasche/pontoon
    def get_relevant_files_without_config(self, paths, locale_path_locales):
        """
        Check if given paths represent localizable files by matching them against locale
        repository paths. Return a dict of relative reference paths of such paths and
        corresponding Locale objects.
        """
        files = {}
        locale_paths = locale_path_locales.keys()

        for path in paths:
            if is_hidden(path):
                continue

            for locale_path in locale_paths:
                if path.startswith(locale_path):
                    locale = locale_path_locales[locale_path]
                    path = path[len(locale_path):].lstrip(os.sep)
                    files.setdefault(path, []).append(locale)
                    break

        return files