def main(argv=None): """Main method for cheshire3 command.""" global argparser, session, server, db if argv is None: args = argparser.parse_args() else: args = argparser.parse_args(argv) console = Cheshire3Console(args) if args.database is not None: dbid = args.database else: # Inspect context try: dbid = identify_database(session, os.getcwd()) except EnvironmentError as e: dbid = None if dbid is not None: dbline = 'db = server.get_object(session, "{0}")'.format(dbid) console.push(dbline) if args.script is not None: with open(args.script, 'r') as fh: retval = console.runsource(fh.read(), args.script) if not args.interactive: return retval console.resetbuffer() banner = '' else: banner = None console.interact(banner) return 0
def main(argv=None): global argparser, lockfilepath, lgr global session, server, db, lgr if argv is None: args = argparser.parse_args() else: args = argparser.parse_args(argv) session = Session() server = SimpleServer(session, args.serverconfig) if args.database is None: try: dbid = identify_database(session, os.getcwd()) except EnvironmentError as e: server.log_critical(session, e.message) return 1 server.log_debug( session, "database identifier not specified, discovered: {0}".format(dbid)) else: dbid = args.database try: db = server.get_object(session, dbid) except ObjectDoesNotExistException: msg = """Cheshire3 database {0} does not exist. Please provide a different database identifier using the --database option. """.format(dbid) server.log_critical(session, msg) return 2 else: lgr = db.get_path(session, 'defaultLogger') pass return args.func(args)
def main(argv=None): """Search a Cheshire3 database based on query in argv.""" global argparser, session, server, db if argv is None: args = argparser.parse_args() else: args = argparser.parse_args(argv) session = Session() server = SimpleServer(session, args.serverconfig) if args.database is None: try: dbid = identify_database(session, os.getcwd()) except EnvironmentError as e: server.log_critical(session, e.message) return 1 server.log_debug(session, "database identifier not specified, discovered: {0}".format(dbid)) else: dbid = args.database try: db = server.get_object(session, dbid) except ObjectDoesNotExistException: msg = """Cheshire3 database {0} does not exist. Please provide a different database identifier using the --database option. """.format( dbid ) server.log_critical(session, msg) return 2 else: qFac = db.get_object(session, "defaultQueryFactory") query = qFac.get_query(session, args.query, format=args.format) resultSet = db.search(session, query) return _format_resultSet(resultSet, maximumRecords=args.maxRecs, startRecord=args.startRec)
def main(argv=None): """Load data into a Cheshire3 database based on parameters in argv.""" global argparser, session, server, db if argv is None: args = argparser.parse_args() else: args = argparser.parse_args(argv) session = Session() server = SimpleServer(session, args.serverconfig) if args.database is None: try: dbid = identify_database(session, os.getcwd()) except EnvironmentError as e: server.log_critical(session, e.message) return 1 server.log_debug( session, "database identifier not specified, discovered: {0}".format(dbid)) else: dbid = args.database try: db = server.get_object(session, dbid) except ObjectDoesNotExistException: msg = """Cheshire3 database {0} does not exist. Please provide a different database identifier using the --database option. """.format(dbid) server.log_critical(session, msg) return 2 else: docFac = db.get_object(session, 'defaultDocumentFactory') docFac.load(session, args.data, args.cache, args.format, args.tagname, args.codec) wf = db.get_object(session, 'buildIndexWorkflow') wf.process(session, docFac)
def main(argv=None): """Load data into a Cheshire3 database based on parameters in argv.""" global argparser, session, server, db if argv is None: args = argparser.parse_args() else: args = argparser.parse_args(argv) session = Session() server = SimpleServer(session, args.serverconfig) if args.database is None: try: dbid = identify_database(session, os.getcwd()) except EnvironmentError as e: server.log_critical(session, e.message) return 1 server.log_debug( session, "database identifier not specified, discovered: {0}".format(dbid) ) else: dbid = args.database try: db = server.get_object(session, dbid) except ObjectDoesNotExistException: msg = """Cheshire3 database {0} does not exist. Please provide a different database identifier using the --database option. """.format(dbid) server.log_critical(session, msg) return 2 else: # Allow for multiple data arguments docFac = db.get_object(session, 'defaultDocumentFactory') for dataArg in args.data: try: docFac.load(session, dataArg, args.cache, args.format, args.tagname, args.codec ) except MissingDependencyException as e: server.log_critical(session, e.reason) missingDependencies = e.dependencies raise MissingDependencyException('cheshire3-load script', missingDependencies ) wf = db.get_object(session, 'buildIndexWorkflow') wf.process(session, docFac)
def main(argv=None): """Main method for cheshire3 command.""" global argparser, session, server, db if argv is None: args = argparser.parse_args() else: args = argparser.parse_args(argv) console = Cheshire3Console(args) if args.database is not None: dbid = args.database else: # Inspect context try: dbid = identify_database(session, os.getcwd()) except EnvironmentError as e: dbid = None if dbid is not None: dbline = 'db = server.get_object(session, "{0}")'.format(dbid) console.push(dbline) # Try to get main recordStore recordStoreLines = [ "try:", " recordStore = db.get_object(session, 'recordStore')", "except ObjectDoesNotExistException:", " recordStore = db.get_path(session, 'recordStore')", "", ] for line in recordStoreLines: console.push(line) if args.script is not None: with open(args.script, "r") as fh: retval = console.runsource(fh.read(), args.script) if not args.interactive: return retval console.resetbuffer() banner = "" else: banner = None console.interact(banner) return 0
def main(argv=None): """Search a Cheshire3 database based on query in argv.""" global argparser, session, server, db if argv is None: args = argparser.parse_args() else: args = argparser.parse_args(argv) session = Session() server = SimpleServer(session, args.serverconfig) if args.database is None: try: dbid = identify_database(session, os.getcwd()) except EnvironmentError as e: server.log_critical(session, e.message) return 1 server.log_debug( session, "database identifier not specified, discovered: {0}".format(dbid) ) else: dbid = args.database try: db = server.get_object(session, dbid) except ObjectDoesNotExistException: msg = """Cheshire3 database {0} does not exist. Please provide a different database identifier using the --database option. """.format(dbid) server.log_critical(session, msg) return 2 else: qFac = db.get_object(session, 'defaultQueryFactory') query = qFac.get_query(session, args.query, format=args.format) resultSet = db.search(session, query) return _format_resultSet(resultSet, maximumRecords=args.maxRecs, startRecord=args.startRec)
def getCheshire3Env(args): """Init and return Cheshire3 Session, Server and Database. Intialize Cheshire3 Session, Server and Database objects based on ``args``. """ # Create a Session session = Session() # Get the Server based on given serverConfig file server = SimpleServer(session, args.serverconfig) # Try to get the Database if args.database is None: try: dbid = identify_database(session, os.getcwd()) except EnvironmentError as e: server.log_critical(session, e.message) raise server.log_debug( session, "database identifier not specified, discovered: {0}".format(dbid) ) else: dbid = args.database try: db = server.get_object(session, dbid) except ObjectDoesNotExistException: msg = """Cheshire3 database {0} does not exist. Please provide a different database identifier using the --database option. """.format(dbid) server.log_critical(session, msg) raise else: # Attach a default Logger to the Session session.logger = db.get_path(session, 'defaultLogger') return session, server, db
def main(argv=None): """Load data into a Cheshire3 database based on parameters in argv.""" global argparser, session, server, db if argv is None: args = argparser.parse_args() else: args = argparser.parse_args(argv) if irods is None: raise MissingDependencyException('icheshire3-load script', 'irods (PyRods)' ) session = Session() server = SimpleServer(session, args.serverconfig) if args.database is None: try: dbid = identify_database(session, os.getcwd()) except EnvironmentError as e: server.log_critical(session, e.message) return 1 server.log_debug( session, "database identifier not specified, discovered: {0}".format(dbid)) else: dbid = args.database try: db = server.get_object(session, dbid) except ObjectDoesNotExistException: msg = """Cheshire3 database {0} does not exist. Please provide a different database identifier using the --database option. """.format(dbid) server.log_critical(session, msg) return 2 else: # Allow for multiple data arguments docFac = db.get_object(session, 'defaultDocumentFactory') for dataArg in args.data: if dataArg.startswith('irods://'): parsed = urlsplit(dataArg) else: # Examine current environment status, myEnv = irods.getRodsEnv() try: host = myEnv.getRodsHost() except AttributeError: host = myEnv.rodsHost # Port try: myEnv.getRodsPort() except AttributeError: port = myEnv.rodsPort # User try: username = myEnv.getRodsUserName() except AttributeError: username = myEnv.rodsUserName netloc = '{0}@{1}:{2}'.format(username, host, port) try: cqm = myEnv.getRodsCwd() except AttributeError: cwd = myEnv.rodsCwd path = '/'.join([cwd, dataArg]) parsed = SplitResult('irods', netloc, path, None, None) dataArg = urlunsplit(parsed) server.log_debug(session, dataArg) if args.format is None or not args.format.startswith('i'): fmt = 'irods' else: fmt = args.format server.log_debug(session, fmt) try: docFac.load(session, dataArg, args.cache, fmt, args.tagname, args.codec) except MissingDependencyException as e: server.log_critical(session, e.reason) missingDependencies = e.dependencies raise MissingDependencyException('cheshire3-load script', missingDependencies) wf = db.get_object(session, 'buildIndexWorkflow') wf.process(session, docFac)