changeset 2196:7ccf403b9c3f beta

made repo-size hook more generic
author Marcin Kuzminski <marcin@python-works.com>
date Tue, 17 Apr 2012 21:40:49 +0200
parents b5f03c1d2153
children b14d8bd96144
files rhodecode/lib/hooks.py
diffstat 1 files changed, 28 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- a/rhodecode/lib/hooks.py	Mon Apr 16 19:27:27 2012 +0200
+++ b/rhodecode/lib/hooks.py	Tue Apr 17 21:40:49 2012 +0200
@@ -33,6 +33,33 @@
 from inspect import isfunction
 
 
+def _get_scm_size(alias, root_path):
+
+    if not alias.startswith('.'):
+        alias += '.'
+
+    size_scm, size_root = 0, 0
+    for path, dirs, files in os.walk(root_path):
+        if path.find(alias) != -1:
+            for f in files:
+                try:
+                    size_scm += os.path.getsize(os.path.join(path, f))
+                except OSError:
+                    pass
+        else:
+            for f in files:
+                try:
+                    size_root += os.path.getsize(os.path.join(path, f))
+                except OSError:
+                    pass
+
+    size_scm_f = h.format_byte_size(size_scm)
+    size_root_f = h.format_byte_size(size_root)
+    size_total_f = h.format_byte_size(size_root + size_scm)
+
+    return size_scm_f, size_root_f, size_total_f
+
+
 def repo_size(ui, repo, hooktype=None, **kwargs):
     """
     Presents size of repository after push
@@ -42,24 +69,7 @@
     :param hooktype:
     """
 
-    size_hg, size_root = 0, 0
-    for path, dirs, files in os.walk(repo.root):
-        if path.find('.hg') != -1:
-            for f in files:
-                try:
-                    size_hg += os.path.getsize(os.path.join(path, f))
-                except OSError:
-                    pass
-        else:
-            for f in files:
-                try:
-                    size_root += os.path.getsize(os.path.join(path, f))
-                except OSError:
-                    pass
-
-    size_hg_f = h.format_byte_size(size_hg)
-    size_root_f = h.format_byte_size(size_root)
-    size_total_f = h.format_byte_size(size_root + size_hg)
+    size_hg_f, size_root_f, size_total_f = _get_scm_size('.hg', repo.root)
 
     last_cs = repo[len(repo) - 1]