Пример #1
0
class InstallBaseCommand(Command):
    """
    Base command class to install or upgrade an OMERO server
    Do not call this class directly
    """

    def __init__(self, sub_parsers):
        super(InstallBaseCommand, self).__init__(sub_parsers)

        self.parser.add_argument("-n", "--dry-run", action="store_true")
        self.parser.add_argument(
            "server", nargs="?", help="The server directory, or a server-zip, " "or the url of a server-zip"
        )

        self.parser.add_argument(
            "--prestartfile",
            action="append",
            help="Run these OMERO commands before starting server, " "can be repeated",
        )
        self.parser.add_argument(
            "--ignoreconfig", action="store_true", help="Don't copy the old configuration file when upgrading"
        )

        self.parser = JenkinsParser(self.parser)
        self.parser = DbParser(self.parser)
        self.parser = FileUtilsParser(self.parser)

        Add = EnvDefault.add

        Add(self.parser, "sym", "OMERO-CURRENT")

        self.parser.add_argument("--no-start", action="store_true", help="Don't start any omero components")

        self.parser.add_argument("--no-web", action="store_true", help="Ignore OMERO.web, don't start or stop")

        self.parser.add_argument("--delete-old", action="store_true", help="Delete the old server directory")
        self.parser.add_argument("--keep-old-zip", action="store_true", help="Don't delete the old server zip")

        # Record the values of these environment variables in a file
        envvars = "ICE_HOME PATH DYLD_LIBRARY_PATH LD_LIBRARY_PATH PYTHONPATH"
        envvarsfile = os.path.join("%(sym)s", "omero.envvars")
        Add(self.parser, "savevars", envvars)
        Add(self.parser, "savevarsfile", envvarsfile)

    def __call__(self, args):
        super(InstallBaseCommand, self).__call__(args)
        self.configure_logging(args)

        # Since EnvDefault.__action__ is only called if a user actively passes
        # a variable, there's no way to do the string replacing in the action
        # itself. Instead, we're post-processing them here, but this could be
        # improved.

        names = sorted(x.dest for x in self.parser._actions)
        for dest in names:
            if dest in ("help", "verbose", "quiet"):
                continue
            value = getattr(args, dest)
            if value and isinstance(value, basestring):
                replacement = value % dict(args._get_kwargs())
                log.debug("% 20s => %s" % (dest, replacement))
                setattr(args, dest, replacement)

        if args.dry_run:
            return

        if WINDOWS:
            WindowsInstall(self.NAME, args)
        else:
            UnixInstall(self.NAME, args)