+ if prog in [POST_BUILD, FAILED_BUILD, PRE_BUILD]:
+ if len(args) != 1:
+ parser.set_usage('Usage: %prog [options] build_id')
+ parser.print_help()
+ return 1
+ database.connect()
+ build = database.Build.query().get(args[0])
+ short_commit = builder.canonicalize_commit(build.package, build.commit, shorten=True)
+ values = { 'build_id' : build.build_id,
+ 'commit' : build.commit,
+ 'failed_stage' : build.failed_stage,
+ 'inserted_at' : build.inserted_at,
+ 'package' : build.package,
+ 'pocket' : build.pocket,
+ 'principal' : build.principal,
+ 'short_commit' : short_commit,
+ 'traceback' : build.traceback,
+ 'version' : build.version,
+ 'default_instance' : 'b%(build_id)s',
+ 'default_subject' : 'Build %(build_id)d %(result)s: %(package)s %(version)s in %(pocket)s'}
+ if prog == PRE_BUILD:
+ succeeded = True
+ elif build.succeeded:
+ assert prog == POST_BUILD
+ values['result'] = 'succeeded'
+ succeeded = True
+ else:
+ assert prog == FAILED_BUILD
+ values['result'] = 'failed'
+ succeeded = False
+ elif prog in [POST_SUBMIT, FAILED_SUBMIT]:
+ if len(args) != 4:
+ parser.set_usage('Usage: %prog [options] pocket package commit principal')
+ parser.print_help()
+ return 2
+ values = { 'pocket' : args[0],
+ 'package' : args[1],
+ 'commit' : args[2],
+ 'principal' : args[3],
+ 'default_instance' : 'submission',
+ 'default_subject' : 'Submission %(result)s: %(package)s %(version)s in %(pocket)s'}
+ if prog == POST_SUBMIT:
+ values['result'] = 'succeeded'
+ succeeded = True
+ else:
+ values['result'] = 'failed'
+ succeeded = False
+ elif prog in [POST_ADD_REPO]:
+ if len(args) != 3:
+ parser.set_usage('Usage: %prog [options] category name principal')
+ parser.print_help()
+ return 3
+ values = { 'category' : args[0],
+ 'name' : args[1],
+ 'principal' : args[2],
+ 'default_instance' : 'new-repo',
+ 'default_subject' : 'New repository %(category)s/%(name)s'}
+ succeeded = True
+ else:
+ raise AssertionError('Impossible state')
+