if (len(sys.argv) != 5): print( "Usage python set.py crypto_token dataset_id users|schemes|messages path" ) exit(1) CRYPTO_TOKEN_PATH = sys.argv[1] fcw.init_client(CRYPTO_TOKEN_PATH) DATASET_ID = sys.argv[2] CONTENT_TYPE = sys.argv[3] PATH = sys.argv[4] dataset_ids = fcw.get_dataset_ids() if DATASET_ID not in dataset_ids: print("WARNING: dataset {} does not exist, this will create a new dataset". format(DATASET_ID)) if CONTENT_TYPE not in ["users", "schemes", "messages"]: print("update content_type {} not known".format(CONTENT_TYPE)) exit(1) json_data = json.loads(open(PATH, 'r').read()) if CONTENT_TYPE == "users": validate_user_list.verify_JSON_path(PATH) users_list = json_data print("Setting users for '{}': {}".format(DATASET_ID, users_list))
fcw.init_client(CRYPTO_TOKEN_PATH) project_id = json.load(open(CRYPTO_TOKEN_PATH, 'r'))["project_id"] existing_segmented_dataset_ids = fcw.get_segmented_dataset_ids() if len(existing_segmented_dataset_ids) > 0: print( "Target Firestore still has segment_counts, can't restore. Please delete all existing data first:" ) print("Run:") print( "firebase -P {} firestore:delete -r segment_counts".format(project_id)) print("") exit(1) existing_ids = fcw.get_dataset_ids() if len(existing_ids) > 0: print( "Target Firestore still has datasets, can't restore. Please delete all existing data first:" ) print("Run:") print("firebase -P {} firestore:delete -r datasets".format(project_id)) print("") exit(1) with open(BACKUP_PATH, 'r') as f: for line in f: dataset = json.loads(line) dataset_id = dataset["dataset_id"] print(f"Restoring dataset {dataset_id}")