def _init_translation_file_lists(self): """Initialize the member variables that hold the information about the relevant files. The information is collected from the branch tree and stored in the following member variables: * file_names is a dictionary of two lists ('pot', 'po') of file names that are POT or PO files respectively. This includes all files, changed or unchanged. * changed_files is a dictionary of two lists ('pot', 'po') of tuples of (file_name, file_content) of all changed files that are POT or PO files respectively. """ bzrbranch = self.branch.getBzrBranch() from_tree = bzrbranch.repository.revision_tree( self.from_revision_id) to_tree = bzrbranch.repository.revision_tree( self.branch.last_scanned_id) importer = TranslationImporter() to_tree.lock_read() try: for dir, files in to_tree.walkdirs(): for afile in files: file_path, file_name, file_type = afile[:3] if file_type != 'file': continue if importer.isHidden(file_path): continue if importer.isTemplateName(file_name): append_to = self.template_file_names elif importer.isTranslationName(file_name): append_to = self.translation_file_names else: continue append_to.append(file_path) from_tree.lock_read() try: for file_names, changed_files in self._iter_all_lists(): for changed_file in to_tree.iter_changes( from_tree, specific_files=file_names): (from_kind, to_kind) = changed_file[6] if to_kind != 'file': continue file_id, (from_path, to_path) = changed_file[:2] changed_files.append(( to_path, to_tree.get_file_text(file_id))) finally: from_tree.unlock() finally: to_tree.unlock()
def _init_translation_file_lists(self): """Initialize the member variables that hold the information about the relevant files. The information is collected from the branch tree and stored in the following member variables: * file_names is a dictionary of two lists ('pot', 'po') of file names that are POT or PO files respectively. This includes all files, changed or unchanged. * changed_files is a dictionary of two lists ('pot', 'po') of tuples of (file_name, file_content) of all changed files that are POT or PO files respectively. """ bzrbranch = self.branch.getBzrBranch() from_tree = bzrbranch.repository.revision_tree( self.from_revision_id) to_tree = bzrbranch.repository.revision_tree( self.branch.last_scanned_id) importer = TranslationImporter() to_tree.lock_read() try: for dir, files in to_tree.walkdirs(): for afile in files: file_path, file_name, file_type = afile[:3] if file_type != 'file': continue if importer.isHidden(file_path): continue if importer.isTemplateName(file_name): append_to = self.template_file_names elif importer.isTranslationName(file_name): append_to = self.translation_file_names else: continue append_to.append(file_path) from_tree.lock_read() try: for file_names, changed_files in self._iter_all_lists(): for changed_file in to_tree.iter_changes( from_tree, specific_files=file_names): (from_kind, to_kind) = changed_file[6] if to_kind != 'file': continue file_id, (from_path, to_path) = changed_file[:2] changed_files.append(( to_path, to_tree.get_file_text(file_id))) finally: from_tree.unlock() finally: to_tree.unlock()
def __init__(self, files, productseries=None, distroseries=None, sourcepackagename=None): """Create the approver and build the approval list by comparing the given files as found in the source tree to the database entries. Either productseries or distroseries/sourcepackagename must be given but not all. :param files: A list of paths to the translation files. :param productseries: The productseries that this upload is for. :param distroseries: The distroseries that this upload is for. :param sourcepackagename: The sourcepackagename that this upload is for. """ assert (distroseries is None or sourcepackagename is not None), ( "Please specify distroseries and sourcepackagename together.") self._potemplates = {} self._n_matched = 0 self.is_approval_possible = True potemplate_names = set() product_name = get_product_name(productseries) importer = TranslationImporter() self._potemplateset = getUtility(IPOTemplateSet).getSubset( iscurrent=True, productseries=productseries, distroseries=distroseries, sourcepackagename=sourcepackagename) for path in files: if importer.isTemplateName(path): potemplate = self._potemplateset.getPOTemplateByPath(path) if potemplate is None: name = make_name_from_path(path, default=product_name) potemplate = self._potemplateset.getPOTemplateByName(name) else: name = potemplate.name # Template names must occur only once. if name in potemplate_names: self.is_approval_possible = False else: potemplate_names.add(name) if potemplate is not None: self._n_matched += 1 self._potemplates[path] = potemplate # The simplest case of exactly one file and one POTemplate object is # always approved. if len(self._potemplateset) == len(self._potemplates) == 1: self._potemplates[self._potemplates.keys()[0]] = ( list(self._potemplateset)[0]) self.is_approval_possible = True