From dd189996c9b2e97c9f0e2422b47694d6ac878691 Mon Sep 17 00:00:00 2001
From: Marco Mariani <marco.mariani@nexedi.com>
Date: Tue, 23 Apr 2013 17:21:04 +0200
Subject: [PATCH] moved old entry points for supply, remove, console

---
 setup.py                     |  2 +-
 slapos/cli_legacy/console.py | 50 ++++++++++++++++++++
 slapos/cli_legacy/entry.py   | 12 ++---
 slapos/cli_legacy/remove.py  | 23 +++++++++
 slapos/cli_legacy/supply.py  | 23 +++++++++
 slapos/client.py             | 91 +++---------------------------------
 6 files changed, 109 insertions(+), 92 deletions(-)
 create mode 100644 slapos/cli_legacy/console.py
 create mode 100644 slapos/cli_legacy/remove.py
 create mode 100644 slapos/cli_legacy/supply.py

diff --git a/setup.py b/setup.py
index b9e74a72a..488176dd3 100644
--- a/setup.py
+++ b/setup.py
@@ -61,7 +61,7 @@ setup(name=name,
           'slapproxy = slapos.proxy:main',
           'slapproxy-query = slapos.proxy.query:main',
           # Deprecated entry points
-          'slapconsole = slapos.client:slapconsole',
+          'slapconsole = slapos.cli_legacy.console:console',
           'slapformat = slapos.cli_legacy.format:main',
           'slapgrid = slapos.grid.slapgrid:run',
           'slapgrid-sr = slapos.grid.slapgrid:runSoftwareRelease',
diff --git a/slapos/cli_legacy/console.py b/slapos/cli_legacy/console.py
new file mode 100644
index 000000000..03e8b482e
--- /dev/null
+++ b/slapos/cli_legacy/console.py
@@ -0,0 +1,50 @@
+# -*- coding: utf-8 -*-
+
+import argparse
+import os
+import sys
+
+from slapos.client import ClientConfig, init, do_console, get_config_parser
+
+
+def console():
+  usage = """usage: %s [options] CONFIGURATION_FILE
+slapconsole allows you interact with slap API. You can play with the global
+"slap" object and with the global "request" method.
+
+examples :
+  >>> # Request instance
+  >>> request(kvm, "myuniquekvm")
+  >>> # Request software installation on owned computer
+  >>> supply(kvm, "mycomputer")
+  >>> # Fetch instance informations on already launched instance
+  >>> request(kvm, "myuniquekvm").getConnectionParameter("url")""" % sys.argv[0]
+
+
+  ap = argparse.ArgumentParser(usage=usage)
+
+  ap.add_argument('-u', '--master_url',
+                  default=None,
+                  action="store",
+                  help='Url of SlapOS Master to use.')
+
+  ap.add_argument('-k', '--key_file',
+                  action="store",
+                  help="SSL Authorisation key file.")
+
+  ap.add_argument('-c', '--cert_file',
+                  action="store",
+                  help="SSL Authorisation certificate file.")
+
+  ap.add_argument('configuration_file',
+                  help='path to slapos.cfg')
+
+  options = ap.parse_args()
+
+  if not os.path.isfile(options.configuration_file):
+    ap.error("%s: Not found or not a regular file." % options.configuration_file)
+
+  config = ClientConfig(options, get_config_parser(options.configuration_file))
+  local = init(config)
+  do_console(local)
+
diff --git a/slapos/cli_legacy/entry.py b/slapos/cli_legacy/entry.py
index 2764c14c2..1f21c379a 100644
--- a/slapos/cli_legacy/entry.py
+++ b/slapos/cli_legacy/entry.py
@@ -30,11 +30,12 @@ import argparse
 import ConfigParser
 import os
 import sys
+
 from slapos.cli_legacy.bang import main as bang
-from slapos.client import slapconsole as console
-from slapos.client import request as request
-from slapos.client import remove as remove
-from slapos.client import supply as supply
+from slapos.cli_legacy.console import console
+from slapos.client import request
+from slapos.cli_legacy.remove import remove
+from slapos.cli_legacy.supply import supply
 from slapos.cli_legacy.format import main as format
 from slapos.cli_legacy.cache import cache_lookup
 from slapos.grid.slapgrid import runComputerPartition as instance
@@ -88,7 +89,7 @@ def checkOption(option):
     if key in element:
       return True
   sys.argv.append(key)
-  if len(option) > 1 :
+  if len(option) > 1:
     sys.argv = sys.argv + option[1:]
   return True
 
@@ -226,4 +227,3 @@ Node subcommands usage:
         'forum. Please also make sure that SlapOS Node is up to '
         'date.' % exception)
     sys.exit(1)
-
diff --git a/slapos/cli_legacy/remove.py b/slapos/cli_legacy/remove.py
new file mode 100644
index 000000000..fad4e1563
--- /dev/null
+++ b/slapos/cli_legacy/remove.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+
+import argparse
+
+from slapos.client import ClientConfig, init, do_remove, get_config_parser
+
+
+def remove():
+  """
+  Run when invoking slapos remove. Mostly argument parsing.
+  """
+  parser = argparse.ArgumentParser()
+  parser.add_argument('configuration_file',
+                      help='SlapOS configuration file')
+  parser.add_argument('software_url',
+                      help='Your software url')
+  parser.add_argument('node',
+                      help='Target node')
+  args = parser.parse_args()
+
+  config = ClientConfig(args, get_config_parser(args.configuration_file))
+  local = init(config)
+  do_remove(args.software_url, args.node, local)
diff --git a/slapos/cli_legacy/supply.py b/slapos/cli_legacy/supply.py
new file mode 100644
index 000000000..d0a9f189f
--- /dev/null
+++ b/slapos/cli_legacy/supply.py
@@ -0,0 +1,23 @@
+# -*- coding: utf-8 -*-
+
+import argparse
+
+from slapos.client import ClientConfig, init, do_supply, get_config_parser
+
+
+def supply():
+  """
+  Run when invoking slapos supply. Mostly argument parsing.
+  """
+  parser = argparse.ArgumentParser()
+  parser.add_argument('configuration_file',
+                      help='SlapOS configuration file')
+  parser.add_argument('software_url',
+                      help='Your software url')
+  parser.add_argument('node',
+                      help='Target node')
+  args = parser.parse_args()
+
+  config = ClientConfig(args, get_config_parser(args.configuration_file))
+  local = init(config)
+  do_supply(args.software_url, args.node, local)
diff --git a/slapos/client.py b/slapos/client.py
index 5d0c7c785..debe87177 100644
--- a/slapos/client.py
+++ b/slapos/client.py
@@ -28,13 +28,13 @@
 ##############################################################################
 
 import argparse
+import atexit
 import ConfigParser
-import pprint
 import os
-from slapos.slap import ResourceNotReady
+import pprint
+
 import slapos.slap.slap
-import sys
-import atexit
+from slapos.slap import ResourceNotReady
 
 
 def argToDict(element):
@@ -184,6 +184,7 @@ def request():
         "couple of minutes to get connection informations.")
     exit(2)
 
+
 def do_supply(software_url, computer_id, local, remove=False):
   """
   Request installation of Software Release
@@ -209,45 +210,10 @@ def do_supply(software_url, computer_id, local, remove=False):
   )
   print 'Done.'
 
+
 def do_remove(software_url, node, local):
   do_supply(software_url, node, local, remove=True)
 
-def supply():
-  """
-  Run when invoking slapos supply. Mostly argument parsing.
-  """
-  # XXX-Cedric: move argument parsing to main entry point
-  parser = argparse.ArgumentParser()
-  parser.add_argument("configuration_file",
-                      help="SlapOS configuration file")
-  parser.add_argument("software_url",
-                      help="Your software url")
-  parser.add_argument("node",
-                      help="Target node")
-  args = parser.parse_args()
-
-  config = ClientConfig(args, get_config_parser(args.configuration_file))
-  local = init(config)
-  do_supply(args.software_url, args.node, local)
-
-def remove():
-  """
-  Run when invoking slapos remove. Mostly argument parsing.
-  """
-  # XXX-Cedric: move argument parsing to main entry point
-  parser = argparse.ArgumentParser()
-  parser.add_argument("configuration_file",
-                      help="SlapOS configuration file.")
-  parser.add_argument("software_url",
-                      help="Your software url")
-  parser.add_argument("node",
-                      help="Target node")
-  args = parser.parse_args()
-
-  config = ClientConfig(args, get_config_parser(args.configuration_file))
-  local = init(config)
-  do_remove(args.software_url, args.node, local)
-
 
 def do_console(local):
   # try to enable readline with completion and history
@@ -271,48 +237,3 @@ def do_console(local):
     atexit.register(save_history)
 
   __import__("code").interact(banner="", local=local)
-
-
-def slapconsole():
-  """Ran when invoking slapconsole"""
-  # Parse arguments
-  usage = """usage: %s [options] CONFIGURATION_FILE
-slapconsole allows you interact with slap API. You can play with the global
-"slap" object and with the global "request" method.
-
-examples :
-  >>> # Request instance
-  >>> request(kvm, "myuniquekvm")
-  >>> # Request software installation on owned computer
-  >>> supply(kvm, "mycomputer")
-  >>> # Fetch instance informations on already launched instance
-  >>> request(kvm, "myuniquekvm").getConnectionParameter("url")""" % sys.argv[0]
-
-
-  ap = argparse.ArgumentParser(usage=usage)
-
-  ap.add_argument('-u', '--master_url',
-                  default=None,
-                  action="store",
-                  help='Url of SlapOS Master to use.')
-
-  ap.add_argument('-k', '--key_file',
-                  action="store",
-                  help="SSL Authorisation key file.")
-
-  ap.add_argument('-c', '--cert_file',
-                  action="store",
-                  help="SSL Authorisation certificate file.")
-
-  ap.add_argument('configuration_file',
-                  help='path to slapos.cfg')
-
-  options = ap.parse_args()
-
-  if not os.path.isfile(options.configuration_file):
-    ap.error("%s: Not found or not a regular file." % options.configuration_file)
-
-  config = ClientConfig(options, get_config_parser(options.configuration_file))
-  local = init(config)
-  do_console(local)
-
-- 
2.30.9