def __call__(self, args): super(DbCommand, 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.serverdir: d = args.serverdir else: raise Stop(1, 'OMERO server directory required') ext = External(d) ext.setup_omero_cli() DbAdmin(d, args.dbcommand, args, ext)
def __init__(self, cmd, args): self.args = args log.info("%s: %s", self.__class__.__name__, cmd) log.debug("Current directory: %s", os.getcwd()) if cmd == 'upgrade': newinstall = False if not os.path.exists(args.sym): raise Stop(30, 'Symlink is missing: %s' % args.sym) elif cmd == 'install': newinstall = True if os.path.exists(args.sym): raise Stop(30, 'Symlink already exists: %s' % args.sym) else: raise Exception('Unexpected command: %s' % cmd) server_dir = self.get_server_dir() if newinstall: # Create a symlink to simplify the rest of the logic- # just need to check if OLD == NEW self.symlink(server_dir, args.sym) log.info("Installing %s (%s)...", server_dir, args.sym) else: log.info("Upgrading %s (%s)...", server_dir, args.sym) self.external = External(server_dir) self.external.setup_omero_cli() if not newinstall: self.external.setup_previous_omero_env(args.sym, args.savevarsfile) # Need lib/python set above import path self.dir = path.path(server_dir) if not newinstall: self.stop() self.archive_logs() copyold = not newinstall and not args.ignoreconfig self.configure(copyold, args.prestartfile) self.directories() if newinstall: self.init_db() self.upgrade_db() self.external.save_env_vars(args.savevarsfile, args.savevars.split()) self.start()
def __init__(self, cmd, args): self.args, newinstall = self._handle_args(cmd, args) log.info("%s: %s", self.__class__.__name__, cmd) log.debug("Current directory: %s", os.getcwd()) self.symlink_check_and_set() if newinstall is None: # Automatically install or upgrade newinstall = not os.path.exists(args.sym) elif newinstall is False: if not os.path.exists(args.sym): raise Stop(30, 'Symlink is missing: %s' % args.sym) elif newinstall is True: if os.path.exists(args.sym): raise Stop(30, 'Symlink already exists: %s' % args.sym) else: assert False server_dir = self.get_server_dir() if newinstall: # Create a symlink to simplify the rest of the logic- # just need to check if OLD == NEW self.symlink(server_dir, args.sym) log.info("Installing %s (%s)...", server_dir, args.sym) else: log.info("Upgrading %s (%s)...", server_dir, args.sym) self.external = External(server_dir) self.external.setup_omero_cli() if not newinstall: self.external.setup_previous_omero_env(args.sym, args.savevarsfile) # Need lib/python set above import path self.dir = path.path(server_dir) if not newinstall: self.stop() self.archive_logs() copyold = not newinstall and not args.ignoreconfig self.configure(copyold, args.prestartfile) self.directories() self.handle_database() self.external.save_env_vars(args.savevarsfile, args.savevars.split()) self.start()
def run(self, wd=None): self.log.info("Starting RunController") try: while True: time.sleep(0.2) if self._stop.isSet(): break if self.current and self.current.status == 'completed': if self.current.retval: self.retval[self.current.pid] = self.current.retval self.log.info("Retval: %s" % self.current.retval) self.current_process = None self.current.join() self.current = None if self.current and self.current.status == 'aborted': self.log.warning("%s aborted without finishing" % self.current.name) if self.run_queue and not self.current: pid = sorted(self.run_queue.keys())[0] cmd = self.run_queue[pid] if cmd[0] == 'mkdir': try: os.stat(cmd[1]) except: os.makedirs(cmd[1]) elif cmd[0] == 'cd': os.chdir(cmd[1]) else: self.current = External(cmd[0], cmd[1:], pid=pid, log_name=self.log_name) cwd = os.getcwd() if self.wd: os.chdir(self.wd) self.current.start() while not self.current.started: time.sleep(0.1) os.chdir(cwd) del self.run_queue[pid] self.state = 'running' if not self.run_queue and not self.current and self.state == 'running': self.state = 'finished' if self.current: self.current.stop() self.current.join() except Exception as e: print "RunController: %s" % e self.log.info("RunController finishing")
def main(argv): parser = argparse.ArgumentParser(description='Create a skeleton application using some command line options.') parser.add_argument('appname', help='The application name') parser.add_argument('-b', '--bower', help='Dependencies installed using bower') parser.add_argument('-n', '--no-debug', action='store_false') parser.add_argument('-v', '--virtualenv', action='store_true') parser.add_argument('-d', '--database', action='store_true') parser.add_argument('-g', '--git', action='store_true') args = parser.parse_args() bower = None if args.bower: bower = args.bower.split(',') virtualenv = args.virtualenv debug = args.no_debug appname = args.appname database = args.database git = args.git if database: project = FlaskDbProject(appname) else: project = FlaskProject(appname) project.debug = debug project.bower = bower project.virtualenv = virtualenv project.git = git print(generate_brief(project.brief_var)) errors = External().errors if len(errors) > 0: print(generate_errorlist({'errors': errors, })) sys.exit(1) if query_yes_no("Is this correct ?"): project.install() else: print("Aborting") sys.exit(0)