def main(): import argparse parser = argparse.ArgumentParser( description="Generate new sonata workspaces and project layouts") parser.add_argument("--init", help="Create a new sonata workspace", action="store_true") parser.add_argument("--workspace", help="location of existing (or new) workspace. " "If not specified will assume '{}'".format( Workspace.DEFAULT_WORKSPACE_DIR), required=False) parser.add_argument("--project", help="create a new project at the specified location", required=False) parser.add_argument("--debug", help="increases logging level to debug", required=False, action="store_true") args = parser.parse_args() log_level = "INFO" if args.debug: log_level = "DEBUG" coloredlogs.install(level=log_level) # Ensure that one argument is given (--init, --workspace or --project) if not args.init and not args.workspace and not args.project: parser.print_help() return # Ensure that argument --workspace is not alone if not args.init and args.workspace and not args.project: parser.print_help() return # If workspace arg is not given, create a workspace in user home if args.workspace is None: ws_root = Workspace.DEFAULT_WORKSPACE_DIR # If a workspace already exists at user home, throw an error and quit if args.init and os.path.isdir(ws_root): print("A workspace already exists in {}. " "Please specify a different location.\n".format(ws_root), file=sys.stderr) exit(1) else: ws_root = expanduser(args.workspace) if args.init: ws = Workspace(ws_root, log_level=log_level) if ws.check_ws_exists(): print( "A workspace already exists at the " "specified location, exiting", file=sys.stderr) exit(1) log.debug("Attempting to create a new workspace") cwd = os.getcwd() ws.create_dirs() ws.create_files() os.chdir(cwd) log.debug("Workspace created.") else: ws = Workspace.__create_from_descriptor__(ws_root) if not ws: print( "Could not find a SONATA workspace " "at the specified location", file=sys.stderr) exit(1) if args.project is not None: log.debug("Attempting to create a new project") prj_root = os.path.expanduser(args.project) proj = Project(ws, prj_root) proj.create_prj() log.debug("Project created.")
def main(): import argparse parser = argparse.ArgumentParser( description="Publish a project or component to the catalogue server") parser.add_argument( "--workspace", help="Specify workspace. Default is located at '{}'".format( Workspace.DEFAULT_WORKSPACE_DIR), required=False) parser.add_argument("--project", help="Specify project to be published", required=False) parser.add_argument("-d", "--component", help="Project component to be published.", required=False) parser.add_argument("-c", "--catalogue", help="Catalogue ID where to publish. " "Overrides defaults in workspace config.") args = parser.parse_args() # Ensure that either --component or --project # argument is given, but not the two simultaneously (XOR) if bool(args.component) == bool(args.project): parser.print_help() return # If workspace arg is not given, specify workspace as the default location if not args.workspace: ws_root = Workspace.DEFAULT_WORKSPACE_DIR else: ws_root = expanduser(args.workspace) # Create the Workspace object ws = Workspace.__create_from_descriptor__(ws_root) if not ws: print("Could not find a SONATA SDK workspace at '{}'".format(ws_root), file=sys.stderr) exit(1) if args.project: prj_root = os.path.expanduser(args.project) proj = Project(ws, prj_root) if not proj: print( "Could not find a SONATA SDK project at '{}'".format(prj_root), file=sys.stderr) exit(1) pub = Publisher(ws, project=proj, catalogue=args.catalogue) pub.publish_project() if args.component: comp_file = os.path.expanduser(args.component) if not os.path.isfile(comp_file): print("'{}' is not a valid file".format(comp_file), file=sys.stderr) exit(1) pub = Publisher(ws, component=comp_file, catalogue=args.catalogue) pub.publish_component()