sitemap: adding sizecalculation
[treecutter.git] / treecutter / tools.py
old mode 100755 (executable)
new mode 100644 (file)
index f6dd79b..62cb32a
@@ -1,21 +1,7 @@
 #!/usr/bin/python
 import os
-import fnmatch
 import subprocess
-import amara
-import re
-import tempfile
 import errno
-import time
-import argparse
-import shutil
-import pygraphviz as pgv
-import glob
-import gettext
-import shutil
-from amara import bindery
-from amara.xslt import transform
-from Cheetah.Template import Template
 
 def mkdir_p(path):
     try:
@@ -34,7 +20,27 @@ def publish(src,target):
 def ssh_cmd(target, command):
     t = target.split(":")
     c = command.split()
-    cmd = ["ssh",t[0],c[0],c[1],t[1]]
+    if len(t)==1:
+        cmd = [c[0],c[1],t[0]]
+    else:
+        cmd = ["ssh",t[0],c[0],c[1],t[1]]
     retcode = subprocess.call(cmd)
     if retcode:
         print 'Error: '+' '.join(cmd)+' Returncode ['+str(retcode)+']'
+
+def sizeof_fmt(num, suffix='B'):
+    for unit in ['','Ki','Mi','Gi','Ti','Pi','Ei','Zi']:
+        if abs(num) < 1024.0:
+            return "%3.1f%s%s" % (num, unit, suffix)
+        num /= 1024.0
+    return "%.1f%s%s" % (num, 'Yi', suffix)
+
+def get_folder_size(folder):
+    total_size = os.path.getsize(folder)
+    for item in os.listdir(folder):
+        itempath = os.path.join(folder, item)
+        if os.path.isfile(itempath):
+            total_size += os.path.getsize(itempath)
+        elif os.path.isdir(itempath):
+            total_size += get_folder_size(itempath)
+    return total_size