def _exportToBranch(self, source): """Export translations for source into source.translations_branch. :param source: a `ProductSeries`. """ self.logger.info("Exporting %s." % source.title) self._checkForObjections(source) branch = source.translations_branch branch = source.translations_branch try: committer = self._makeDirectBranchCommit(branch) except StaleLastMirrored as e: # Request a rescan of the branch. Do this on the master # store, or we won't be able to modify the branch object. # (The master copy may also be more recent, in which case # the rescan won't be necessary). master_branch = IMasterStore(branch).get(Branch, branch.id) master_branch.branchChanged(**get_db_branch_info(**e.info)) self.logger.warning( "Skipped %s due to stale DB info, and scheduled a new scan.", branch.bzr_identity) if self.txn: self.txn.commit() return self.logger.debug("Created DirectBranchCommit.") if self.txn: self.txn.commit() bzr_branch = committer.bzrbranch last_commit_date = self._getLatestTranslationsCommit(bzr_branch) if last_commit_date is None: self.logger.debug("No previous translations commit found.") changed_since = None else: # Export files that have been touched since the last export. # Subtract a fudge factor because the last-export date marks # the end of the previous export, and the POFiles' # last-touched timestamp marks the beginning of the last # transaction that changed them. self.logger.debug("Last commit was at %s." % last_commit_date) changed_since = last_commit_date - self.fudge_factor change_count = 0 try: for pofile in self._findChangedPOFiles(source, changed_since): base_path = os.path.dirname(pofile.potemplate.path) language_code = pofile.getFullLanguageCode() self.logger.debug("Exporting %s." % language_code) pofile_path = os.path.join( base_path, language_code + '.po') pofile_contents = pofile.export() committer.writeFile(pofile_path, pofile_contents) change_count += 1 # We're not actually writing any changes to the # database, but it's not polite to stay in one # transaction for too long. if self.txn: self.txn.commit() # We're done with this POFile. Don't bother caching # anything about it any longer. pofile.potemplate.clearPOFileCache() if change_count > 0: self.logger.debug("Writing to branch.") self._commit(source, committer) finally: committer.unlock()