本文整理汇总了Python中libraries.app.app.App.db_close方法的典型用法代码示例。如果您正苦于以下问题:Python App.db_close方法的具体用法?Python App.db_close怎么用?Python App.db_close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类libraries.app.app.App
的用法示例。
在下文中一共展示了App.db_close方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from libraries.app.app import App [as 别名]
# 或者: from libraries.app.app.App import db_close [as 别名]
def handle(self, event, context):
"""
:param dict event:
:param context:
:return dict:
"""
if 'vars' in event:
App(**event['vars'])
App.logger.debug("EVENT:")
App.logger.debug(json.dumps(self.mask_event(event)))
self.data = {}
if 'data' in event and isinstance(event['data'], dict):
self.data = event['data']
if 'body-json' in event and isinstance(event['body-json'], dict):
self.data.update(event['body-json'])
try:
return self._handle(event, context)
except Exception as e:
App.logger.error(e.message)
App.logger.error('{0}: {1}'.format(str(e), traceback.format_exc()))
raise EnvironmentError('Bad Request: {}'.format(e.message))
finally:
App.db_close()
示例2: process_callback
# 需要导入模块: from libraries.app.app import App [as 别名]
# 或者: from libraries.app.app.App import db_close [as 别名]
def process_callback(self):
if not self.identifier:
error = 'No identifier found'
App.logger.error(error)
raise Exception(error)
if not self.s3_results_key:
error = 'No s3_results_key found for identifier = {0}'.format(self.identifier)
App.logger.error(error)
raise Exception(error)
id_parts = self.identifier.split('/')
self.multipart = len(id_parts) > 3
if self.multipart:
part_count, part_id, book = id_parts[1:4]
App.logger.debug('Multiple project, part {0} of {1}, linted book {2}'.
format(part_id, part_count, book))
s3__master_results_key = '/'.join(self.s3_results_key.split('/')[:-1])
else:
App.logger.debug('Single project')
s3__master_results_key = self.s3_results_key
build_log = {
'identifier': self.identifier,
'success': self.success,
'multipart_project': self.multipart,
'log': self.log,
'warnings': self.warnings,
'errors': self.errors,
's3_commit_key': self.s3_results_key
}
if not self.success:
msg = "Linter failed for identifier: " + self.identifier
build_log['warnings'].append(msg)
App.logger.error(msg)
else:
App.logger.debug("Linter {0} {1} warnings:\n{1}".format(self.identifier, len(self.warnings),
'\n'.join(self.warnings[:5])))
has_warnings = len(build_log['warnings']) > 0
if has_warnings:
msg = "Linter {0} has Warnings!".format(self.identifier)
build_log['log'].append(msg)
else:
msg = "Linter {0} completed with no warnings".format(self.identifier)
build_log['log'].append(msg)
ClientLinterCallback.upload_build_log(build_log, 'lint_log.json', self.temp_dir, self.s3_results_key)
results = ClientLinterCallback.deploy_if_conversion_finished(s3__master_results_key, self.identifier)
if results:
self.all_parts_completed = True
build_log = results
remove_tree(self.temp_dir) # cleanup
App.db_close()
return build_log
示例3: test_setup_db_with_connection_string_parts
# 需要导入模块: from libraries.app.app import App [as 别名]
# 或者: from libraries.app.app.App import db_close [as 别名]
def test_setup_db_with_connection_string_parts(self):
App(db_protocol='sqlite', db_user=None, db_pass=None, db_end_point=None, db_port=None, db_name=':memory:',
db_connection_string_params=None)
App.db_create_tables([User.__table__])
user = User(name='ed', fullname='Edward Scissorhands', password='12345')
user.insert()
user_from_db = User.get(name='ed')
self.assertIsNotNone(user_from_db)
self.assertEqual(user_from_db.password, '12345')
App.db_close()
示例4: test_update_manifest
# 需要导入模块: from libraries.app.app import App [as 别名]
# 或者: from libraries.app.app.App import db_close [as 别名]
def test_update_manifest(self):
repo_name = self.items['francis/fr_ulb']['repo_name']
user_name = self.items['francis/fr_ulb']['user_name']
tx_manifest = TxManifest.get(repo_name=repo_name, user_name=user_name)
# Update by setting fields and calling update()
tx_manifest.resource_id = 'udb'
tx_manifest.title = 'Unlocked Dynamic Bible'
tx_manifest.update()
manifest_from_db = TxManifest.get(repo_name=repo_name, user_name=user_name)
self.assertEqual(manifest_from_db.title, tx_manifest.title)
# Update by giving a dict to update()
tx_manifest.views = 5
tx_manifest.update()
manifest_from_db = TxManifest.get(repo_name=repo_name, user_name=user_name)
self.assertEqual(manifest_from_db.views, 5)
App.db_close()
示例5: tearDown
# 需要导入模块: from libraries.app.app import App [as 别名]
# 或者: from libraries.app.app.App import db_close [as 别名]
def tearDown(self):
"""Runs after each test."""
App.db_close()
shutil.rmtree(self.base_temp_dir, ignore_errors=True)
示例6: search_projects
# 需要导入模块: from libraries.app.app import App [as 别名]
# 或者: from libraries.app.app.App import db_close [as 别名]
def search_projects(self, criterion):
"""
search for repos in manifest that match criterion
:param criterion:
:return:
"""
App.logger.debug("Start: search_repos: " + json.dumps(criterion))
self.criterion = json.loads(json.dumps(criterion)) # clone so we can modify
try:
query = TxManifest.query()
self.url_params = ""
k = 'languages'
if k in self.criterion: # apply languages first
v = self.criterion[k]
del self.criterion[k]
query = self.apply_filters(query, k, v)
if query is None:
return None
for k in self.criterion: # apply everything else
v = self.criterion[k]
query = self.apply_filters(query, k, v)
if query is None:
return None
if len(self.url_params) > 0 and (self.url_params[0] == '&'):
self.url_params = self.url_params[1:]
self.url_params = '?' + self.url_params
if 'sort_by' in self.criterion:
db_key = getattr(TxManifest, self.criterion['sort_by'], None)
if db_key:
query = query.order_by(db_key)
if 'sort_by_reversed' in self.criterion:
db_key = getattr(TxManifest, self.criterion['sort_by_reversed'], None)
if db_key:
query = query.order_by(db_key.desc())
except Exception as e:
self.log_error('Failed to create a query: ' + str(e))
return None
limit = 100 if 'matchLimit' not in self.criterion else self.criterion['matchLimit']
results = query.limit(limit).all() # get all matching
data = []
if results:
App.logger.debug('Returning search result count of {0}'.format(len(results)))
returned_fields = "repo_name, user_name, title, lang_code, manifest, last_updated, views" \
if "returnedFields" not in self.criterion else self.criterion["returnedFields"]
returned_fields = returned_fields.replace('resID', 'resource_id')
returned_fields = returned_fields.replace('resType', 'resource_type')
returned_fields = returned_fields.split(',')
# copy wanted fields from this result item
for result in results:
item = {}
for key in returned_fields:
key = key.strip()
if hasattr(result, key):
value = getattr(result, key)
destination_key = key
if key == 'resource_id':
destination_key = 'resID'
elif key == 'resource_type':
destination_key = 'resType'
item[destination_key] = value
if isinstance(value, datetime.datetime):
item[destination_key] = str(value)
data.append(item)
else: # record is not present
App.logger.debug('No entries found in search')
App.db_close()
self.save_url_search()
return data
示例7: tearDown
# 需要导入模块: from libraries.app.app import App [as 别名]
# 或者: from libraries.app.app.App import db_close [as 别名]
def tearDown(self):
"""Runs after each test."""
App.db_close()