def get_local_filename(translation_project, upload_filename): base, ext = os.path.splitext(upload_filename) new_ext = translation_project.project.localfiletype if new_ext == 'po' and translation_project.is_template_project: new_ext = 'pot' local_filename = '%s.%s' % (base, new_ext) # check if name is valid if (os.path.basename(local_filename) != local_filename or local_filename.startswith(".")): raise ValueError(_("Invalid/insecure file name: %s", local_filename)) # XXX: Leakage of the project layout information outside of # project_tree.py! The rest of Pootle shouldn't have to care # whether something is GNU-style or not. if (translation_project.file_style == "gnu" and not translation_project.is_template_project): if not direct_language_match_filename(translation_project.language.code, local_filename): raise ValueError(_("Invalid GNU-style file name: " "%(local_filename)s. It must match " "'%(langcode)s.%(filetype)s'.", {'local_filename': local_filename, 'langcode': translation_project.language.code, 'filetype': translation_project.project.localfiletype, })) return local_filename
def scan_files(self): """returns a list of po files for the project and language""" ignored_files = set(p.strip() for p in self.project.ignoredfiles.split(',')) ext = os.extsep + self.project.localfiletype # scan for pots if template project if self.is_template_project: ext = os.extsep + self.project.get_template_filtetype() if self.file_style == 'gnu': if self.pootle_path.startswith('/templates/'): add_files( self, ignored_files, ext, self.abs_real_path, self.directory, lambda filename: match_template_filename( self.project, filename)) else: add_files( self, ignored_files, ext, self.abs_real_path, self.directory, lambda filename: direct_language_match_filename( self.language.code, filename)) else: add_files(self, ignored_files, ext, self.abs_real_path, self.directory)
def scan_files(self): """Returns a list of translation files for the project and language.""" projects = [p.strip() for p in self.project.ignoredfiles.split(',')] ignored_files = set(projects) ext = os.extsep + self.project.localfiletype # Scan for pots if template project if self.is_template_project: ext = os.extsep + self.project.get_template_filetype() from pootle_app.project_tree import add_files, match_template_filename,\ direct_language_match_filename all_files = [] new_files = [] if self.file_style == 'gnu': if self.pootle_path.startswith('/templates/'): all_files, new_files = add_files(self, ignored_files, ext, self.real_path, self.directory, lambda filename: match_template_filename(\ self.project, filename)) else: all_files, new_files = add_files(self, ignored_files, ext,\ self.real_path, self.directory, lambda filename: direct_language_match_filename(\ self.language.code, filename)) else: all_files, new_files = add_files(self, ignored_files, ext, \ self.real_path, self.directory) return all_files, new_files
def get_local_filename(translation_project, upload_filename): base, ext = os.path.splitext(upload_filename) new_ext = translation_project.project.localfiletype if new_ext == 'po' and translation_project.is_template_project: new_ext = 'pot' local_filename = '%s.%s' % (base, new_ext) # check if name is valid if (os.path.basename(local_filename) != local_filename or local_filename.startswith(".")): raise ValueError(_("Invalid/insecure file name: %s", local_filename)) # XXX: Leakage of the project layout information outside of # project_tree.py! The rest of Pootle shouldn't have to care # whether something is GNU-style or not. if (translation_project.file_style == "gnu" and not translation_project.is_template_project): if not direct_language_match_filename( translation_project.language.code, local_filename): raise ValueError( _( "Invalid GNU-style file name: " "%(local_filename)s. It must match " "'%(langcode)s.%(filetype)s'.", { 'local_filename': local_filename, 'langcode': translation_project.language.code, 'filetype': translation_project.project.localfiletype, })) return local_filename
def scan_files(self): """returns a list of po files for the project and language""" ignored_files = set(p.strip() for p in self.project.ignoredfiles.split(",")) ext = os.extsep + self.project.localfiletype # scan for pots if template project if self.is_template_project: ext = os.extsep + self.project.get_template_filtetype() if self.file_style == "gnu": if self.pootle_path.startswith("/templates/"): add_files( self, ignored_files, ext, self.abs_real_path, self.directory, lambda filename: match_template_filename(self.project, filename), ) else: add_files( self, ignored_files, ext, self.abs_real_path, self.directory, lambda filename: direct_language_match_filename(self.language.code, filename), ) else: add_files(self, ignored_files, ext, self.abs_real_path, self.directory)
def scan_files(self): """Scans the file system and returns a list of translation files. """ projects = [p.strip() for p in self.project.ignoredfiles.split(",")] ignored_files = set(projects) ext = os.extsep + self.project.localfiletype # Scan for pots if template project if self.is_template_project: ext = os.extsep + self.project.get_template_filetype() from pootle_app.project_tree import add_files, match_template_filename, direct_language_match_filename all_files = [] new_files = [] if self.file_style == "gnu": if self.pootle_path.startswith("/templates/"): file_filter = lambda filename: match_template_filename(self.project, filename) else: file_filter = lambda filename: direct_language_match_filename(self.language.code, filename) else: file_filter = lambda filename: True all_files, new_files, is_empty = add_files( self, ignored_files, ext, self.real_path, self.directory, file_filter ) return all_files, new_files
def scan_files(self, vcs_sync=True): """Scans the file system and returns a list of translation files. :param vcs_sync: boolean on whether or not to synchronise the PO directory with the VCS checkout. """ projects = [p.strip() for p in self.project.ignoredfiles.split(',')] ignored_files = set(projects) ext = os.extsep + self.project.localfiletype # Scan for pots if template project if self.is_template_project: ext = os.extsep + self.project.get_template_filetype() from pootle_app.project_tree import (add_files, match_template_filename, direct_language_match_filename, sync_from_vcs) all_files = [] new_files = [] if self.file_style == 'gnu': if self.pootle_path.startswith('/templates/'): file_filter = lambda filename: match_template_filename( self.project, filename, ) else: file_filter = lambda filename: direct_language_match_filename( self.language.code, filename, ) else: file_filter = lambda filename: True if vcs_sync: sync_from_vcs(ignored_files, ext, self.real_path, file_filter) all_files, new_files = add_files( self, ignored_files, ext, self.real_path, self.directory, file_filter, ) return all_files, new_files
def scan_files(self, vcs_sync=True): """Scan the file system and return a list of translation files. :param vcs_sync: boolean on whether or not to synchronise the PO directory with the VCS checkout. """ proj_ignore = [p.strip() for p in self.project.ignoredfiles.split(',')] ignored_files = set(proj_ignore) ext = os.extsep + self.project.localfiletype # Scan for pots if template project if self.is_template_project: ext = os.extsep + self.project.get_template_filetype() from pootle_app.project_tree import (add_files, match_template_filename, direct_language_match_filename, sync_from_vcs) all_files = [] new_files = [] if self.file_style == 'gnu': if self.pootle_path.startswith('/templates/'): file_filter = lambda filename: match_template_filename( self.project, filename, ) else: file_filter = lambda filename: direct_language_match_filename( self.language.code, filename, ) else: file_filter = lambda filename: True if vcs_sync: sync_from_vcs(ignored_files, ext, self.real_path, file_filter) all_files, new_files = add_files( self, ignored_files, ext, self.real_path, self.directory, file_filter, ) return all_files, new_files
def scan_files(self): """Scans the file system and returns a list of translation files. """ projects = [p.strip() for p in self.project.ignoredfiles.split(',')] ignored_files = set(projects) filetypes = self.project.filetype_tool exts = filetypes.filetype_extensions # Scan for pots if template project if self.is_template_project: exts = filetypes.template_extensions from pootle_app.project_tree import (add_files, match_template_filename, direct_language_match_filename) all_files = [] new_files = [] if self.file_style == 'gnu': if self.pootle_path.startswith('/templates/'): file_filter = lambda filename: match_template_filename( self.project, filename, ) else: file_filter = lambda filename: direct_language_match_filename( self.language.code, filename, ) else: file_filter = lambda filename: True all_files, new_files, __ = add_files( self, ignored_files, exts, self.real_path, self.directory, file_filter, ) return all_files, new_files
def scan_files(self): """Scans the file system and returns a list of translation files. """ projects = [p.strip() for p in self.project.ignoredfiles.split(',')] ignored_files = set(projects) filetypes = self.project.filetype_tool exts = filetypes.filetype_extensions # Scan for pots if template project if self.is_template_project: exts = filetypes.template_extensions from pootle_app.project_tree import (add_files, match_template_filename, direct_language_match_filename) all_files = [] new_files = [] if self.file_style == 'gnu': if self.pootle_path.startswith('/templates/'): file_filter = lambda filename: match_template_filename( self.project, filename,) else: file_filter = lambda filename: direct_language_match_filename( self.language.code, filename,) else: file_filter = lambda filename: True all_files, new_files, __ = add_files( self, ignored_files, exts, self.real_path, self.directory, file_filter, ) return all_files, new_files
def test_direct_language_match_filename(language_code, path_name, matched): with keep_data(signals=(update_revisions, ), suppress=(Directory, Store)): LanguageDBFactory(code="pt_BR") assert direct_language_match_filename(language_code, path_name) is matched
def test_direct_language_match_filename(language_code, path_name, matched): LanguageDBFactory(code="pt_BR") assert direct_language_match_filename(language_code, path_name) is matched