本文整理汇总了Python中bitten.model.BuildStep.select方法的典型用法代码示例。如果您正苦于以下问题:Python BuildStep.select方法的具体用法?Python BuildStep.select怎么用?Python BuildStep.select使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitten.model.BuildStep
的用法示例。
在下文中一共展示了BuildStep.select方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: template_data
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def template_data(self):
failed_steps = BuildStep.select(self.env, build=self.build.id,
status=BuildStep.FAILURE)
platform = TargetPlatform.fetch(self.env, id=self.build.platform)
reposname, repos, change = self.get_change()
return {
'build': {
'id': self.build.id,
'status': self.readable_states[self.build.status],
'link': self.build_link(),
'config': self.build.config,
'platform': getattr(platform, 'name', 'unknown'),
'slave': self.build.slave,
'failed_steps': [{
'name': step.name,
'description': step.description,
'errors': step.errors,
'log_messages': self.get_all_log_messages_for_step(step),
} for step in failed_steps],
},
'change': {
'rev': display_rev(repos, change.rev),
'link': self.env.abs_href.changeset(change.rev,
reposname != '(default)' and reposname or None),
'author': change.author,
},
}
示例2: reset_orphaned_builds
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def reset_orphaned_builds(self):
"""Reset all in-progress builds to ``PENDING`` state if they've been
running so long that the configured timeout has been reached.
This is used to cleanup after slaves that have unexpectedly cancelled
a build without notifying the master, or are for some other reason not
reporting back status updates.
"""
if not self.timeout:
# If no timeout is set, none of the in-progress builds can be
# considered orphaned
return
db = self.env.get_db_cnx()
now = int(time.time())
for build in Build.select(self.env, status=Build.IN_PROGRESS, db=db):
if now - build.started < self.timeout:
# This build has not reached the timeout yet, assume it's still
# being executed
# FIXME: ideally, we'd base this check on the last activity on
# the build, not the start time
continue
build.status = Build.PENDING
build.slave = None
build.slave_info = {}
build.started = 0
for step in list(BuildStep.select(self.env, build=build.id, db=db)):
step.delete(db=db)
build.update(db=db)
db.commit()
示例3: test_process_build_step_success_with_log
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def test_process_build_step_success_with_log(self):
recipe = """<build>
<step id="foo">
</step>
</build>"""
BuildConfig(self.env, 'test', path='somepath', active=True,
recipe=recipe).insert()
build = Build(self.env, 'test', '123', 1, slave='hal', rev_time=42,
started=42, status=Build.IN_PROGRESS)
build.slave_info[Build.IP_ADDRESS] = '127.0.0.1';
build.insert()
inbody = StringIO("""<result step="foo" status="success"
time="2007-04-01T15:30:00.0000"
duration="3.45">
<log generator="http://bitten.cmlenz.net/tools/python#unittest">
<message level="info">Doing stuff</message>
<message level="error">Ouch that hurt</message>
</log>
</result>""")
outheaders = {}
outbody = StringIO()
req = Mock(method='POST', base_path='',
path_info='/builds/%d/steps/' % build.id,
href=Href('/trac'), abs_href=Href('http://example.org/trac'),
remote_addr='127.0.0.1', args={},
perm=PermissionCache(self.env, 'hal'),
read=inbody.read,
send_response=lambda x: outheaders.setdefault('Status', x),
send_header=lambda x, y: outheaders.setdefault(x, y),
write=outbody.write)
module = BuildMaster(self.env)
assert module.match_request(req)
try:
module.process_request(req)
self.fail('Expected RequestDone')
except RequestDone:
self.assertEqual(201, outheaders['Status'])
self.assertEqual('20', outheaders['Content-Length'])
self.assertEqual('text/plain', outheaders['Content-Type'])
self.assertEqual('Build step processed', outbody.getvalue())
build = Build.fetch(self.env, build.id)
self.assertEqual(Build.SUCCESS, build.status)
assert build.stopped
assert build.stopped > build.started
steps = list(BuildStep.select(self.env, build.id))
self.assertEqual(1, len(steps))
self.assertEqual('foo', steps[0].name)
self.assertEqual(BuildStep.SUCCESS, steps[0].status)
logs = list(BuildLog.select(self.env, build=build.id, step='foo'))
self.assertEqual(1, len(logs))
self.assertEqual('http://bitten.cmlenz.net/tools/python#unittest',
logs[0].generator)
self.assertEqual(2, len(logs[0].messages))
self.assertEqual((u'info', u'Doing stuff'), logs[0].messages[0])
self.assertEqual((u'error', u'Ouch that hurt'), logs[0].messages[1])
示例4: process_request
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def process_request(self, req):
req.perm.require('BUILD_VIEW')
db = self.env.get_db_cnx()
build_id = int(req.args.get('id'))
build = Build.fetch(self.env, build_id, db=db)
assert build, 'Build %s does not exist' % build_id
if req.method == 'POST':
if req.args.get('action') == 'invalidate':
self._do_invalidate(req, build, db)
req.redirect(req.href.build(build.config, build.id))
add_link(req, 'up', req.href.build(build.config),
'Build Configuration')
data = {'title': 'Build %s - %s' % (build_id,
_status_title[build.status]),
'page_mode': 'view_build',
'build': {}}
config = BuildConfig.fetch(self.env, build.config, db=db)
data['build']['config'] = {
'name': config.label,
'href': req.href.build(config.name)
}
formatters = []
for formatter in self.log_formatters:
formatters.append(formatter.get_formatter(req, build))
summarizers = {} # keyed by report type
for summarizer in self.report_summarizers:
categories = summarizer.get_supported_categories()
summarizers.update(dict([(cat, summarizer) for cat in categories]))
data['build'].update(_get_build_data(self.env, req, build))
steps = []
for step in BuildStep.select(self.env, build=build.id, db=db):
steps.append({
'name': step.name, 'description': step.description,
'duration': pretty_timedelta(step.started, step.stopped),
'failed': step.status == BuildStep.FAILURE,
'errors': step.errors,
'log': self._render_log(req, build, formatters, step),
'reports': self._render_reports(req, config, build, summarizers,
step)
})
data['build']['steps'] = steps
data['build']['can_delete'] = ('BUILD_DELETE' in req.perm)
repos = self.env.get_repository(req.authname)
repos.authz.assert_permission(config.path)
chgset = repos.get_changeset(build.rev)
data['build']['chgset_author'] = chgset.author
add_script(req, 'bitten/tabset.js')
add_stylesheet(req, 'bitten/bitten.css')
return 'bitten_build.html', data, None
示例5: test_process_build_step_failure_continue
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def test_process_build_step_failure_continue(self):
recipe = """<build>
<step id="foo" onerror="continue">
</step>
</build>"""
BuildConfig(self.env, 'test', path='somepath', active=True,
recipe=recipe).insert()
build = Build(self.env, 'test', '123', 1, slave='hal', rev_time=42,
started=42, status=Build.IN_PROGRESS)
build.slave_info[Build.TOKEN] = '123';
build.insert()
inbody = StringIO("""<result step="foo" status="failure"
time="2007-04-01T15:30:00.0000"
duration="3.45">
</result>""")
outheaders = {}
outbody = StringIO()
req = Mock(method='POST', base_path='',
path_info='/builds/%d/steps/' % build.id,
href=Href('/trac'), abs_href=Href('http://example.org/trac'),
remote_addr='127.0.0.1', args={},
perm=PermissionCache(self.env, 'hal'),
read=inbody.read,
send_response=lambda x: outheaders.setdefault('Status', x),
send_header=lambda x, y: outheaders.setdefault(x, y),
write=outbody.write,
incookie=Cookie('trac_auth=123'))
module = BuildMaster(self.env)
module._start_new_step(build, 'foo').insert()
assert module.match_request(req)
self.assertRaises(RequestDone, module.process_request, req)
self.assertEqual(201, outheaders['Status'])
self.assertEqual('20', outheaders['Content-Length'])
self.assertEqual('text/plain', outheaders['Content-Type'])
self.assertEqual('Build step processed', outbody.getvalue())
build = Build.fetch(self.env, build.id)
self.assertEqual(Build.FAILURE, build.status)
assert build.stopped
assert build.stopped > build.started
steps = list(BuildStep.select(self.env, build.id))
self.assertEqual(1, len(steps))
self.assertEqual('foo', steps[0].name)
self.assertEqual(BuildStep.FAILURE, steps[0].status)
示例6: test_process_build_step_wrong_slave
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def test_process_build_step_wrong_slave(self):
recipe = """<build>
<step id="foo">
</step>
</build>"""
BuildConfig(self.env, 'test', path='somepath', active=True,
recipe=recipe).insert()
build = Build(self.env, 'test', '123', 1, slave='hal', rev_time=42,
started=42, status=Build.IN_PROGRESS)
build.slave_info[Build.TOKEN] = '123';
build.insert()
inbody = StringIO("""<result step="foo" status="success"
time="2007-04-01T15:30:00.0000"
duration="3.45">
<log generator="http://bitten.edgewall.org/tools/python#unittest">
<message level="info">Doing stuff</message>
<message level="error">Ouch that hurt</message>
</log>
</result>""")
outheaders = {}
outbody = StringIO()
req = Mock(method='POST', base_path='',
path_info='/builds/%d/steps/' % build.id,
href=Href('/trac'), abs_href=Href('http://example.org/trac'),
remote_addr='127.0.0.1', args={},
perm=PermissionCache(self.env, 'hal'),
read=inbody.read,
send_response=lambda x: outheaders.setdefault('Status', x),
send_header=lambda x, y: outheaders.setdefault(x, y),
write=outbody.write,
incookie=Cookie('trac_auth='))
module = BuildMaster(self.env)
module._start_new_step(build, 'foo').insert()
assert module.match_request(req)
self.assertRaises(RequestDone, module.process_request, req)
self.assertEqual(409, outheaders['Status'])
self.assertEqual('Token mismatch (wrong slave): slave=, build=123',
outbody.getvalue())
build = Build.fetch(self.env, build.id)
self.assertEqual(Build.IN_PROGRESS, build.status)
assert not build.stopped
steps = list(BuildStep.select(self.env, build.id))
self.assertEqual(1, len(steps))
示例7: _do_invalidate
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def _do_invalidate(self, req, build, db):
self.log.info('Invalidating build %d', build.id)
for step in BuildStep.select(self.env, build=build.id, db=db):
step.delete(db=db)
build.slave = None
build.started = build.stopped = 0
build.status = Build.PENDING
build.slave_info = {}
build.update()
db.commit()
req.redirect(req.href.build(build.config))
示例8: test_select
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def test_select(self):
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.executemany("INSERT INTO bitten_step VALUES (%s,%s,%s,%s,%s,%s)",
[(1, 'test', 'Foo bar', BuildStep.SUCCESS, 1, 2),
(1, 'dist', 'Foo baz', BuildStep.FAILURE, 2, 3)])
steps = list(BuildStep.select(self.env, build=1))
self.assertEqual(1, steps[0].build)
self.assertEqual('test', steps[0].name)
self.assertEqual('Foo bar', steps[0].description)
self.assertEqual(BuildStep.SUCCESS, steps[0].status)
self.assertEqual(1, steps[1].build)
self.assertEqual('dist', steps[1].name)
self.assertEqual('Foo baz', steps[1].description)
self.assertEqual(BuildStep.FAILURE, steps[1].status)
示例9: _process_build_cancellation
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def _process_build_cancellation(self, req, config, build):
self.log.info('Build slave %r cancelled build %d', build.slave,
build.id)
build.status = Build.PENDING
build.slave = None
build.slave_info = {}
build.started = 0
db = self.env.get_db_cnx()
for step in list(BuildStep.select(self.env, build=build.id, db=db)):
step.delete(db=db)
build.update(db=db)
db.commit()
for listener in BuildSystem(self.env).listeners:
listener.build_aborted(build)
self._send_response(req, 204, '', {})
示例10: test_process_build_step_wrong_slave
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def test_process_build_step_wrong_slave(self):
recipe = """<build>
<step id="foo">
</step>
</build>"""
BuildConfig(self.env, 'test', path='somepath', active=True,
recipe=recipe).insert()
build = Build(self.env, 'test', '123', 1, slave='hal', rev_time=42,
started=42, status=Build.IN_PROGRESS)
build.slave_info[Build.IP_ADDRESS] = '192.168.1.1';
build.insert()
inbody = StringIO("""<result step="foo" status="success"
time="2007-04-01T15:30:00.0000"
duration="3.45">
<log generator="http://bitten.cmlenz.net/tools/python#unittest">
<message level="info">Doing stuff</message>
<message level="error">Ouch that hurt</message>
</log>
</result>""")
outheaders = {}
outbody = StringIO()
req = Mock(method='POST', base_path='',
path_info='/builds/%d/steps/' % build.id,
href=Href('/trac'), abs_href=Href('http://example.org/trac'),
remote_addr='127.0.0.1', args={},
perm=PermissionCache(self.env, 'hal'),
read=inbody.read,
send_response=lambda x: outheaders.setdefault('Status', x),
send_header=lambda x, y: outheaders.setdefault(x, y),
write=outbody.write)
module = BuildMaster(self.env)
assert module.match_request(req)
try:
module.process_request(req)
self.fail('Expected HTTPForbidden')
except HTTPForbidden, e:
self.assertEqual('Build 1 has been invalidated for host 127.0.0.1.', e.detail)
build = Build.fetch(self.env, build.id)
self.assertEqual(Build.IN_PROGRESS, build.status)
assert not build.stopped
steps = list(BuildStep.select(self.env, build.id))
self.assertEqual(0, len(steps))
示例11: get_timeline_events
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def get_timeline_events(self, req, start, stop, filters):
if 'build' not in filters:
return
# Attachments (will be rendered by attachment module)
for event in AttachmentModule(self.env).get_timeline_events(
req, Resource('build'), start, stop):
yield event
start = to_timestamp(start)
stop = to_timestamp(stop)
add_stylesheet(req, 'bitten/bitten.css')
db = self.env.get_db_cnx()
cursor = db.cursor()
cursor.execute("SELECT b.id,b.config,c.label,c.path, b.rev,p.name,"
"b.stopped,b.status FROM bitten_build AS b"
" INNER JOIN bitten_config AS c ON (c.name=b.config) "
" INNER JOIN bitten_platform AS p ON (p.id=b.platform) "
"WHERE b.stopped>=%s AND b.stopped<=%s "
"AND b.status IN (%s, %s) ORDER BY b.stopped",
(start, stop, Build.SUCCESS, Build.FAILURE))
repos = self.env.get_repository(authname=req.authname)
assert repos, 'No "(default)" Repository: Add a repository or alias ' \
'named "(default)" to Trac.'
event_kinds = {Build.SUCCESS: 'successbuild',
Build.FAILURE: 'failedbuild'}
for id_, config, label, path, rev, platform, stopped, status in cursor:
if not _has_permission(req.perm, repos, path, rev=rev):
continue
errors = []
if status == Build.FAILURE:
for step in BuildStep.select(self.env, build=id_,
status=BuildStep.FAILURE,
db=db):
errors += [(step.name, error) for error
in step.errors]
display_rev = repos.normalize_rev(rev)
yield (event_kinds[status], to_datetime(stopped, utc), None,
(id_, config, label, display_rev, platform, status,
errors))
示例12: _format_plaintext
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def _format_plaintext(self, event):
failed_steps = BuildStep.select(self.env, build=event.target.id,
status=BuildStep.FAILURE)
change = self._get_changeset(event.target)
data = {
'build': {
'id': event.target.id,
'status': self.readable_states.get(
event.target.status, event.target.status
),
'link': self._build_link(event.target),
'config': event.target.config,
'slave': event.target.slave,
'failed_steps': [{
'name': step.name,
'description': step.description,
'errors': step.errors,
'log_messages':
self._get_all_log_messages_for_step(event.target,
step),
} for step in failed_steps],
},
'change': {
'rev': change.rev,
'link': self.env.abs_href.changeset(change.rev),
'author': change.author,
},
'project': {
'name': self.env.project_name,
'url': self.env.project_url or self.env.abs_href(),
'descr': self.env.project_description
}
}
chrome = Chrome(self.env)
dirs = []
for provider in chrome.template_providers:
dirs += provider.get_templates_dirs()
templates = TemplateLoader(dirs, variable_lookup='lenient')
template = templates.load('bitten_plaintext.txt',
cls=NewTextTemplate)
if template:
stream = template.generate(**data)
return stream.render('text')
示例13: reset_orphaned_builds
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def reset_orphaned_builds(self):
"""Reset all in-progress builds to ``PENDING`` state if they've been
running so long that the configured timeout has been reached.
This is used to cleanup after slaves that have unexpectedly cancelled
a build without notifying the master, or are for some other reason not
reporting back status updates.
"""
if not self.timeout:
# If no timeout is set, none of the in-progress builds can be
# considered orphaned
return
db = self.env.get_db_cnx()
now = int(time.time())
for build in Build.select(self.env, status=Build.IN_PROGRESS, db=db):
if now - build.last_activity < self.timeout:
# This build has not reached the timeout yet, assume it's still
# being executed
continue
self.log.info('Orphaning build %d. Last activity was %s (%s)' % \
(build.id, format_datetime(build.last_activity),
pretty_timedelta(build.last_activity)))
build.status = Build.PENDING
build.slave = None
build.slave_info = {}
build.started = 0
build.stopped = 0
build.last_activity = 0
for step in list(BuildStep.select(self.env, build=build.id, db=db)):
step.delete(db=db)
build.update(db=db)
Attachment.delete_all(self.env, 'build', build.resource.id, db)
db.commit()
示例14: _format_plaintext
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def _format_plaintext(self, event):
failed_steps = BuildStep.select(self.env, build=event.target.id, status=BuildStep.FAILURE)
change = self._get_changeset(event.target)
data = {
"build": {
"id": event.target.id,
"status": self.readable_states.get(event.target.status, event.target.status),
"link": self._build_link(event.target),
"config": event.target.config,
"slave": event.target.slave,
"failed_steps": [
{
"name": step.name,
"description": step.description,
"errors": step.errors,
"log_messages": self._get_all_log_messages_for_step(event.target, step),
}
for step in failed_steps
],
},
"change": {"rev": change.rev, "link": self.env.abs_href.changeset(change.rev), "author": change.author},
"project": {
"name": self.env.project_name,
"url": self.env.project_url or self.env.abs_href(),
"descr": self.env.project_description,
},
}
chrome = Chrome(self.env)
dirs = []
for provider in chrome.template_providers:
dirs += provider.get_templates_dirs()
templates = TemplateLoader(dirs, variable_lookup="lenient")
template = templates.load("bitten_plaintext.txt", cls=NewTextTemplate)
if template:
stream = template.generate(**data)
output = stream.render("text")
return output
示例15: template_data
# 需要导入模块: from bitten.model import BuildStep [as 别名]
# 或者: from bitten.model.BuildStep import select [as 别名]
def template_data(self):
failed_steps = BuildStep.select(self.env, build=self.build.id,
status=BuildStep.FAILURE)
change = self.get_changeset()
return {
'build': {
'id': self.build.id,
'status': self.readable_states[self.build.status],
'link': self.build_link(),
'config': self.build.config,
'slave': self.build.slave,
'failed_steps': [{
'name': step.name,
'description': step.description,
'errors': step.errors,
'log_messages': self.get_all_log_messages_for_step(step),
} for step in failed_steps],
},
'change': {
'rev': change.rev,
'link': self.env.abs_href.changeset(change.rev),
'author': change.author,
},
}