本文整理汇总了Python中quanthistling.config.environment.load_environment函数的典型用法代码示例。如果您正苦于以下问题:Python load_environment函数的具体用法?Python load_environment怎么用?Python load_environment使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_environment函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(argv):
if len(argv) < 2:
print "call: updatecomponents.py ini_file"
exit(1)
ini_file = argv[1]
dictdata_path = 'quanthistling/dictdata'
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
# update languages
for c in quanthistling.dictdata.components.list:
db_lang = Session.query(model.Component).filter_by(name=c['name']).first()
if db_lang == None:
component = model.Component()
component.name = c['name']
component.description = c['description']
Session.add(component)
Session.commit()
print("Inserted component " + c['name'] + ".")
示例2: main
def main(argv):
if len(argv) < 2:
print "call: updateversion.py ini_file"
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
new_version = False
corpusversion = Session.query(model.Corpusversion).filter_by(version=version,revision=revision).first()
if corpusversion == None:
corpusversion = model.Corpusversion()
new_version = True
corpusversion.version = version
corpusversion.revision = revision
corpusversion.updated = datetime.datetime.now()
if new_version:
Session.add(corpusversion)
Session.commit()
示例3: main
def main(argv):
bibtex_key = u"jakway2008"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
#entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=109,pos_on_page=18).all()
#entries = []
startletters = set()
for e in entries:
if dictdata.startpage == 129:
heads = annotate_head_without_comma(e)
else:
heads = annotate_head(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
annotate_translations(e)
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
for e in manual_entries:
dictdata = model.meta.Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).filter("startpage<=:pagenr and endpage>=:pagenr").params(pagenr=int(e["startpage"])).first()
entry_db = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id, startpage=e["startpage"], pos_on_page=e["pos_on_page"]).first()
if difflib.SequenceMatcher(None, e["fullentry"].decode('utf-8'), entry_db.fullentry).ratio() > 0.95:
entry_db.fullentry = e["fullentry"].decode('utf-8')
# delete all annotations in db
for a in entry_db.annotations:
Session.delete(a)
# insert new annotations
for a in e["annotations"]:
entry_db.append_annotation(a["start"], a["end"], a["value"].decode('utf-8'), a["type"].decode('utf-8'), a["string"].decode('utf-8'))
else:
print "We have a problem, manual entry on page %i pos %i seems not to be the same entry as in db, it was not inserted to db. Please correct the problem." % (e["startpage"], e["pos_on_page"])
Session.commit()
示例4: main
def main(argv):
if len(argv) < 2:
print "call: updatelanguages.py ini_file"
exit(1)
ini_file = argv[1]
dictdata_path = 'quanthistling/dictdata'
log = logging.getLogger()
logging.basicConfig(level=logging.INFO)
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
# update languages
for l in quanthistling.dictdata.languages.list:
db_lang = Session.query(model.LanguageIso).filter_by(name=l['name']).first()
if db_lang == None:
lname = l['name']
#lname = importfunctions.normalize_stroke(lname)
#lname = unicodedata.normalize("NFD", lname)
language = model.LanguageIso()
language.name = l['name']
language.langcode = l['langcode']
language.description = l['description']
language.url = l['url']
Session.add(language)
Session.commit()
log.info("Inserted language " + l['name'] + ".")
示例5: main
def main(argv):
if len(argv) < 2:
print "call: exportheads.py ini_file"
exit(1)
ini_file = argv[1]
# load web application config
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create database session
metadata.create_all(bind=Session.bind)
# database queries for pos
annotations = model.meta.Session.query(model.Annotation).join(
(model.Entry, model.Annotation.entry_id==model.Entry.id),
(model.Dictdata, model.Entry.dictdata_id==model.Dictdata.id),
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Annotation.value==u"underline").all()
books = set()
for a in annotations:
books.add(a.entry.dictdata.book.bibtex_key)
print books
示例6: setup_app
def setup_app(command, conf, vars):
"""Place any commands to setup quanthistling here"""
thread.stack_size(512 * 1024)
# Don't reload the app if it was loaded under the testing environment
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
示例7: main
def main(argv):
bibtex_key = u"dooley2006"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
#entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=1,pos_on_page=4).all()
startletters = set()
for e in entries:
#split on newline, but ignore newline at pagebreak
pagebreaks = [b[0] for b in functions.get_list_ranges_for_annotation(e, 'pagebreak')]
newlines = [n[0] for n in functions.get_list_ranges_for_annotation(e, 'newline')
if not [ b for b in pagebreaks if abs(n[0] - b) < 3 ]]
lines = []
n = last = 0
for n in newlines:
lines.append((last, n))
last = n
lines.append((n, len(e.fullentry)))
heads = annotate_first_line(e, *lines.pop(0))
for l in lines:
heads.extend(annotate_secondary_line(e, *l))
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例8: main
def main(argv):
bibtex_key = u"thiesen1998"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
# create orthography parser
base_qlc_path = "/media/Daten/Projects/git-github/qlc"
sys.path.append(os.path.join(base_qlc_path, "src"))
#import qlc.OrthographyProfile
#orthography_profile_location = os.path.join(base_qlc_path, "data", "orthography_profiles", "{0}.txt".format(bibtex_key))
#o_parser = qlc.OrthographyProfile.OrthographyProfile(orthography_profile_location)
# load dictionary data for this book
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
#entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=128,pos_on_page=18).all()
startletters = set()
for e in entries:
heads = annotate_head(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
annotate_pos(e)
annotate_translations(e)
annotate_examples(e)
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例9: main
def main(argv):
bibtex_key = u"morse1999"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
cmd = """\
delete from annotation
using book tb, entry te
where tb.bibtex_key = :bibtex_key and tb.id = te.book_id and te.id = entry_id
and annotationtype_id = (select id from annotationtype where type = 'dictinterpretation')"""
Session.execute(cmd, dict(bibtex_key=bibtex_key))
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
#entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=21,pos_on_page=12).all()
startletters = set()
for e in entries:
heads = annotate_everything(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
#annotate_dialect(e)
#annotate_pos(e)
#annotate_translations(e)
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例10: main
def main(argv):
bibtex_key = u"fastmowitz2008"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
#print "Processing %s - %s dictdata..." %(dictdata.src_language.langcode, dictdata.tgt_language.langcode)
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
#print len(entries)
#entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=343,pos_on_page=3).all()
#entries = []
startletters = set()
for e in entries:
heads = annotate_head(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
annotate_pos(e)
#Session.commit()
annotate_translations(e)
annotate_crossrefs(e)
annotate_dialect(e)
annotate_stratum(e)
#annotate_examples(e)
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例11: main
def main(argv):
bibtex_key = u"rolland1999"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
#entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=101,pos_on_page=23).all()
startletters = set()
for e in entries:
#skip subentries which start with '||'
if e.is_subentry and (e.fullentry.startswith('||') or e.fullentry.startswith(' ||')):
for a in e.annotations:
if a.annotationtype.type == 'dictinterpretation':
Session.delete(a)
continue
heads = annotate_head(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
annotate_pos(e)
annotate_translations(e)
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例12: main
def main(argv):
bibtex_key = u"tuggy1966"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entry = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=345,pos_on_page=21).first()
if entry:
for a in entry.annotations:
Session.delete(a)
Session.delete(entry)
Session.commit()
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
# entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=1,pos_on_page=1).all()
startletters = set()
for e in entries:
heads = annotate_everything(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例13: main
def main(argv):
bibtex_key = u"gerdelslocum1983"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
# entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=21,pos_on_page=3).all()
# entries.extend(Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=2,pos_on_page=2).all())
# entries.extend(Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=2,pos_on_page=7).all())
startletters = set()
for e in entries:
try:
heads = annotate_head(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
annotate_pos(e)
annotate_translation(e)
except TypeError:
print " error on startpage: %i, pos_on_page: %i" % (e.startpage, e.pos_on_page)
raise
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例14: main
def main(argv):
bibtex_key = u"parker2010a"
if len(argv) < 2:
print "call: annotations_for%s.py ini_file" % bibtex_key
exit(1)
ini_file = argv[1]
conf = appconfig('config:' + ini_file, relative_to='.')
if not pylons.test.pylonsapp:
load_environment(conf.global_conf, conf.local_conf)
# Create the tables if they don't already exist
metadata.create_all(bind=Session.bind)
dictdatas = Session.query(model.Dictdata).join(
(model.Book, model.Dictdata.book_id==model.Book.id)
).filter(model.Book.bibtex_key==bibtex_key).all()
for dictdata in dictdatas:
entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id).all()
#entries = Session.query(model.Entry).filter_by(dictdata_id=dictdata.id,startpage=15,pos_on_page=5).all()
startletters = set()
for e in entries:
#one time data conversion
if e.fullentry.find('[email protected]') != -1 or e.fullentry.find('[email protected]') != -1:
e.fullentry = e.fullentry.replace(u'[email protected]', u's\u0308').replace(u'[email protected]', u'c\u0308')
functions.print_error_in_entry(e, 'Replacing [email protected] and [email protected]')
heads = annotate_head(e)
if not e.is_subentry:
for h in heads:
if len(h) > 0:
startletters.add(h[0].lower())
annotate_translations(e)
dictdata.startletters = unicode(repr(sorted(list(startletters))))
Session.commit()
示例15: make_app
def make_app(global_conf, full_stack=True, static_files=True, **app_conf):
"""Create a Pylons WSGI application and return it
``global_conf``
The inherited configuration for this application. Normally from
the [DEFAULT] section of the Paste ini file.
``full_stack``
Whether this application provides a full WSGI stack (by default,
meaning it handles its own exceptions and errors). Disable
full_stack when this application is "managed" by another WSGI
middleware.
``static_files``
Whether this application serves its own static files; disable
when another web server is responsible for serving them.
``app_conf``
The application's local configuration. Normally specified in
the [app:<name>] section of the Paste ini file (where <name>
defaults to main).
"""
# Configure the Pylons environment
config = load_environment(global_conf, app_conf)
# The Pylons WSGI app
app = PylonsApp(config=config)
# Routing/Session/Cache Middleware
app = RoutesMiddleware(app, config['routes.map'])
app = SessionMiddleware(app, config)
# CUSTOM MIDDLEWARE HERE (filtered by error handling middlewares)
if asbool(full_stack):
# Handle Python exceptions
app = ErrorHandler(app, global_conf, **config['pylons.errorware'])
# Display error documents for 401, 403, 404 status codes (and
# 500 when debug is disabled)
if asbool(config['debug']):
app = StatusCodeRedirect(app)
else:
app = StatusCodeRedirect(app, [400, 401, 403, 404, 500])
# Establish the Registry for this application
app = RegistryManager(app)
if asbool(static_files):
# Serve static files
static_app = StaticURLParser(config['pylons.paths']['static_files'])
app = Cascade([static_app, app])
app.config = config
return app