コード例 #1
0
class DirectBranchCommitTestCase:
    """Base class for `DirectBranchCommit` tests."""
    db_branch = None
    committer = None

    def setUp(self):
        super(DirectBranchCommitTestCase, self).setUp()
        self.useBzrBranches(direct_database=True)

        self.series = self.factory.makeProductSeries()
        self.db_branch, self.tree = self.create_branch_and_tree()

        self.series.translations_branch = self.db_branch

        self._setUpCommitter()
        self.addCleanup(self._tearDownCommitter)

    def _setUpCommitter(self, update_last_scanned_id=True):
        """Clean up any existing `DirectBranchCommit`, set up a new one."""
        if self.committer:
            self.committer.unlock()

        self.committer = DirectBranchCommit(self.db_branch)
        if update_last_scanned_id:
            self.committer.last_scanned_id = (
                self.committer.bzrbranch.last_revision())

    def _tearDownCommitter(self):
        if self.committer:
            self.committer.unlock()

    def _getContents(self):
        """Return branch contents as dict mapping filenames to contents."""
        return map_branch_contents(self.committer.db_branch.getBzrBranch())
コード例 #2
0
class DirectBranchCommitTestCase:
    """Base class for `DirectBranchCommit` tests."""
    db_branch = None
    committer = None

    def setUp(self):
        super(DirectBranchCommitTestCase, self).setUp()
        self.useBzrBranches(direct_database=True)

        self.series = self.factory.makeProductSeries()
        self.db_branch, self.tree = self.create_branch_and_tree()

        self.series.translations_branch = self.db_branch

        self._setUpCommitter()
        self.addCleanup(self._tearDownCommitter)

    def _setUpCommitter(self, update_last_scanned_id=True):
        """Clean up any existing `DirectBranchCommit`, set up a new one."""
        if self.committer:
            self.committer.unlock()

        self.committer = DirectBranchCommit(self.db_branch)
        if update_last_scanned_id:
            self.committer.last_scanned_id = (
                self.committer.bzrbranch.last_revision())

    def _tearDownCommitter(self):
        if self.committer:
            self.committer.unlock()

    def _getContents(self):
        """Return branch contents as dict mapping filenames to contents."""
        return map_branch_contents(self.committer.db_branch.getBzrBranch())
コード例 #3
0
def commit_file(branch, path, contents, merge_parents=None):
    """Create a commit that updates a file to specified contents.

    This will create or modify the file, as needed.
    """
    committer = DirectBranchCommit(
        removeSecurityProxy(branch), no_race_check=True,
        merge_parents=merge_parents)
    committer.writeFile(path, contents)
    try:
        return committer.commit('committing')
    finally:
        committer.unlock()