def main(): script, args = sys.argv[0], sys.argv[1:] try: if args: command, args = args[0], args[1:] if command == "help": _help(script) elif command == "list": _list(*args) else: warehouse = Warehouse() name, args = args[0], args[1:] box = warehouse.box(name) if command == "install": edition, version = args box.install(edition, version) webserver_port = warehouse._ports[name] webserver_https_port = webserver_port + 1 print("Created server instance %r configured on ports %s and %s" % ( name, webserver_port, webserver_https_port)) elif command == "remove" and not args: box.remove() elif command == "remove" and args[0] == "force": box.remove(force=True) elif command == "rename": new_name, = args box.rename(new_name) elif command == "start": ps = box.server.start() print(ps.service_root.uri) elif command == "stop": box.server.stop() elif command == "open": if box.server: box.server.graph.open_browser() else: raise RuntimeError("Server %r is not running" % name) elif command == "drop" and not args: box.server.store.drop() elif command == "drop" and args[0] == "force": box.server.store.drop(force=True) elif command == "load": path, args = args[0], args[1:] if not args: box.server.store.load(path) elif args[0] == "force": box.server.store.load(path, force=True) else: raise ValueError("Bad command or arguments") elif command == "save": path, args = args[0], args[1:] if not args: box.server.store.save(path) elif args[0] == "force": box.server.store.save(path, force=True) else: raise ValueError("Bad command or arguments") else: raise ValueError("Bad command or arguments") else: _help(script) except Exception as error: sys.stderr.write(ustr(error)) sys.stderr.write("\n") sys.exit(1)
def _list(*args): warehouse = Warehouse() for box in warehouse.boxes(): print(box.name)