aurora-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From wfar...@apache.org
Subject aurora git commit: Improve diff output of aurora cli.
Date Fri, 17 Jul 2015 22:14:41 GMT
Repository: aurora
Updated Branches:
  refs/heads/master d74b02e87 -> 4eaacf7b5


Improve diff output of aurora cli.

Use json.dumps to pretty print the executor config,
and munge it to look right and not get messed with by
the general pretty printer.
Show newlines directly so that multi-line cmdlines look right.

Make DIFF_VIEWER work for things like "diff -u10"

Testing Done:
Tested in vargant environment.

Reviewed at https://reviews.apache.org/r/36392/


Project: http://git-wip-us.apache.org/repos/asf/aurora/repo
Commit: http://git-wip-us.apache.org/repos/asf/aurora/commit/4eaacf7b
Tree: http://git-wip-us.apache.org/repos/asf/aurora/tree/4eaacf7b
Diff: http://git-wip-us.apache.org/repos/asf/aurora/diff/4eaacf7b

Branch: refs/heads/master
Commit: 4eaacf7b5e7b02d626e821b8a4117363f6b39490
Parents: d74b02e
Author: Brian Brazil <brian.brazil@boxever.com>
Authored: Fri Jul 17 15:14:26 2015 -0700
Committer: Bill Farner <wfarner@apache.org>
Committed: Fri Jul 17 15:14:26 2015 -0700

----------------------------------------------------------------------
 .../python/apache/aurora/client/cli/jobs.py     | 21 +++++++++++++++++---
 .../apache/aurora/client/cli/test_diff.py       |  8 ++++----
 2 files changed, 22 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/aurora/blob/4eaacf7b/src/main/python/apache/aurora/client/cli/jobs.py
----------------------------------------------------------------------
diff --git a/src/main/python/apache/aurora/client/cli/jobs.py b/src/main/python/apache/aurora/client/cli/jobs.py
index 6f76181..6d15f1e 100644
--- a/src/main/python/apache/aurora/client/cli/jobs.py
+++ b/src/main/python/apache/aurora/client/cli/jobs.py
@@ -25,6 +25,7 @@ import webbrowser
 from collections import namedtuple
 from copy import deepcopy
 from datetime import datetime
+from pipes import quote
 from tempfile import NamedTemporaryFile
 
 from thrift.protocol import TJSONProtocol
@@ -149,7 +150,7 @@ class DiffCommand(Verb):
     return textwrap.dedent("""\
         Compare a job configuration against a running job.
         By default the diff will be displayed using 'diff', though you may choose an
-        alternate diff program by setting the DIFF_VIEWER environment variable.""")
+        alternate diff command by setting the DIFF_VIEWER environment variable.""")
 
   @property
   def name(self):
@@ -164,9 +165,22 @@ class DiffCommand(Verb):
 
   def pretty_print_task(self, task):
     task.configuration = None
+    executor_config = json.loads(task.executorConfig.data)
+    pretty_executor = json.dumps(executor_config, indent=2, sort_keys=True)
+    pretty_executor = '\n'.join(["    %s" % s for s in pretty_executor.split("\n")])
+    # Make start cleaner, and display multi-line commands across multiple lines.
+    pretty_executor = '\n    ' + pretty_executor.replace(r'\n', '\n')
+    # Avoid re-escaping as it's already pretty printed.
+    class RawRepr(object):
+      def __init__(self, data):
+        self.data = data
+
+      def __repr__(self):
+        return self.data
+
     task.executorConfig = ExecutorConfig(
         name=AURORA_EXECUTOR_NAME,
-        data=json.loads(task.executorConfig.data))
+        data=RawRepr(pretty_executor))
     return self.prettyprinter.pformat(vars(task))
 
   def pretty_print_tasks(self, tasks):
@@ -210,7 +224,8 @@ class DiffCommand(Verb):
       self.dump_tasks(local_tasks, local)
       with NamedTemporaryFile() as remote:
         self.dump_tasks(remote_tasks, remote)
-        result = subprocess.call([diff_program, remote.name, local.name])
+        result = subprocess.call("%s %s %s" % (
+            diff_program, quote(remote.name), quote(local.name)), shell=True)
         # Unlike most commands, diff doesn't return zero on success; it returns
         # 1 when a successful diff is non-empty.
         if result not in (0, 1):

http://git-wip-us.apache.org/repos/asf/aurora/blob/4eaacf7b/src/test/python/apache/aurora/client/cli/test_diff.py
----------------------------------------------------------------------
diff --git a/src/test/python/apache/aurora/client/cli/test_diff.py b/src/test/python/apache/aurora/client/cli/test_diff.py
index da52105..753a041 100644
--- a/src/test/python/apache/aurora/client/cli/test_diff.py
+++ b/src/test/python/apache/aurora/client/cli/test_diff.py
@@ -73,7 +73,7 @@ class TestDiffCommand(AuroraClientCommandTest):
     with contextlib.nested(
         patch('apache.aurora.client.api.SchedulerProxy', return_value=mock_scheduler_proxy),
         patch('subprocess.call', return_value=0),
-        patch('json.loads', return_value=Mock())) as (_, subprocess_patch, _):
+        patch('json.loads', return_value={})) as (_, subprocess_patch, _):
 
       mock_scheduler_proxy.getTasksStatus.return_value = self.create_status_response()
       self.setup_populate_job_config(mock_scheduler_proxy)
@@ -91,10 +91,10 @@ class TestDiffCommand(AuroraClientCommandTest):
         assert isinstance(mock_scheduler_proxy.populateJobConfig.call_args[0][0], JobConfiguration)
         assert (mock_scheduler_proxy.populateJobConfig.call_args[0][0].key ==
             JobKey(environment=u'test', role=u'bozo', name=u'hello'))
-        # Subprocess should have been used to invoke diff with two parameters.
+        # Subprocess should have been used to invoke diff.
         assert subprocess_patch.call_count == 1
-        assert len(subprocess_patch.call_args[0][0]) == 3
-        assert subprocess_patch.call_args[0][0][0] == os.environ.get('DIFF_VIEWER', 'diff')
+        assert subprocess_patch.call_args[0][0].startswith(
+            os.environ.get('DIFF_VIEWER', 'diff') + ' ')
 
   def test_diff_invalid_config(self):
     """Test the diff command if the user passes a config with an error in it."""


Mime
View raw message