Exemplo n.º 1
0
def main(argv=None):
    global argparser, lockfilepath
    global session, server, db
    if argv is None:
        args = argparser.parse_args()
    else:
        args = argparser.parse_args(argv)
    try:
        session, server, db = getCheshire3Env(args)
    except (EnvironmentError, ObjectDoesNotExistException):
        return 1
    with db.get_path(session, 'defaultLogger') as session.logger:
        mp = db.get_path(session, 'metadataPath')
        lock = FileLock(mp)
        if lock.is_locked() and args.unlock:
            # Forcibly unlock
            session.logger.log_warning(session, "Unlocking Database")
            lock.break_lock()
        try:
            lock.acquire(timeout=30)    # wait up to 30 seconds
        except LockTimeout:
            msg = ("The database is locked. It is possible that another"
                   "user is currently indexing this database. Please wait at "
                   "least 10 minutes and then try again. If you continue to "
                   "get this message and you are sure no one is reindexing "
                   "the database please contact the archives hub team for "
                   "advice."
                   )
            session.logger.log_critical(session, msg)
            return 1
        try:
            return args.func(args)
        finally:
            lock.release()
Exemplo n.º 2
0
def main(argv=None):
    global argparser
    global session, server, db, qf, recordStore
    if argv is None:
        args = argparser.parse_args()
    else:
        args = argparser.parse_args(argv)
    try:
        session, server, db = getCheshire3Env(args)
    except (EnvironmentError, ObjectDoesNotExistException):
        return 1

    qf = db.get_object(session, 'defaultQueryFactory')
    recordStore = db.get_object(session, 'recordStore')

    terms = ' '.join(args.query)
    if args.cql:
        session.logger.log_debug(session,
                                 'Executing CQL: {0}'.format(terms)
                                 )
        qString = terms
    else:
        # Treat as keywords
        session.logger.log_debug(session,
                                 'Searching for all keywords "{0}"'
                                 ''.format(terms)
                                 )
        qString = ('(cql.anywhere all/relevant/proxinfo "{0}") '
                   'or/relevant/proxinfo '
                   '(dc.description all/relevant/proxinfo "{0}") '
                   'or/relevant/proxinfo '
                   '(dc.title all/relevant/proxinfo "{0}")'
                   ''.format(terms))
    doSearch(qString)
Exemplo n.º 3
0
def main(argv=None):
    global argparser
    global session, server, db, qf, recordStore
    if argv is None:
        args = argparser.parse_args()
    else:
        args = argparser.parse_args(argv)
    try:
        session, server, db = getCheshire3Env(args)
    except (EnvironmentError, ObjectDoesNotExistException):
        return 1
    qf = db.get_object(session, 'defaultQueryFactory')
    qString = u'%s %s "%s"' % (args.index, args.relation, args.term)
    try:
        scanClause = qf.get_query(session,
                                  qString,
                                  format="cql"
                                  )
    except:
        session.logger.log_critical(session,
                                    "Unparsable query {0}".format(qString)
                                    )
        return 1
    else:
        session.logger.log_debug(session,
                                 "Scanning query {0}".format(qString)
                                 )
    scanData = fetch_scanData(scanClause,
                              args.nTerms,
                              args.responsePosition
                              )
    for row in scanData:
        if row is None:
            print "'{0}' would have been here".format(args.term)
        else:
            print cleverTitleCase(row[0])