Rev 1: Bootstrap in http://people.ubuntu.com/~robertc/baz2.0/plugins/repodetails/trunk

Robert Collins robertc at robertcollins.net
Fri Oct 17 02:50:01 BST 2008


At http://people.ubuntu.com/~robertc/baz2.0/plugins/repodetails/trunk

------------------------------------------------------------
revno: 1
revision-id: robertc at robertcollins.net-20081017015000-00m52hln7vqsye3d
committer: Robert Collins <robertc at robertcollins.net>
branch nick: trunk
timestamp: Fri 2008-10-17 12:50:00 +1100
message:
  Bootstrap
added:
  README                         readme-20081017014933-iriuw53viune2txe-1
  __init__.py                    __init__.py-20081017014933-iriuw53viune2txe-2
  setup.py                       setup.py-20081017014933-iriuw53viune2txe-3
  tests/                         tests-20081017014933-iriuw53viune2txe-4
  tests/__init__.py              __init__.py-20081017014933-iriuw53viune2txe-5
  tests/test_repositorydetails.py test_repositorydetai-20081017014933-iriuw53viune2txe-6
=== added file 'README'
--- a/README	1970-01-01 00:00:00 +0000
+++ b/README	2008-10-17 01:50:00 +0000
@@ -0,0 +1,4 @@
+repodetails - get detailed information about repository usage.
+
+Install as any normal bzr plugin, see bzr help repodetails for usage details.
+

=== added file '__init__.py'
--- a/__init__.py	1970-01-01 00:00:00 +0000
+++ b/__init__.py	2008-10-17 01:50:00 +0000
@@ -0,0 +1,94 @@
+# RepositoryDetails, a bzr plugin for analysing repository details.
+# Copyright (C) 2008 Canonical Limited.
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+# 
+
+"""Repository details provides analysis of repository storage.
+
+The repository-details command is the only tool so far.
+"""
+
+version_info = (1, 9, 0, 'dev', 0)
+
+import bzrlib.commands
+from bzrlib import repository
+
+
+class ObjectStats(object):
+    """Statistics for a particular type of object."""
+
+    def __init__(self):
+        self.objects = 1
+        self.raw_size = 1
+        self.compressed_size = 1
+
+
+class RepoStats(object):
+    """Statistics for a repository."""
+
+
+def gather_stats(repo):
+    """Gather statistics on a repository.
+    
+    :param repo: A repository.
+    :return: A stats object.
+    """
+    repo.lock_read()
+    try:
+        return _gather_stats_locked(repo)
+    finally:
+        repo.unlock()
+
+
+def _gather_stats_locked(repo):
+    result = RepoStats()
+    result.revision_count = 1
+    result.revisions = ObjectStats()
+    result.inventories = ObjectStats()
+    result.texts = ObjectStats()
+    result.signatures = ObjectStats()
+    result.signatures.objects = len(repo.signatures.keys())
+    return result
+
+
+class cmd_repository_details(bzrlib.commands.Command):
+    """Get details for a bzr repository."""
+
+    def _format_object(self, objectstats):
+        return "%6d KiB  %6d KiB %7d" % (objectstats.raw_size/1024,
+            objectstats.compressed_size/1024, objectstats.objects)
+
+    def run(self):
+        repo = repository.Repository.open(".")
+        stats = gather_stats(repo)
+        self.outf.write("Commits: %d\n" % stats.revision_count)
+        self.outf.write("                    Raw  Compressed Objects\n")
+        self.outf.write("Revisions:   %s\n" %
+            self._format_object(stats.revisions))
+        self.outf.write("Inventories: %s\n" %
+            self._format_object(stats.inventories))
+        self.outf.write("Texts:       %s\n" %
+            self._format_object(stats.texts))
+        self.outf.write("Signatures:  %s\n" %
+            self._format_object(stats.signatures))
+
+
+bzrlib.commands.register_command(cmd_repository_details)
+
+
+def load_tests(standard_tests, module, loader):
+    standard_tests.addTests(loader.loadTestsFromModuleNames(
+        ['bzrlib.plugins.repodetails.tests']))
+    return standard_tests

=== added file 'setup.py'
--- a/setup.py	1970-01-01 00:00:00 +0000
+++ b/setup.py	2008-10-17 01:50:00 +0000
@@ -0,0 +1,24 @@
+#!/usr/bin/env python2.4
+from distutils.core import setup
+
+bzr_plugin_name = 'repodetails'
+bzr_commands = [
+    'repodetails',
+    ]
+
+bzr_plugin_version = (1, 9, 0, 'dev', 0)
+bzr_minimum_version = (1, 9, 0)
+bzr_maximum_version = None
+
+if __name__ == 'main':
+    setup(name="Repository details",
+          version="1.9.0dev0",
+          description="Repository analysis plugin for bzr.",
+          author="Canonical Ltd",
+          author_email="bazaar at lists.canonical.com",
+          license = "GNU GPL v2",
+          url="https://launchpad.net/bzr-repodetails",
+          packages=['bzrlib.plugins.repodetails',
+                    'bzrlib.plugins.repodetails.tests',
+                    ],
+          package_dir={'bzrlib.plugins.repodetails': '.'})

=== added directory 'tests'
=== added file 'tests/__init__.py'
--- a/tests/__init__.py	1970-01-01 00:00:00 +0000
+++ b/tests/__init__.py	2008-10-17 01:50:00 +0000
@@ -0,0 +1,29 @@
+# Copyright (C) 2008 Canonical Limited.
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+# 
+
+
+"""Tests for the bzr plugin repodetails."""
+
+
+def load_tests(standard_tests, module, loader):
+    test_modules = [
+        'repositorydetails',
+        ]
+    standard_tests.addTests(loader.loadTestsFromModuleNames(
+        ['bzrlib.plugins.repodetails.tests.test_' + name for 
+         name in test_modules]))
+    return standard_tests
+

=== added file 'tests/test_repositorydetails.py'
--- a/tests/test_repositorydetails.py	1970-01-01 00:00:00 +0000
+++ b/tests/test_repositorydetails.py	2008-10-17 01:50:00 +0000
@@ -0,0 +1,81 @@
+# Copyright (C) 2008 Canonical Limited.
+# 
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License version 2 as published
+# by the Free Software Foundation.
+# 
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+# 
+
+
+"""Tests for the bzr plugin epositorydetails."""
+
+
+import bzrlib.plugins.repodetails as repodetails
+from bzrlib.tests import TestCaseWithTransport
+
+
+class TestRepositoryDetails(TestCaseWithTransport):
+
+    def test_smoke_pack92(self):
+        tree = self.make_branch_and_tree('.', format="pack-0.92")
+        self.build_tree(["foo"])
+        tree.add(["foo"])
+        tree.commit("first post")
+        out, err = self.run_bzr(["repository-details"])
+        self.assertEqual(
+            "Commits: 1\n"
+            "                    Raw  Compressed Objects\n"
+            "Revisions:        0 KiB       0 KiB       1\n"
+            "Inventories:      0 KiB       0 KiB       1\n"
+            "Texts:            0 KiB       0 KiB       1\n"
+            "Signatures:       0 KiB       0 KiB       0\n"
+            , out)
+        self.assertEqual("", err)
+
+    def test_gather_stats_pack92(self):
+        tree = self.make_branch_and_tree('.', format="pack-0.92")
+        self.build_tree(["foo"])
+        tree.add(["foo"])
+        tree.commit("first post")
+        stats = repodetails.gather_stats(tree.branch.repository)
+        self.assertEqual(1, stats.revision_count)
+        self.assertEqual(1, stats.revisions.objects)
+        self.assertEqual(1, stats.revisions.raw_size)
+        self.assertEqual(1, stats.revisions.compressed_size)
+        self.assertEqual(1, stats.inventories.objects)
+        self.assertEqual(1, stats.inventories.raw_size)
+        self.assertEqual(1, stats.inventories.compressed_size)
+        self.assertEqual(1, stats.texts.objects)
+        self.assertEqual(1, stats.texts.raw_size)
+        self.assertEqual(1, stats.texts.compressed_size)
+        self.assertEqual(0, stats.signatures.objects)
+        self.assertEqual(1, stats.signatures.raw_size)
+        self.assertEqual(1, stats.signatures.compressed_size)
+
+    def test_gather_stats_chk(self):
+        tree = self.make_branch_and_tree('.', format="development3")
+        self.build_tree(["foo"])
+        tree.add(["foo"])
+        tree.commit("first post")
+        stats = repodetails.gather_stats(tree.branch.repository)
+        self.assertEqual(1, stats.revision_count)
+        self.assertEqual(1, stats.revisions.objects)
+        self.assertEqual(1, stats.revisions.raw_size)
+        self.assertEqual(1, stats.revisions.compressed_size)
+        self.assertEqual(1, stats.inventories.objects)
+        self.assertEqual(1, stats.inventories.raw_size)
+        self.assertEqual(1, stats.inventories.compressed_size)
+        self.assertEqual(1, stats.texts.objects)
+        self.assertEqual(1, stats.texts.raw_size)
+        self.assertEqual(1, stats.texts.compressed_size)
+        self.assertEqual(0, stats.signatures.objects)
+        self.assertEqual(1, stats.signatures.raw_size)
+        self.assertEqual(1, stats.signatures.compressed_size)




More information about the bazaar-commits mailing list