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
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
def changed_locales_files(self): """ Map of changed files and locales they were changed for. """ files = {} # VCS changes repos = self.db_project.translation_repositories() if self.repo_locales: repos = repos.filter(pk__in=self.repo_locales.keys()) for repo in repos: 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, changed_files)) # Include only relevant (localizable) files if self.configuration: files = self.get_relevant_files_with_config(changed_files) else: files = self.get_relevant_files_without_config( changed_files, self.locale_path_locales(repo.checkout_path)) log.info( "Changed files in {} repository, relevant for enabled locales: {}". format(self.db_project, files)) # DB changes vcs = files db = self.db_project.changed_resources(self.now) for path in set(list(vcs.keys()) + list(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
def changed_source_files(self): """ Returns a tuple of changed and removed source files in the project: (changed_files, removed_files) """ source_resources_repo = self.db_project.source_repository if not source_resources_repo: raise MissingSourceRepository(self.db_project) source_directory = self.source_directory_path last_revision = source_resources_repo.get_last_synced_revisions() modified_files, removed_files = get_changed_files( source_resources_repo.type, source_directory, last_revision) # Unify filesystem and data model file extensions if not self.configuration: modified_files = map(source_to_locale_path, modified_files) removed_files = map(source_to_locale_path, removed_files) if source_resources_repo.source_repo or not last_revision: def get_path(path): return (path, []) else: relative_source_path = source_directory[ len(source_resources_repo.checkout_path):].lstrip(os.sep) def get_path(path): return (path[len(relative_source_path):].lstrip(os.sep), []) return dict(map(get_path, modified_files)), dict(map(get_path, removed_files))
def changed_source_files(self): """ Returns a tuple of changed and removed source files in the project: (changed_files, removed_files) """ source_resources_repo = self.db_project.source_repository if not source_resources_repo: raise MissingSourceRepository(self.db_project) source_directory = self.source_directory_path last_revision = source_resources_repo.get_last_synced_revisions() modified_files, removed_files = get_changed_files(source_resources_repo.type, source_directory, last_revision) # Unify filesystem and data model file extensions modified_files = map(source_to_locale_path, modified_files) removed_files = map(source_to_locale_path, removed_files) if source_resources_repo.source_repo or not last_revision: get_path = lambda path: (path, []) else: relative_source_path = source_directory[len(source_resources_repo.checkout_path):].lstrip(os.sep) get_path = lambda path: (path[len(relative_source_path):].lstrip(os.sep), []) return dict(map(get_path, modified_files)), dict(map(get_path, removed_files))
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
def find_changed_files(repo, locale=None): """ Returns a dictionary that contains resource paths as keys and their list of locales as value. """ if repo.last_synced_revisions: last_revision = repo.last_synced_revisions.get(locale.code if locale else 'single_locale') else: last_revision = None # We have to filter out paths that are locale files checkout_path = repo.locale_checkout_path(locale) if locale else repo.checkout_path return get_changed_files(repo.type, checkout_path, last_revision)[0]