From cec4eff0bda7e093cf6ba2d699356e3422c22351 Mon Sep 17 00:00:00 2001
From: ale <ale@incal.net>
Date: Sat, 13 Jun 2015 19:12:23 +0100
Subject: [PATCH] with dry_run, show usage of blog data

---
 noblogsmv/main.py | 38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/noblogsmv/main.py b/noblogsmv/main.py
index bf6ca94..19d44fd 100644
--- a/noblogsmv/main.py
+++ b/noblogsmv/main.py
@@ -17,6 +17,8 @@ MYSQL_URI_RE = re.compile(
 
 log = logging.getLogger(__name__)
 
+dry_run = False
+
 
 def execute_gen(cmd, dry_run=False):
     if dry_run:
@@ -89,16 +91,29 @@ def process_move_data(blog_id, value, progress):
     progress.update('moving blog data')
     log.info('moving data for %s', blog_id)
     blog_dir = os.path.join(BLOGS_DIR, blog_id)
-    cmd = sshcmd(
-        'root@%s' % value['old_host'], 'rsync', '-az',
-        '%s/' % blog_dir, 'root@%s:%s' % (value['new_host'], blog_dir))
-    log.debug('Calling %s', ' '.join(cmd))
-    try:
-        execute(cmd)
-    except (subprocess.CalledProcessError, OSError), e:
-        progress.update('moving blog data failed, retrying')
-        log.info('Could not move data for blog %s: %s', blog_id, e)
-        return None
+
+    if not dry_run:
+        cmd = sshcmd(
+            'root@%s' % value['old_host'], 'rsync', '-az',
+            '%s/' % blog_dir, 'root@%s:%s' % (value['new_host'], blog_dir))
+        log.debug('Calling %s', ' '.join(cmd))
+        try:
+            execute(cmd)
+        except (subprocess.CalledProcessError, OSError), e:
+            progress.update('moving blog data failed, retrying')
+            log.info('Could not move data for blog %s: %s', blog_id, e)
+            return None
+
+    else:
+        cmd = sshcmd(
+            'root@%s' % value['old_host'],
+            'du', '-s', blog_dir)
+        try:
+            usage = int(subprocess.check_output(cmd))
+            log.info('blog %s on %s usage: %d Kb', blog_id, value['old_host'], usage)
+        except (subprocess.CalledProcessError, OSError), e:
+            log.error('error retrieving usage for blog %s@%s: %s',
+                      blog_id, value['old_host'], e)
 
     progress.update('moved blog data')
     log.info('Moved data for blog %s', blog_id)
@@ -258,6 +273,9 @@ use the `--recover' option.
     global execute
     execute = partial(execute_gen, dry_run=opts.dry_run)
 
+    global dry_run
+    dry_run = opts.dry_run
+
     if opts.clean:
         statemachine = NoblogsCleanStateMachine
     else:
-- 
GitLab