Author: Arnaud Fontaine <arnau@debian.org>
Forwarded: not-needed
Description: Fallback on system configuration file by default
 Scripts expect the configuration file as their first argument, but as
 the configuration file options are set up through debconf, fallback
 on /etc/slapos/slapos-client.cfg and /etc/slapos/slapos-node-unofficial.cfg
 generated upon package installation.

Index: slapos.core-0.35.1/slapos/format.py
===================================================================
--- slapos.core-0.35.1.orig/slapos/format.py	2013-02-28 19:46:01.532762494 +0900
+++ slapos.core-0.35.1/slapos/format.py	2013-02-28 19:46:01.524762410 +0900
@@ -960,8 +960,10 @@
     else:
       (options, args) = self.parse_args()
     if len(args) != 1:
-      self.error("Incorrect number of arguments")
-    return options, args[0]
+      configuration_file = '/etc/slapos/slapos-node-unofficial.cfg'
+    else:
+      configuration_file = args[0]
+    return options, configuration_file
 
 
 
@@ -1326,7 +1328,11 @@
   "Run default configuration."
 
   # Parse arguments
-  usage = "usage: %s [options] CONFIGURATION_FILE" % sys.argv[0]
+  usage = """usage: %s [options] CONFIGURATION_FILE
+
+If CONFIGURATION_FILE is not given explicitly, it fallbacks on
+`/etc/slapos/slapos-node-unofficial.cfg'.
+""" % sys.argv[0]
   options, configuration_file_path = Parser(usage=usage).check_args(args)
   config = Config()
   try:
Index: slapos.core-0.35.1/slapos/grid/slapgrid.py
===================================================================
--- slapos.core-0.35.1.orig/slapos/grid/slapgrid.py	2013-02-28 19:46:01.532762494 +0900
+++ slapos.core-0.35.1/slapos/grid/slapgrid.py	2013-02-28 19:46:01.528762453 +0900
@@ -145,8 +145,9 @@
            "(ie.:slappartX, slappartY),"
            "this option will make all others computer partitions be ignored.")
 
-  parser.add_argument("configuration_file", nargs=1, type=argparse.FileType(),
-      help="SlapOS configuration file.")
+  parser.add_argument("configuration_file", nargs='?', type=argparse.FileType(),
+      help="SlapOS configuration file.",
+      default='/etc/slapos/slapos-node-unofficial.cfg')
 
   # Deprecated options
   parser.add_argument("--develop", action="store_true", default=False,
@@ -168,7 +169,7 @@
       parser.parse_args(list(argument_tuple))
   # Parses arguments from config file, if needed, then merge previous arguments
   option_dict = {}
-  configuration_file = argument_option_instance.configuration_file[0]
+  configuration_file = argument_option_instance.configuration_file
   # Loads config (if config specified)
   slapgrid_configuration = ConfigParser.SafeConfigParser()
   slapgrid_configuration.readfp(configuration_file)
Index: slapos.core-0.35.1/slapos/proxy/__init__.py
===================================================================
--- slapos.core-0.35.1.orig/slapos/proxy/__init__.py	2013-02-28 19:46:01.532762494 +0900
+++ slapos.core-0.35.1/slapos/proxy/__init__.py	2013-02-28 19:46:01.528762453 +0900
@@ -67,9 +67,11 @@
     """
     (options, args) = self.parse_args()
     if len(args) != 1:
-      self.error("Incorrect number of arguments")
+      configuration_filename = '/etc/slapos/slapos-node-unofficial.cfg'
+    else:
+      configuration_filename = args[0]
 
-    return options, args[0]
+    return options, configuration_filename
 
 class Config:
   def setConfig(self, option_dict, configuration_file_path):
Index: slapos.core-0.35.1/slapos/grid/svcbackend.py
===================================================================
--- slapos.core-0.35.1.orig/slapos/grid/svcbackend.py	2013-02-28 19:46:01.532762494 +0900
+++ slapos.core-0.35.1/slapos/grid/svcbackend.py	2013-02-28 19:46:01.528762453 +0900
@@ -127,6 +127,8 @@
 Typical usage:
  * %prog CONFIGURATION_FILE [arguments passed to supervisor]
 
+If CONFIGURATION_FILE is not given explicitly, it fallbacks on
+`/etc/slapos/slapos-node-unofficial.cfg'.
 """.strip()
 
   parser = OptionParser(usage=usage)
@@ -138,12 +140,12 @@
     # No arguments given to entry point : we parse sys.argv.
     (argument_option_instance, argument_list) = parser.parse_args()
 
-  if not argument_list:
-    parser.error("Configuration file is obligatory. Consult documentation by "
-        "calling with -h.")
-  configuration_file = argument_list[0]
-  if not os.path.exists(configuration_file):
-    parser.error("Could not read configuration file : %s" % configuration_file)
+  if argument_list and os.path.exists(argument_list[0]):
+    configuration_file = argument_list.pop(0)
+  else:
+    configuration_file = '/etc/slapos/slapos-node-unofficial.cfg'
+    if not os.path.exists(configuration_file):
+      parser.error("Could not read configuration file: %s" % configuration_file)
 
   slapgrid_configuration = ConfigParser.SafeConfigParser()
   slapgrid_configuration.read(configuration_file)
@@ -156,7 +158,7 @@
   # Supervisord socket
   option_dict.setdefault('supervisord_socket',
                          os.path.join(option_dict['instance_root'], 'supervisord.socket'))
-  return option_dict, argument_list[1:]
+  return option_dict, argument_list
 
 
 def supervisorctl(*argument_tuple):
Index: slapos.core-0.35.1/slapos/bang.py
===================================================================
--- slapos.core-0.35.1.orig/slapos/bang.py	2013-02-28 19:46:01.532762494 +0900
+++ slapos.core-0.35.1/slapos/bang.py	2013-02-28 19:46:01.528762453 +0900
@@ -34,13 +34,14 @@
 def main(*args):
   parser = argparse.ArgumentParser()
   parser.add_argument("-m", "--message", default='', help="Message for bang.")
-  parser.add_argument("configuration_file", nargs=1, type=argparse.FileType(),
+  parser.add_argument("configuration_file", nargs='?', type=argparse.FileType(),
+      default='/etc/slapos/slapos-node-unofficial.cfg',
       help="SlapOS configuration file.")
   if len(args) == 0:
     argument = parser.parse_args()
   else:
     argument = parser.parse_args(list(args))
-  configuration_file = argument.configuration_file[0]
+  configuration_file = argument.configuration_file
   message = argument.message
   # Loads config (if config specified)
   configuration = ConfigParser.SafeConfigParser()
Index: slapos.core-0.35.1/slapos/client.py
===================================================================
--- slapos.core-0.35.1.orig/slapos/client.py	2013-02-28 19:46:01.532762494 +0900
+++ slapos.core-0.35.1/slapos/client.py	2013-02-28 19:46:01.528762453 +0900
@@ -64,12 +64,15 @@
     """
     (options, args) = self.parse_args()
     if len(args) == 0:
-      self.error("Incorrect number of arguments")
-    elif not os.path.isfile(args[0]):
-      self.error("%s: Not found or not a regular file." % args[0])
+      configuration_file_path = '/etc/slapos/slapos-client.cfg'
+    else:
+      configuration_file_path = args[0]
+
+    if not os.path.isfile(configuration_file_path):
+      self.error("%s: Not found or not a regular file." % configuration_file_path)
 
-    # Return options and only first element of args since there is only one.
-    return options, args[0]
+    # Return options and configuration file path
+    return options, configuration_file_path
 
 
 def argToDict(element):
@@ -86,6 +89,8 @@
   """
   parser = argparse.ArgumentParser()
   parser.add_argument("configuration_file",
+                      nargs='?',
+                      default='/etc/slapos/slapos-client.cfg',
                       help="SlapOS configuration file.")
   parser.add_argument("reference",
                       help="Your instance reference")
@@ -124,13 +129,17 @@
       setattr(self, option, value)
 
     # Load configuration file
-    configuration_parser = ConfigParser.SafeConfigParser()
     if configuration_file_path:
       configuration_file_path = os.path.expanduser(configuration_file_path)
-      if not os.path.isfile(configuration_file_path):
-        raise OSError('Specified configuration file %s does not exist.'
-            ' Exiting.' % configuration_file_path)
-      configuration_parser.read(configuration_file_path)
+    else:
+      configuration_file_path = '/etc/slapos/slapos-client.cfg'
+
+    if not os.path.isfile(configuration_file_path):
+      raise OSError('Specified configuration file %s does not exist.'
+                    ' Exiting.' % configuration_file_path)
+
+    configuration_parser = ConfigParser.SafeConfigParser()
+    configuration_parser.read(configuration_file_path)
     # Merges the arguments and configuration
     try:
       configuration_dict = dict(configuration_parser.items('slapconsole'))
@@ -249,6 +258,8 @@
   # XXX-Cedric: move argument parsing to main entry point
   parser = argparse.ArgumentParser()
   parser.add_argument("configuration_file",
+                      nargs='?',
+                      default='/etc/slapos/slapos-client.cfg',
                       help="SlapOS configuration file")
   parser.add_argument("software_url",
                       help="Your software url")
@@ -266,6 +277,8 @@
   # XXX-Cedric: move argument parsing to main entry point
   parser = argparse.ArgumentParser()
   parser.add_argument("configuration_file",
+                      nargs='?',
+                      default='/etc/slapos/slapos-client.cfg',
                       help="SlapOS configuration file.")
   parser.add_argument("software_url",
                       help="Your software url")
@@ -284,6 +297,9 @@
 slapconsole allows you interact with slap API. You can play with the global
 "slap" object and with the global "request" method.
 
++If CONFIGURATION_FILE is not given explicitly, it fallbacks on
+`/etc/slapos/slapos-client.cfg'.
+
 examples :
   >>> # Request instance
   >>> request(kvm, "myuniquekvm")
Index: slapos.core-0.35.1/slapos/entry.py
===================================================================
--- slapos.core-0.35.1.orig/slapos/entry.py	2013-02-28 19:46:01.532762494 +0900
+++ slapos.core-0.35.1/slapos/entry.py	2013-02-28 19:46:01.528762453 +0900
@@ -50,11 +50,15 @@
 
 GLOBAL_SLAPOS_CONFIGURATION = os.environ.get(
     'SLAPOS_CONFIGURATION',
-    '/etc/opt/slapos/slapos.cfg')
+    '/etc/slapos/slapos-node-unofficial.cfg')
+
 USER_SLAPOS_CONFIGURATION = os.environ.get(
     'SLAPOS_CLIENT_CONFIGURATION',
     os.environ.get('SLAPOS_CONFIGURATION', '~/.slapos/slapos.cfg'))
 
+if not os.path.exists(USER_SLAPOS_CONFIGURATION):
+  USER_SLAPOS_CONFIGURATION = GLOBAL_SLAPOS_CONFIGURATION
+
 class EntryPointNotImplementedError(NotImplementedError):
   def __init__(self, *args, **kw_args):
     NotImplementedError.__init__(self, *args, **kw_args)
Index: slapos.core-0.35.1/slapos/cache.py
===================================================================
--- slapos.core-0.35.1.orig/slapos/cache.py	2013-02-28 19:46:01.532762494 +0900
+++ slapos.core-0.35.1/slapos/cache.py	2013-02-28 19:46:01.528762453 +0900
@@ -18,7 +18,10 @@
 
 def cache_lookup():
     parser = argparse.ArgumentParser()
-    parser.add_argument("configuration_file", help="SlapOS configuration file")
+    parser.add_argument(
+        "configuration_file",
+        help="SlapOS configuration file (by default: ~/.slapos/slapos.cfg "
+             "then /etc/slapos/slapos-client.cfg)")
     parser.add_argument("software_url", help="Your software url or MD5 hash")
     args = parser.parse_args()
 
Index: slapos.core-0.35.1/slapos/proxy/query.py
===================================================================
--- slapos.core-0.35.1.orig/slapos/proxy/query.py	2013-02-08 18:25:46.000000000 +0900
+++ slapos.core-0.35.1/slapos/proxy/query.py	2013-02-28 19:50:59.527916050 +0900
@@ -50,8 +50,9 @@
         Check arguments
         """
         (options, args) = self.parse_args()
-        if len(args) < 1:
-            self.error("Incorrect number of arguments")
+        args_len = len(args)
+        if args_len < 1:
+          return options, '/etc/slapos/slapos-node-unofficial.cfg'
 
         return options, args[0]
 
@@ -228,7 +229,11 @@
 
 def main():
   "Run default configuration."
-  usage = "usage: %s [options] CONFIGURATION_FILE" % sys.argv[0]
+  usage = """usage: %s [options] CONFIGURATION_FILE
+
+If CONFIGURATION_FILE is not given explicitly, it fallbacks on
+`/etc/slapos/slapos-node-unofficial.cfg'.
+""" % sys.argv[0]
 
   try:
     # Parse arguments
