Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing auto delete #121

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 22 additions & 11 deletions generate_test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import sys
import subprocess
import json
import pprint


def parse_args():
Expand All @@ -23,18 +24,19 @@ def parse_args():

def main(args):
ingest_repo_dir = os.path.dirname(os.path.abspath(__file__))
if args.delete:
shutil.rmtree(args.tmp)
if os.path.exists(args.tmp):
yes = ['yes', 'y', 'ye', '']
no = ['no', 'n']
response = input(f"Specified directory {args.tmp}, ok to delete? (yes/no)")
if response.lower() in yes:
if args.delete:
shutil.rmtree(args.tmp)
else:
print("Cannot clone repo until --tmp directory is removed. Remove manually or specify an alternate --tmp "
"destination.")
sys.exit()
yes = ['yes', 'y', 'ye', '']
no = ['no', 'n']
response = input(f"Specified directory {args.tmp}, ok to delete? (yes/no)")
if response.lower() in yes:
shutil.rmtree(args.tmp)
else:
print("Cannot clone repo until --tmp directory is removed. Remove manually or specify an alternate --tmp "
"destination.")
sys.exit()
print(f"Cloning mohccn-synthetic-data repo into {args.tmp}")
synth_repo = Repo.clone_from("https://github.com/CanDIG/mohccn-synthetic-data.git", args.tmp)

Expand All @@ -54,8 +56,17 @@ def main(args):
else:
print("Converting small_dataset_csvs to small_dataset_clinical_ingest.json")
output_dir = f"{args.tmp}/small_dataset_csv"
process = subprocess.run([f'python {args.tmp}/src/csv_to_ingest.py --size s'],
shell=True, check=True, capture_output=True)
try:
process = subprocess.run([f'python {args.tmp}/src/csv_to_ingest.py --size s'],
shell=True, check=True, capture_output=True)
except subprocess.CalledProcessError as e:
print("Data conversion failed, review error messages below and try again.")
print(e)
pprint.pprint(e.output)
print("Removing repo.")
shutil.rmtree(args.tmp)
sys.exit(0)

with open(f"{args.tmp}/small_dataset_csv/raw_data_validation_results.json") as f:
errors = json.load(f)['validation_errors']
if len(errors) > 0:
Expand Down
1 change: 1 addition & 0 deletions tests/clinical_ingest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"openapi_url": "https://raw.githubusercontent.com/CanDIG/katsu/develop/chord_metadata_service/mohpackets/docs/schemas/schema.yml",

"schema_class": "MoHSchemaV3",
"donors": [
{
Expand Down