def _parser_callback(args): csar_path = Path(args.csar) if not csar_path.is_file(): raise argparse.ArgumentTypeError("CSAR file {} is not a valid path!".format(args.csar)) # if the output is set use it, if not create a random file name with UUID if args.destination: extracted_folder = Path(args.destination) else: # generate a unique extracted CSAR folder name extracted_folder = Path(generate_random_pathname("opera-unpackage-")) try: abs_csar_path = str(csar_path.resolve()) abs_dest_path = str(extracted_folder.resolve()) unpackage(abs_csar_path, abs_dest_path) print("The CSAR was unpackaged to '{}'.".format(abs_dest_path)) except ParseError as e: print("{}: {}".format(e.loc, e)) return 1 except DataError as e: print(str(e)) return 1 return 0
def _parser_callback(args): if not Path(args.service_template_folder).is_dir(): raise argparse.ArgumentTypeError( f"Directory {args.service_template_folder} is not a valid path!") # if the output is set use it, if not create a random file name with UUID if args.output: # remove file extension if needed (".zip" or ".tar") # because shutil.make_archive already adds the extension if args.output.endswith("." + args.format): csar_output = str(Path(args.output).with_suffix("")) else: csar_output = str(Path(args.output)) else: # generate a create a unique random file name csar_output = generate_random_pathname("opera-package-") try: service_template_path = None if args.service_template: service_template_path = PurePath(args.service_template) output_package = package(PurePath(args.service_template_folder), csar_output, service_template_path, args.format) print(f"CSAR was created and packed to '{output_package}'.") except ParseError as e: print(f"{e.loc}: {e}") return 1 except DataError as e: print(str(e)) return 1 return 0