#153 Add cli args to ipsilon-upgrade-database to make it nicer to use
Merged 7 years ago by merlinthp. Opened 7 years ago by merlinthp.
merlinthp/ipsilon updb  into  master

file modified
+10 -7
@@ -1,17 +1,20 @@ 

  # Copyright (C) 2015 Ipsilon project Contributors, for license see COPYING

  

- import sys

  import os

  

  

- def find_config():

+ def find_config(instance, path):

      cfgfile = None

-     if (len(sys.argv) > 1):

-         cfgfile = sys.argv[-1]

-     elif os.path.isfile('ipsilon.conf'):

+ 

+     if path is not None:

+         cfgfile = path

+     elif instance is None:

          cfgfile = 'ipsilon.conf'

-     elif os.path.isfile('/etc/ipsilon/ipsilon.conf'):

-         cfgfile = '/etc/ipsilon/ipsilon.conf'

+     elif instance != '':

+         cfgfile = '/etc/ipsilon/%s/ipsilon.conf' % instance

      else:

+         cfgfile = '/etc/ipsilon/ipsilon.conf'

+ 

+     if not os.path.isfile(cfgfile):

          raise IOError("Configuration file not found")

      return cfgfile

@@ -5,6 +5,7 @@ 

  __requires__ = ['sqlalchemy >= 0.8']

  import pkg_resources  # pylint: disable=unused-import

  

+ from argparse import ArgumentParser

  import sys

  import logging

  logging.basicConfig(level=logging.INFO)
@@ -16,8 +17,20 @@ 

  

  

  if __name__ == '__main__':

+     parser = ArgumentParser(description='Upgrade the ipsilon database')

+     group = parser.add_mutually_exclusive_group()

+     group.add_argument('cfgfile', metavar='CONFIGFILE', nargs='?',

+                        help='Path to config file')

+     group.add_argument('--instance', default='idp', help='IdP instance name')

+     group.add_argument('--root-instance', default=False, action='store_true',

+                        help='Web root mounted instance')

+     args = parser.parse_args()

+ 

+     if args.root_instance:

+         args.instance = 'root'

+ 

      try:

-         dbupgrade.execute_upgrade(find_config())

+         dbupgrade.execute_upgrade(find_config(args.instance, args.cfgfile))

      except Exception as ex:

          logger.error('Error upgrading database', exc_info=True)

          sys.exit(1)

file modified
+1 -1
@@ -35,7 +35,7 @@ 

          except Exception:  # pylint: disable=broad-except

              pass

  

- cfgfile = find_config()

+ cfgfile = find_config(None, None)

  

  cherrypy.lib.sessions.SqlSession = ipsilon.util.sessions.SqlSession

  cherrypy.config.update(cfgfile)

file modified
+9 -2
@@ -427,14 +427,21 @@ 

              return

  

          current_version = self._get_schema_version()

+ 

+         base = cherrypy.config.get('base.mount', '/')

+         if base == '/':

+             updbargs = '--root-instance'

+         else:

+             updbargs = '--instance %s' % base[1:]

+ 

          if current_version is None:

              self.error('Database initialization required! ' +

-                        'Please run ipsilon-upgrade-database')

+                        'Please run ipsilon-upgrade-database ' + updbargs)

              raise DatabaseError('Database initialization required for %s' %

                                  self.__class__.__name__)

          if current_version != self._code_schema_version():

              self.error('Database upgrade required! ' +

-                        'Please run ipsilon-upgrade-database')

+                        'Please run ipsilon-upgrade-database ' + updbargs)

              raise DatabaseError('Database upgrade required for %s' %

                                  self.__class__.__name__)

  

Add an argparser to it taking similar arguments to -server-install, and
rework find_config a bit.

Also, change the error messages that tell the admin to run ipsilon-
upgrade-database to include the correct command line arguments for the
instance.

Signed-off-by: Howard Johnson merlin@merlinthp.org

All the arguments are in a mutual exclusion group, so you can't specify more than one of the three arguments at once. But if --instance isn't specified, it will always be set to idp, so we blank out that value if root-instance is specified.

Note that the root instance has the name "root".
So it's in /etc/ipsilon/root/ipsilon.conf

rebased

7 years ago

Commit 7d1b216 fixes this pull-request

Pull-Request has been merged by merlin@merlinthp.org

7 years ago