From 8474f2cd66b94195b8ec0c10ef44d115bcb698a6 Mon Sep 17 00:00:00 2001 From: Daniel Ellis Date: Tue, 19 Nov 2024 14:41:37 +0000 Subject: [PATCH] development --- cmipld/browse/__main__.py | 65 ++++++++++++++++++++++----------------- cmipld/locations.py | 10 +++--- 2 files changed, 42 insertions(+), 33 deletions(-) diff --git a/cmipld/browse/__main__.py b/cmipld/browse/__main__.py index 8b8b075..eabdebf 100644 --- a/cmipld/browse/__main__.py +++ b/cmipld/browse/__main__.py @@ -30,36 +30,45 @@ def main(): print(args.url) print('-'*50) - try: - if args.deps: - - # Extract dependencies - deps = processor.extract_dependencies(args.url, args.relative) - result = sorted(list(deps)) - else: - # Process document - result = processor.get( - args.url, - compact=not args.no_compact, - expand_ctx=not args.expand_ctx, - expand_links=not args.no_expand_links - ) - - # Output results - - if args.output: - output = json.dumps(result, indent=2) - with open(args.output, 'w') as f: - f.write(output) + passes=2 + while passes: + try: + if args.deps: - if args.no_interactive: - open_jless_with_memory(result) - else: - print(output) + # Extract dependencies + deps = processor.extract_dependencies(args.url, args.relative) + result = sorted(list(deps)) + else: + # Process document + result = processor.get( + args.url, + compact=not args.no_compact, + expand_ctx=not args.expand_ctx, + expand_links=not args.no_expand_links + ) + + # Output results - except Exception as e: - print(f"Error processing document: {str(e)}", file=sys.stderr) - sys.exit(1) + if args.output: + output = json.dumps(result, indent=2) + with open(args.output, 'w') as f: + f.write(output) + + if args.no_interactive: + open_jless_with_memory(result) + else: + print(output) + + passes=0 + sys.exit(0) + + except Exception as e: + if 'Could not retrieve a JSON-LD document from the URL.' in str(e): + passes-=1 + args.url+= '/graph' + if not passes: + print(f"Error processing document: {str(e)}\n\n", file=sys.stderr) + sys.exit(1) main() diff --git a/cmipld/locations.py b/cmipld/locations.py index c0f9746..d51e0f9 100644 --- a/cmipld/locations.py +++ b/cmipld/locations.py @@ -15,12 +15,12 @@ # locations mandatory for graphing script to run # added to contexts mapping = { - 'wcrp-universe': 'https://WCRP-CMIP.github.io/WCRP-UNIVERSE/', - 'mip-variables': 'https://WCRP-CMIP/github.io/MIPvariables/', - 'cmip6plus': 'https://WCRP-CMIP.github.io/CMIP6Plus_CVs/', - 'cmip7': 'https://WCRP-CMIP.github.io/CMIP7_CVs/', + 'wcrp-universe': 'https:/wcrp-cmip.github.io/WCRP-UNIVERSE/', + 'mip-variables': 'https://wcrp-cmip.github.io/MIPvariables/', + 'cmip6plus': 'https:/wcrp-cmip.github.io/CMIP6Plus_CVs/', + 'cmip7': 'https:/wcrp-cmip.github.io/CMIP7_CVs/', # 'mip-cmor-tables': 'https://PCMDI.github.io/mip-cmor-tables/', - 'cf': 'https://WCRP-CMIP.github.io/WCRP-CMIP/CF/', + 'cf': 'https:/wcrp-cmip.github.io/WCRP-CMIP/CF/', } historic = ['mip-variables','cmip6plus','cmip7','cf','wcrp-universe','mip-cmor-tables','mip-variables:', 'cmip6plus:', 'cmip7:', 'cf:', 'wcrp-universe:', 'mip-cmor-tables:']