def run(configbase, options, args): status = 0 progname = ro_utils.progname(args) if len(args) < 2: print "%s No command given" % (progname) print "Enter '%s help' to show a list of commands" status = 2 else: status = ro_command.check_command_args(progname, options, args) if status != 0: return status # @@TODO: refactor to use command/usage table in rocommand for dispatch if args[1] == "help": status = ro_command.help(progname, args) elif args[1] == "config": status = ro_command.config(progname, configbase, options, args) elif args[1] == "create": status = ro_command.create(progname, configbase, options, args) elif args[1] == "status": status = ro_command.status(progname, configbase, options, args) elif args[1] == "add": status = ro_command.add(progname, configbase, options, args) elif args[1] == "remove": status = ro_command.remove(progname, configbase, options, args) elif args[1] in ["list", "ls"]: status = ro_command.list(progname, configbase, options, args) elif args[1] in ["annotate", "link"]: status = ro_command.annotate(progname, configbase, options, args) elif args[1] == "annotations": status = ro_command.annotations(progname, configbase, options, args) elif args[1] == "evaluate" or args[1] == "eval": status = ro_command.evaluate(progname, configbase, options, args) elif args[1] == "checkout": status = ro_command.checkout(progname, configbase, options, args) elif args[1] == "push": status = ro_command.push(progname, configbase, options, args) elif args[1] == "dump": status = ro_command.dump(progname, configbase, options, args) elif args[1] == "manifest": status = ro_command.manifest(progname, configbase, options, args) elif args[1] == "snapshot": status = ro_command.snapshot(progname, configbase, options, args) elif args[1] == "archive": status = ro_command.archive(progname, configbase, options, args) elif args[1] == "freeze": status = ro_command.freeze(progname, configbase, options, args) else: print "%s: unrecognized command: %s" % (progname, args[1]) status = 2 return status
def run(configbase, options, args): status = 0 progname = ro_utils.progname(args) if args[1] == "help": status = ro_command.help(progname, args) elif args[1] == "config": status = ro_command.config(progname, configbase, options, args) elif args[1] == "create": status = ro_command.create(progname, configbase, options, args) elif args[1] == "status": status = ro_command.status(progname, configbase, options, args) elif args[1] == "list" or args[1] == "ls": status = ro_command.list(progname, configbase, options, args) elif args[1] == "annotate": status = ro_command.annotate(progname, configbase, options, args) elif args[1] == "annotations": status = ro_command.annotations(progname, configbase, options, args) else: print "%s: unrecognized command: %s"%(progname,args[1]) status = 2 return status
def create(progname, configbase, options, args): """ Create a new Research Object. ro create RO-name [ -d dir ] [ -i RO-ident ] """ ro_options = { "roname": getoptionvalue(args[2], "Name of new research object: "), "rodir": options.rodir or "", "roident": options.roident or "" } log.debug("cwd: " + os.getcwd()) log.debug("ro_options: " + repr(ro_options)) ro_options['roident'] = ro_options['roident'] or ro_utils.ronametoident(ro_options['roname']) # Read local ro configuration and extract creator ro_config = ro_utils.readconfig(configbase) timestamp = datetime.datetime.now().replace(microsecond=0) ro_options['rocreator'] = ro_config['username'] ro_options['rocreated'] = timestamp.isoformat() ro_dir = ro_utils.ropath(ro_config, ro_options['rodir']) if not ro_dir: print ("%s: research object not in configured research object directory tree: %s" % (ro_utils.progname(args), ro_options['rodir'])) return 1 # Create directory for manifest if options.verbose: print "ro create \"%(roname)s\" -d \"%(rodir)s\" -i \"%(roident)s\"" % ro_options manifestdir = os.path.join(ro_dir, ro_settings.MANIFEST_DIR) log.debug("manifestdir: " + manifestdir) try: os.makedirs(manifestdir) except OSError: if os.path.isdir(manifestdir): # Someone else created it... # See http://stackoverflow.com/questions/273192/ # python-best-way-to-create-directory-if-it-doesnt-exist-for-file-write pass else: # There was an error on creation, so make sure we know about it raise # Create manifest file # @@TODO: create in-memory graph and serialize that manifestfilename = os.path.join(manifestdir, ro_settings.MANIFEST_FILE) log.debug("manifestfilename: " + manifestfilename) manifest = ( """<?xml version="1.0" encoding="utf-8"?> <rdf:RDF xml:base=".." xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ro="http://purl.org/wf4ever/ro#" xmlns:ore="http://www.openarchives.org/ore/terms/" xmlns:ao="http://purl.org/ao/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:foaf="http://xmlns.com/foaf/0.1/" > <ro:ResearchObject rdf:about=""> <dcterms:identifier>%(roident)s</dcterms:identifier> <dcterms:title>%(roname)s</dcterms:title> <dcterms:description>%(roname)s</dcterms:description> <dcterms:creator>%(rocreator)s</dcterms:creator> <dcterms:created>%(rocreated)s</dcterms:created> <!-- self-reference to include above details as annotation --> <ore:aggregates> <ro:AggregatedAnnotation> <ro:annotatesAggregatedResource rdf:resource="" /> <ao:body rdf:resource=".ro/manifest.rdf" /> </ro:AggregatedAnnotation> </ore:aggregates> </ro:ResearchObject> </rdf:RDF> """ % ro_options) log.debug("manifest: " + manifest) manifestfile = open(manifestfilename, 'w') manifestfile.write(manifest) manifestfile.close() return 0