def _set_host_config(hostname, method="local"): cfg = simcity.Config(from_file=False) cfg.add_section( hostname + "-host", {"script": "mynonexistingscript.sh", "host": "does_not_exist", "port": 50080, "path": "~", "method": method}, ) try: simcity.init(cfg) except KeyError: pass # ignore mal-configured databases in this config
import couchdb import sys if __name__ == '__main__': parser = argparse.ArgumentParser( description="create databases and views for the simcity client") parser.add_argument( '-c', '--config', help="configuration file", default=None) parser.add_argument( '-p', '--password', help="admin password", default=None) parser.add_argument( 'admin', help="admin user", default=None) args = parser.parse_args() try: simcity.init(config=args.config) except couchdb.http.ResourceNotFound: pass # database does not exist yet except couchdb.http.Unauthorized: pass # user does not exist yet if args.password is None: try: args.password = getpass.getpass('Password:') except KeyboardInterrupt: # cancel password prompt print("") sys.exit(1) try: simcity.create(args.admin, args.password) except couchdb.http.Unauthorized: