本文整理汇总了Python中libraries.app.app.App类的典型用法代码示例。如果您正苦于以下问题:Python App类的具体用法?Python App怎么用?Python App使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了App类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
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: multipart_master_merge
def multipart_master_merge(self, s3_commit_key, resource_type, download_key, output_dir, source_dir, start,
template_file):
prefix = download_key + '/'
App.door43_s3_handler().download_dir(prefix, source_dir) # get previous templated files
source_dir = os.path.join(source_dir, download_key)
files = sorted(glob(os.path.join(source_dir, '*.*')))
for f in files:
App.logger.debug("Downloaded: " + f)
fname = os.path.join(source_dir, 'index.html')
if os.path.isfile(fname):
os.remove(fname) # remove index if already exists
elapsed_seconds = int(time.time() - start)
App.logger.debug("deploy download completed in " + str(elapsed_seconds) + " seconds")
templater = init_template(resource_type, source_dir, output_dir, template_file)
# restore index from previous passes
index_json = self.get_templater_index(s3_commit_key, 'index.json')
templater.titles = index_json['titles']
templater.chapters = index_json['chapters']
templater.book_codes = index_json['book_codes']
templater.already_converted = templater.files # do not reconvert files
# merge the source files with the template
try:
self.run_templater(templater)
success = True
except Exception as e:
App.logger.error("Error multi-part applying template {0} to resource type {1}".format(template_file,
resource_type))
self.close()
success = False
return source_dir, success
示例3: upload_converted_files
def upload_converted_files(s3_commit_key, unzip_dir):
for root, dirs, files in os.walk(unzip_dir):
for f in sorted(files):
path = os.path.join(root, f)
key = s3_commit_key + path.replace(unzip_dir, '')
App.logger.debug('Uploading {0} to {1}'.format(f, key))
App.cdn_s3_handler().upload_file(path, key, cache_time=0)
示例4: setUp
def setUp(self):
"""Runs before each test."""
App(prefix='{0}-'.format(self._testMethodName), db_connection_string='sqlite:///:memory:')
App.cdn_s3_handler().create_bucket()
self.temp_dir = tempfile.mkdtemp(prefix="test_project_printer")
self.printer = ProjectPrinter()
self.mock_s3_obs_project()
示例5: test_obs_deploy_revision_to_door43
def test_obs_deploy_revision_to_door43(self):
self.mock_s3_obs_project()
build_log_key = '{0}/build_log.json'.format(self.project_key)
ret = self.deployer.deploy_revision_to_door43(build_log_key)
self.assertTrue(ret)
self.assertTrue(App.door43_s3_handler().key_exists(build_log_key))
self.assertTrue(App.door43_s3_handler().key_exists('{0}/50.html'.format(self.project_key)))
示例6: update_project_file
def update_project_file(build_log, output_dir):
commit_id = build_log['commit_id']
user_name = build_log['repo_owner']
repo_name = build_log['repo_name']
project_json_key = 'u/{0}/{1}/project.json'.format(user_name, repo_name)
project_json = App.cdn_s3_handler().get_json(project_json_key)
project_json['user'] = user_name
project_json['repo'] = repo_name
project_json['repo_url'] = 'https://{0}/{1}/{2}'.format(App.gogs_url, user_name, repo_name)
commit = {
'id': commit_id,
'created_at': build_log['created_at'],
'status': build_log['status'],
'success': build_log['success'],
'started_at': None,
'ended_at': None
}
if 'started_at' in build_log:
commit['started_at'] = build_log['started_at']
if 'ended_at' in build_log:
commit['ended_at'] = build_log['ended_at']
if 'commits' not in project_json:
project_json['commits'] = []
commits = []
for c in project_json['commits']:
if c['id'] != commit_id:
commits.append(c)
commits.append(commit)
project_json['commits'] = commits
project_file = os.path.join(output_dir, 'project.json')
write_file(project_file, project_json)
App.cdn_s3_handler().upload_file(project_file, project_json_key, cache_time=0)
return project_json
示例7: update_project_json
def update_project_json(self, commit_id, job, repo_name, repo_owner):
"""
:param string commit_id:
:param TxJob job:
:param string repo_name:
:param string repo_owner:
:return:
"""
project_json_key = 'u/{0}/{1}/project.json'.format(repo_owner, repo_name)
project_json = App.cdn_s3_handler().get_json(project_json_key)
project_json['user'] = repo_owner
project_json['repo'] = repo_name
project_json['repo_url'] = 'https://git.door43.org/{0}/{1}'.format(repo_owner, repo_name)
commit = {
'id': commit_id,
'created_at': job.created_at,
'status': job.status,
'success': job.success,
'started_at': None,
'ended_at': None
}
if 'commits' not in project_json:
project_json['commits'] = []
commits = []
for c in project_json['commits']:
if c['id'] != commit_id:
commits.append(c)
commits.append(commit)
project_json['commits'] = commits
project_file = os.path.join(self.base_temp_dir, 'project.json')
write_file(project_file, project_json)
App.cdn_s3_handler().upload_file(project_file, project_json_key)
示例8: init_table
def init_table(self, view_count):
try:
App.language_stats_db_handler().table.delete()
except:
pass
App.language_stats_db_handler().resource.create_table(
TableName=App.language_stats_table_name,
KeySchema=[
{
'AttributeName': 'lang_code',
'KeyType': 'HASH'
}
],
AttributeDefinitions=[
{
'AttributeName': 'lang_code',
'AttributeType': 'S'
}
],
ProvisionedThroughput={
'ReadCapacityUnits': 5,
'WriteCapacityUnits': 5
},
)
lang_stats_data = {
'lang_code': ViewCountTest.LANG_CODE.lower(),
'last_updated': datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ"),
'manifest': '{}',
'views': view_count
}
lang_stats = LanguageStats(lang_stats_data).insert()
App.logger.debug("new language: " + lang_stats.lang_code)
示例9: setUp
def setUp(self):
"""Runs before each test."""
App(prefix='{0}-'.format(self._testMethodName), db_connection_string='sqlite:///:memory:')
App.cdn_s3_handler().create_bucket()
App.cdn_s3_handler().upload_file = self.mock_cdn_upload_file
App.cdn_s3_handler().get_json = self.mock_cdn_get_json
App.cdn_s3_handler().key_exists = self.mock_cdn_key_exists
try:
os.makedirs(self.base_temp_dir)
except:
pass
self.temp_dir = tempfile.mkdtemp(dir=self.base_temp_dir, prefix='callbackTest_')
self.transferred_files = []
self.raiseDownloadException = False
self.source_folder = None
self.results_key = 'u/results'
self.lint_callback_data = {
'identifier': 'dummy_id',
's3_results_key': self.results_key,
'success': True,
'info': [],
'warnings': [],
'errors': []
}
self.expected_error_count = 0
self.expected_warning_count = 0
self.expected_log_count = 0
self.expected_status = "success"
self.expected_success = True
self.expected_all_parts_completed = True
self.expected_multipart = False
示例10: test_db
def test_db(self):
App(db_connection_string='sqlite:///:memory:')
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')
示例11: set_deployed_flags
def set_deployed_flags(self, project_key, part_count, skip=-1):
tempf = tempfile.mktemp(prefix="temp", suffix="deployed")
file_utils.write_file(tempf, ' ')
for i in range(0, part_count):
if i != skip:
key = '{0}/{1}/deployed'.format(project_key, i)
App.cdn_s3_handler().upload_file(tempf, key, cache_time=0)
os.remove(tempf)
示例12: process_callback
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
示例13: template_converted_files
def template_converted_files(self, build_log, download_key, output_dir, repo_name, resource_type, s3_commit_key,
source_dir, start, template_file):
App.cdn_s3_handler().download_dir(download_key + '/', source_dir)
source_dir = os.path.join(source_dir, download_key.replace('/', os.path.sep))
elapsed_seconds = int(time.time() - start)
App.logger.debug("deploy download completed in " + str(elapsed_seconds) + " seconds")
html_files = sorted(glob(os.path.join(source_dir, '*.html')))
if len(html_files) < 1:
content = ''
if len(build_log['errors']) > 0:
content += """
<div style="text-align:center;margin-bottom:20px">
<i class="fa fa-times-circle-o" style="font-size: 250px;font-weight: 300;color: red"></i>
<br/>
<h2>Critical!</h2>
<h3>Here is what went wrong with this build:</h3>
</div>
"""
content += '<div><ul><li>' + '</li><li>'.join(build_log['errors']) + '</li></ul></div>'
else:
content += '<h1 class="conversion-requested">{0}</h1>'.format(build_log['message'])
content += '<p><i>No content is available to show for {0} yet.</i></p>'.format(repo_name)
html = """
<html lang="en">
<head>
<title>{0}</title>
</head>
<body>
<div id="content">{1}</div>
</body>
</html>""".format(repo_name, content)
repo_index_file = os.path.join(source_dir, 'index.html')
write_file(repo_index_file, html)
# merge the source files with the template
templater = init_template(resource_type, source_dir, output_dir, template_file)
try:
self.run_templater(templater)
success = True
except Exception as e:
App.logger.error("Error applying template {0} to resource type {1}:".format(template_file, resource_type))
App.logger.error(e.message)
App.logger.error('{0}: {1}'.format(str(e), traceback.format_exc()))
self.close()
success = False
if success:
# update index of templated files
index_json_fname = 'index.json'
index_json = self.get_templater_index(s3_commit_key, index_json_fname)
App.logger.debug("initial 'index.json': " + json.dumps(index_json)[:256])
self.update_index_key(index_json, templater, 'titles')
self.update_index_key(index_json, templater, 'chapters')
self.update_index_key(index_json, templater, 'book_codes')
App.logger.debug("final 'index.json': " + json.dumps(index_json)[:256])
self.write_data_to_file(output_dir, s3_commit_key, index_json_fname, index_json)
return source_dir, success
示例14: mock_s3_obs_project
def mock_s3_obs_project(self):
zip_file = os.path.join(self.resources_dir, 'converted_projects', 'en-obs-complete.zip')
out_dir = os.path.join(self.temp_dir, 'en-obs-complete')
unzip(zip_file, out_dir)
project_dir = os.path.join(out_dir, 'door43', 'en-obs', '12345678')
self.project_files = [f for f in os.listdir(project_dir) if os.path.isfile(os.path.join(project_dir, f))]
self.project_key = 'door43/en-obs/12345678'
for filename in self.project_files:
App.cdn_s3_handler().upload_file(os.path.join(project_dir, filename), 'u/{0}/{1}'.format(self.project_key, filename))
App.cdn_s3_handler().upload_file(os.path.join(out_dir, 'door43', 'en-obs', 'project.json'), 'u/door43/en-obs/project.json')
示例15: test_setup_db_with_connection_string_parts
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()