incubator-cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bhais...@apache.org
Subject git commit: cli: fix autocompletion binding bug, make all params lowercase
Date Tue, 06 Nov 2012 14:12:19 GMT
Updated Branches:
  refs/heads/master ac8ae3065 -> 36e7a7884


cli: fix autocompletion binding bug, make all params lowercase

- fix weird autocompletion bug which won't let you enter the letter b [0]
- make set params, api and secret key vars lowercase
- use partition to get strings for do_set
- while installing, check and only then add readline (requires gcc and can fail)
- show monkey prompt by default, let users change if needed

[0] http://superuser.com/questions/297527/cant-type-the-b-letter-in-python-shell-in-os-x

Signed-off-by: Rohit Yadav <bhaisaab@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/36e7a788
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/36e7a788
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/36e7a788

Branch: refs/heads/master
Commit: 36e7a7884efef7c41ac369549b7bdb93e5122110
Parents: ac8ae30
Author: Rohit Yadav <bhaisaab@apache.org>
Authored: Tue Nov 6 19:29:01 2012 +0530
Committer: Rohit Yadav <bhaisaab@apache.org>
Committed: Tue Nov 6 19:41:07 2012 +0530

----------------------------------------------------------------------
 tools/cli/cloudmonkey/__init__.py    |    2 +-
 tools/cli/cloudmonkey/cloudmonkey.py |   49 +++++++++++++---------------
 tools/cli/cloudmonkey/version.py     |   22 +++++++++++++
 tools/cli/setup.py                   |   11 ++++--
 4 files changed, 53 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/36e7a788/tools/cli/cloudmonkey/__init__.py
----------------------------------------------------------------------
diff --git a/tools/cli/cloudmonkey/__init__.py b/tools/cli/cloudmonkey/__init__.py
index 5f59cd0..45632db 100644
--- a/tools/cli/cloudmonkey/__init__.py
+++ b/tools/cli/cloudmonkey/__init__.py
@@ -16,6 +16,6 @@
 # under the License.
 
 try:
-    from cloudmonkey import __version__
+    from version import __version__
 except ImportError, e:
     print e

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/36e7a788/tools/cli/cloudmonkey/cloudmonkey.py
----------------------------------------------------------------------
diff --git a/tools/cli/cloudmonkey/cloudmonkey.py b/tools/cli/cloudmonkey/cloudmonkey.py
index d980a21..4eb0bc2 100644
--- a/tools/cli/cloudmonkey/cloudmonkey.py
+++ b/tools/cli/cloudmonkey/cloudmonkey.py
@@ -25,8 +25,6 @@ try:
     import logging
     import os
     import pdb
-    import readline
-    import rlcompleter
     import shlex
     import sys
     import types
@@ -34,6 +32,7 @@ try:
     from clint.textui import colored
     from ConfigParser import ConfigParser, SafeConfigParser
 
+    from version import __version__
     from marvin.cloudstackConnection import cloudConnection
     from marvin.cloudstackException import cloudstackAPIException
     from marvin.cloudstackAPI import *
@@ -43,10 +42,17 @@ except ImportError, e:
     import sys
     sys.exit()
 
-# Use following rules for versioning:
-# <cli major version>.<cloudstack minor version>.<cloudstack major version>
-# Example: For CloudStack 4.1.x, CLI version should be 0.1.4
-__version__ = "0.0.4"
+# Fix autocompletion issue, can be put in .pythonstartup
+try:
+    import readline
+except ImportError, e:
+    print "Module readline not found, autocompletions will fail", e
+else:
+    import rlcompleter
+    if 'libedit' in readline.__doc__:
+        readline.parse_and_bind("bind ^I rl_complete")
+    else:
+        readline.parse_and_bind("tab: complete")
 
 log_fmt = '%(asctime)s - %(filename)s:%(lineno)s - [%(levelname)s] %(message)s'
 logger = logging.getLogger(__name__)
@@ -65,8 +71,8 @@ class CloudStackShell(cmd.Cmd):
 
     def __init__(self):
         self.config_fields = {'host': 'localhost', 'port': '8080',
-                              'apiKey': '', 'secretKey': '',
-                              'prompt': 'cloudmonkey> ', 'color': 'true',
+                              'apikey': '', 'secretkey': '',
+                              'prompt': '🐵 cloudmonkey>', 'color': 'true',
                               'log_file':
                               os.path.expanduser('~/.cloudmonkey_log'),
                               'history_file':
@@ -77,7 +83,7 @@ class CloudStackShell(cmd.Cmd):
             for key in self.config_fields.keys():
                 setattr(self, key, self.config_fields[key])
             config = self.write_config()
-            print("🐵 Set your apiKey, secretKey, host, port, prompt, color,"
+            print("Set your apikey, secretkey, host, port, prompt, color,"
                   " log_file, history_file using the set command!")
 
         for key in self.config_fields.keys():
@@ -93,12 +99,6 @@ class CloudStackShell(cmd.Cmd):
         if not os.path.exists(self.config_file):
             config = self.write_config()
 
-        # Fix autocompletion issue
-        if sys.platform == "darwin":
-            readline.parse_and_bind("bind ^I rl_complete")
-        else:
-            readline.parse_and_bind("tab: complete")
-
         # Enable history support
         try:
             if os.path.exists(self.history_file):
@@ -204,7 +204,7 @@ class CloudStackShell(cmd.Cmd):
 
     def make_request(self, command, requests={}):
         conn = cloudConnection(self.host, port=int(self.port),
-                               apiKey=self.apiKey, securityKey=self.secretKey,
+                               apiKey=self.apikey, securityKey=self.secretkey,
                                logging=logging.getLogger("cloudConnection"))
         try:
             response = conn.make_request(command, requests)
@@ -317,7 +317,7 @@ class CloudStackShell(cmd.Cmd):
     def do_set(self, args):
         """
         Set config for CloudStack CLI. Available options are:
-        host, port, apiKey, secretKey, log_file, history_file
+        host, port, apikey, secretkey, log_file, history_file
         You may also edit your ~/.cloudmonkey_config instead of using set.
 
         Example:
@@ -325,20 +325,17 @@ class CloudStackShell(cmd.Cmd):
         set prompt 🐵 cloudmonkey>
         set log_file /var/log/cloudmonkey.log
         """
-        args = shlex.split(args.strip())
-        if len(args) == 2:
-            key, value = args
-            # Note: keys and fields should have same names
-            setattr(self, key, value)
-            self.write_config()
-        else:
-            self.print_shell("Please use the syntax: set valid-key value")
+        args = args.strip().partition(" ")
+        key, value = (args[0], args[2])
+        # Note: keys and class attributes should have same names
+        setattr(self, key, value)
+        self.write_config()
 
     def complete_set(self, text, line, begidx, endidx):
         mline = line.partition(" ")[2]
         offs = len(mline) - len(text)
         return [s[offs:] for s in
-               ['host', 'port', 'apiKey', 'secretKey', 'prompt', 'color',
+               ['host', 'port', 'apikey', 'secretkey', 'prompt', 'color',
                 'log_file', 'history_file'] if s.startswith(mline)]
 
     def do_shell(self, args):

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/36e7a788/tools/cli/cloudmonkey/version.py
----------------------------------------------------------------------
diff --git a/tools/cli/cloudmonkey/version.py b/tools/cli/cloudmonkey/version.py
new file mode 100644
index 0000000..8d891b2
--- /dev/null
+++ b/tools/cli/cloudmonkey/version.py
@@ -0,0 +1,22 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+# Use following rules for versioning:
+# <cli major version>.<cloudstack minor version>.<cloudstack major version>
+# Example: For CloudStack 4.1.x, CLI version should be 0.1.4
+__version__ = "0.0.4"
+

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/36e7a788/tools/cli/setup.py
----------------------------------------------------------------------
diff --git a/tools/cli/setup.py b/tools/cli/setup.py
index ebfb9d0..627a938 100644
--- a/tools/cli/setup.py
+++ b/tools/cli/setup.py
@@ -26,6 +26,12 @@ from cloudmonkey import __version__
 
 name = 'cloudmonkey'
 version = __version__
+requires = ['clint>=0.3.0',]
+
+try:
+    import readline
+except ImportError:
+    requires.append('readline')
 
 setup(
     name = name,
@@ -41,10 +47,7 @@ setup(
     platforms = ("Any",),
     license = 'ASL 2.0',
     packages = find_packages(),
-    install_requires = [
-        'clint>=0.3.0',
-        'readline',
-    ],
+    install_requires = requires,
     include_package_data = True,
     zip_safe = False,
     classifiers = [


Mime
View raw message