本文整理匯總了Python中cheshire3.server.SimpleServer類的典型用法代碼示例。如果您正苦於以下問題:Python SimpleServer類的具體用法?Python SimpleServer怎麽用?Python SimpleServer使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了SimpleServer類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: build_architecture
def build_architecture(data=None):
# data argument provided for when function run as clean-up - always None
global session, serv, db, dbPath, docParser, \
fullTxr, fullSplitTxr, \
ppFlow, \
rebuild
# globals line 1: re-establish session; maintain user if possible
if (session):
u = session.user
else:
u = None
session = Session()
session.database = 'db_ead'
session.environment = 'apache'
session.user = u
serv = SimpleServer(session, os.path.join(cheshirePath, 'cheshire3', 'configs', 'serverConfig.xml'))
db = serv.get_object(session, 'db_ead')
dbPath = db.get_path(session, 'defaultPath')
docParser = db.get_object(session, 'LxmlParser')
# globals line 4: transformers
fullTxr = db.get_object(session, 'htmlFullTxr')
fullSplitTxr = db.get_object(session, 'htmlFullSplitTxr')
# globals line 5: workflows
ppFlow = db.get_object(session, 'preParserWorkflow'); ppFlow.load_cache(session, db)
rebuild = False
示例2: build_architecture
def build_architecture(data=None):
global rebuild, session, serv, db, dbPath
global editStore, authStore, instStore, userStore, xmlp
global docStoreConfigStore
session = Session()
session.database = 'db_hubedit'
session.environment = 'apache'
# session.user = None
serv = SimpleServer(session,
os.path.join(cheshire3Root,
'configs',
'serverConfig.xml'
)
)
db = serv.get_object(session, 'db_hubedit')
dbPath = db.get_path(session, 'defaultPath')
editStore = db.get_object(session, 'editingStore')
userStore = db.get_object(session, 'hubAuthStore')
instStore = db.get_object(session, 'institutionStore')
docStoreConfigStore = db.get_object(session, 'documentStoreConfigStore')
authStore = db.get_object(session, 'adminAuthStore')
xmlp = db.get_object(session, 'LxmlParser')
rebuild = False
示例3: __init__
def __init__(self, session, logger):
self.session = session
session.database = 'db_dickens'
serv = SimpleServer(session,
os.path.join(cheshire3Root, 'configs', 'serverConfig.xml')
)
self.db = serv.get_object(session, session.database)
self.concStore = self.db.get_object(session, 'concordanceStore')
self.collStore = self.db.get_object(session, 'collocateStore')
self.idxStore = self.db.get_object(session, 'indexStore')
self.logger = logger
示例4: main
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)
示例5: main
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)
示例6: main
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)
示例7: main
def main(argv=None):
"""Register a Database configuration file with the Cheshire3 Server."""
global argparser, session, server
if argv is None:
args = argparser.parse_args()
else:
args = argparser.parse_args(argv)
session = Session()
server = SimpleServer(session, args.serverconfig)
# Make path to configfile absolute
args.configfile = os.path.abspath(os.path.expanduser(args.configfile))
# Tell the server to register the config file
server.register_databaseConfigFile(session, args.configfile)
return 0
示例8: build_architecture
def build_architecture(data=None):
global session, serv, db, qf, xmlp, recordStore, sentenceStore, paragraphStore, resultSetStore, articleTransformer, kwicTransformer
session = Session()
session.environment = 'apache'
session.user = None
serv = SimpleServer(session,
os.path.join(cheshire3Root, 'configs', 'serverConfig.xml')
)
session.database = 'db_' + databaseName
db = serv.get_object(session, session.database)
qf = db.get_object(session, 'defaultQueryFactory')
xmlp = db.get_object(session, 'LxmlParser')
recordStore = db.get_object(session, 'recordStore')
articleTransformer = db.get_object(session, 'article-Txr')
kwicTransformer = db.get_object(session, 'kwic-Txr')
示例9: setUp
def setUp(self):
self.session = baseObjects.Session()
serverConfig = os.path.join(cheshire3Root,
'configs',
'serverConfig.xml')
self.server = SimpleServer(self.session, serverConfig)
# Disable stdout logging
lgr = self.server.get_path(self.session, 'defaultLogger')
lgr.minLevel = 60
示例10: Cheshire3ObjectTestCase
class Cheshire3ObjectTestCase(unittest.TestCase):
u"""Abstract Base Class for Cheshire3 Test Cases.
Almost all objects in Cheshire3 require a Session, and a server as its
parent, so create these now.
"""
@classmethod
def _get_class(cls):
# Return class of object to test
return C3Object
def _get_config(self):
# Return a parsed config for the object to be tested
return etree.XML('''
<subConfig id="{0.__name__}">
<objectType>{0.__module__}.{0.__name__}</objectType>
</subConfig>
'''.format(self._get_class()))
def _get_dependencyConfigs(self):
# Generator of configs for objects on which this object depends
# e.g. an Index may depends on and IndexStore for storage, and
# Selectors, Extractors etc.
return
yield
def setUp(self):
self.session = Session()
serverConfig = os.path.join(cheshire3Root,
'configs',
'serverConfig.xml')
self.server = SimpleServer(self.session, serverConfig)
for config in self._get_dependencyConfigs():
identifier = config.get('id')
self.server.subConfigs[identifier] = config
# Disable stdout logging
lgr = self.server.get_path(self.session, 'defaultLogger')
lgr.minLevel = 60
# Create object that will be tested
config = self._get_config()
self.testObj = makeObjectFromDom(self.session, config, self.server)
def tearDown(self):
pass
def test_serverInstance(self):
"Check test case's Session instance."
self.assertIsInstance(self.server, SimpleServer)
def test_instance(self):
"Check that C3Object is an instance of the expected class."
self.assertIsInstance(self.testObj, self._get_class())
示例11: build_architecture
def build_architecture(data=None):
global session, serv, db, qf, xmlp, recordStore, resultSetStore, idxStore, articleTransformer, kwicTransformer, proxExtractor, simpleExtractor, adf, fimi2, rule, arm, vecTxr, vectorStore, armTableTxr
session = Session()
session.environment = 'apache'
session.user = None
serv = SimpleServer(session,
os.path.join(cheshire3Root, 'configs', 'serverConfig.xml')
)
session.database = 'db_' + databaseName
db = serv.get_object(session, session.database)
qf = db.get_object(session, 'defaultQueryFactory')
xmlp = db.get_object(session, 'LxmlParser')
recordStore = db.get_object(session, 'recordStore')
resultSetStore = db.get_object(session, 'resultSetStore')
simpleExtractor = db.get_object(session, 'SimpleExtractor')
proxExtractor = db.get_object(session, 'ProxExtractor')
articleTransformer = db.get_object(session, 'article-Txr')
kwicTransformer = db.get_object(session, 'kwic-Txr')
idxStore = db.get_object(session, 'indexStore')
示例12: setUp
def setUp(self):
self.session = Session()
serverConfig = os.path.join(cheshire3Root,
'configs',
'serverConfig.xml')
self.server = SimpleServer(self.session, serverConfig)
for config in self._get_dependencyConfigs():
identifier = config.get('id')
self.server.subConfigs[identifier] = config
# Disable stdout logging
lgr = self.server.get_path(self.session, 'defaultLogger')
lgr.minLevel = 60
# Create object that will be tested
config = self._get_config()
self.testObj = makeObjectFromDom(self.session, config, self.server)
示例13: getCheshire3Env
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
示例14: main
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)
示例15: Session
from xml.sax.saxutils import escape
from lxml import etree
from lxml.builder import ElementMaker
from cheshire3.server import SimpleServer
from cheshire3.baseObjects import Session
from cheshire3.utils import flattenTexts
from cheshire3 import cqlParser
from cheshire3 import internal
from cheshire3 import exceptions as c3errors
cheshirePath = os.environ.get('C3HOME', '/home/cheshire')
session = Session()
session.environment = "apache"
serv = SimpleServer(session, os.path.join(cheshirePath, 'cheshire3', 'configs', 'serverConfig.xml'))
configs = {}
# determine the root URL of this handler
for configitem in apache.config_tree():
if configitem[0] == "DocumentRoot":
docRoot = configitem[1].strip("\"'")
handlerUrl = apache.get_handler_root().replace(docRoot, "")
if len(serv.databaseConfigs) < 25:
# relatively few dbs - we can safely cache them
serv._cacheDatabases(session)
for db in serv.databases.itervalues():