logging.getLogger().handlers[0].setFormatter( logging.Formatter("{} - %(levelname)s - %(message)s".format(sys.argv[0]))) if arguments.force and os.path.exists(arguments.output_dir): shutil.rmtree(arguments.output_dir) if os.path.exists(arguments.output_dir): raise Exception("Output directory already exists.") couchdb = couchdb.Server()[arguments.couchdb_database] os.makedirs(arguments.output_dir) if arguments.all: arguments.project_id = set( arguments.project_id + [row["id"] for row in couchdb.view("slycat/projects")]) bookmark_ids = list(row["id"] for row in couchdb.view("slycat/project-bookmarks")) reference_ids = list(row["id"] for row in couchdb.view("slycat/references")) logging.info("Dumping bookmarks") for bookmark_id in bookmark_ids: bookmark = couchdb.get(bookmark_id, attachments=True) json.dump( bookmark, open( os.path.join(arguments.output_dir, "bookmark-%s.json" % bookmark["_id"]), "w")) logging.info("Done with bookmarks")
if arguments.force and os.path.exists(arguments.output_dir): shutil.rmtree(arguments.output_dir) if os.path.exists(arguments.output_dir): slycat.email.send_error("slycat-dump.py", "Output directory already exists.") raise Exception("Output directory already exists.") couchdb = couchdb.Server()[arguments.couchdb_database] os.makedirs(arguments.output_dir) if arguments.all: arguments.project_id = set( arguments.project_id + [row["id"] for row in couchdb.view("slycat/projects")]) for project_id in arguments.project_id: logging.info("Dumping project %s", project_id) project = couchdb.get(project_id, attachments=True) json.dump( project, open( os.path.join(arguments.output_dir, "project-%s.json" % project["_id"]), "w")) project_arrays = set() for row in couchdb.view("slycat/project-models", startkey=project_id, endkey=project_id):
logging.getLogger().setLevel(logging.INFO) logging.getLogger().addHandler(logging.StreamHandler()) logging.getLogger().handlers[0].setFormatter(logging.Formatter("{} - %(levelname)s - %(message)s".format(sys.argv[0]))) if arguments.force and os.path.exists(arguments.output_dir): shutil.rmtree(arguments.output_dir) if os.path.exists(arguments.output_dir): slycat.email.send_error("slycat-dump.py", "Output directory already exists.") raise Exception("Output directory already exists.") couchdb = couchdb.Server()[arguments.couchdb_database] os.makedirs(arguments.output_dir) if arguments.all: arguments.project_id = set(arguments.project_id + [row["id"] for row in couchdb.view("slycat/projects")]) for project_id in arguments.project_id: logging.info("Dumping project %s", project_id) project = couchdb.get(project_id, attachments=True) json.dump(project, open(os.path.join(arguments.output_dir, "project-%s.json" % project["_id"]), "w")) project_arrays = set() for row in couchdb.view("slycat/project-models", startkey=project_id, endkey=project_id): logging.info("Dumping model %s", row["id"]) model = couchdb.get(row["id"], attachments=True) json.dump(model, open(os.path.join(arguments.output_dir, "model-%s.json" % model["_id"]), "w")) artifact_types = model["artifact-types"] for key, value in model.items():
logging.warning("Waiting for couchdb.") time.sleep(2) if arguments.database not in server: server.create(arguments.database) couchdb = server[arguments.database] logging.info('Connected to couchdb') """ cleans out project data that is not being pointed at by a parameter space model, and cleans up models that are not parameter space but point to project data """ # get a view list of all pd ids for row in couchdb.view("slycat/project_datas"): logging.info('Testing PD: {0}'.format(str(row.id))) pd_doc = couchdb.get(type="project_data",id=row.id) delete_pd = True # go through model list in pd and start cleaning for model_id in pd_doc['mid']: model_doc = couchdb.get(type="model",id=model_id) if model_doc is not None: if "model-type" in model_doc: #log.error("testing model type:[%s]" % str(model_doc["model-type"])) if model_doc["model-type"] == "parameter-image": logging.info('Skipping deletion of parameter-image PD: {0}'.format(str(row.id))) delete_pd = False # clean up models that don't need pd elif "project_data" in model_doc: logging.info('Deleting non-parameter-image PD: {0}'.format(str(row.id)))