Skip to content

Commit

Permalink
resolve conflicts in controller.
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Haswell committed Feb 12, 2013
2 parents 70ca7eb + cde1206 commit b37f333
Show file tree
Hide file tree
Showing 6 changed files with 281 additions and 15 deletions.
16 changes: 8 additions & 8 deletions pybitweb/controller.py
Expand Up @@ -70,7 +70,7 @@ def process_job(self, dist, architectures, version, name, suite, pkg_format, tra
except Exception as e:
print "Exception checking blacklist " + str(e)
return False

try:
current_package = self.process_package(name, version)
if not current_package.id :
Expand All @@ -82,7 +82,7 @@ def process_job(self, dist, architectures, version, name, suite, pkg_format, tra
build_env_suite_arch = self.process_build_environment_architectures(current_suite,architectures,build_environment)
current_build_env = build_env_suite_arch[0].buildenv
master_flag = True

chan = self.get_amqp_channel()
for build_env_suite_arch in build_env_suite_arch :
current_arch = build_env_suite_arch.suitearch.arch
Expand All @@ -93,8 +93,8 @@ def process_job(self, dist, architectures, version, name, suite, pkg_format, tra
current_packageinstance = self.process_packageinstance(current_build_env, current_arch, current_package, current_dist, current_format, current_suite, master_flag)
if current_packageinstance.id :
new_job = self.db.put_job(current_packageinstance,None)
# print "\nCREATED NEW JOB ID", jsonpickle.encode(new_job), "\n"
if new_job.id :
if (new_job and new_job.id):
# print "\nCREATED NEW JOB ID", jsonpickle.encode(new_job), "\n"
self.cancel_superceded_jobs(new_job)
# NEW STUFF FOR RESUBMITTING JOBS
build_request_obj = BuildRequest(new_job,transport,
Expand Down Expand Up @@ -174,7 +174,7 @@ def process_build_environment_architectures(self, suite, requested_arches, reque
# else :
# print " IGNORING (", build_env_suite_arch.suitearch.suite.name, build_env_suite_arch.suitearch.arch.name, build_env_suite_arch.buildenv.name, ") DOES NOT MATCH REQUESTED BUILD ENV (", requested_environment, ")"
else :
print "SPECIFIC ARCH (", requested_arches, ") BUILD ENV (", requested_environment, ") REQUEST..."
print "SPECIFIC ARCH (", requested_arches, ") BUILD ENV (", requested_environment, ") REQUEST..."
for build_env_suite_arch in supported_build_env_suite_arches :
build_env_name = None
if build_env_suite_arch.buildenv is not None:
Expand All @@ -184,11 +184,11 @@ def process_build_environment_architectures(self, suite, requested_arches, reque
env_arches_to_build.append(build_env_suite_arch)
print " ADDING (", build_env_suite_arch.suitearch.suite.name, build_env_suite_arch.suitearch.arch.name, build_env_suite_arch.buildenv.name, build_env_suite_arch.suitearch.master_weight, ")"
# else :
# print " IGNORING (", build_env_suite_arch.suitearch.suite.name, build_env_suite_arch.suitearch.arch.name, build_env_suite_arch.buildenv.name, ")"
# print " IGNORING (", build_env_suite_arch.suitearch.suite.name, build_env_suite_arch.suitearch.arch.name, build_env_suite_arch.buildenv.name, ")"

# for i in env_arches_to_build :
# print " ", i.buildenv.name, i.suitearch.arch.name

return env_arches_to_build

def process_package(self, name, version) :
Expand Down Expand Up @@ -259,7 +259,7 @@ def cancel_superceded_jobs(self, new_job) :
unfinished_job_suite_id = unfinished_job.packageinstance.suite.id
if (unfinished_job_dist_id == packageinstance.distribution.id) and (unfinished_job_arch_id == packageinstance.arch.id) and (unfinished_job_suite_id == packageinstance.suite.id) :
#check build env...
if (((unfinished_job.packageinstance.build_env is None) and (packageinstance.build_env is None)) or
if (((unfinished_job.packageinstance.build_env is None) and (packageinstance.build_env is None)) or
(unfinished_job.packageinstance.build_env.id == packageinstance.build_env.id)):
self.process_cancel(unfinished_job, chan)
# else :
Expand Down
10 changes: 9 additions & 1 deletion pybitweb/db.py
Expand Up @@ -1461,8 +1461,16 @@ def get_packageinstance_byvalues(self,package,build_env,arch,suite,dist,pkg_form

def put_packageinstance(self,package,build_env,arch,suite,dist,pkg_format,master):
try:

# The buildenv_id field in the DB is allowed to be null.
# We may be passed a None build_env object and must handle this.
if build_env:
build_env_id = build_env.id
else:
build_env_id = None;

cur = self.conn.cursor(cursor_factory=psycopg2.extras.DictCursor)
cur.execute("INSERT into packageinstance(package_id,buildenv_id,arch_id,suite_id,dist_id,format_id,master) VALUES (%s, %s, %s, %s, %s, %s, %s) RETURNING id",(remove_nasties(package.id),remove_nasties(build_env.id),remove_nasties(arch.id),remove_nasties(suite.id),remove_nasties(dist.id),remove_nasties(pkg_format.id),remove_nasties(master)))
cur.execute("INSERT into packageinstance(package_id,buildenv_id,arch_id,suite_id,dist_id,format_id,master) VALUES (%s, %s, %s, %s, %s, %s, %s) RETURNING id",(remove_nasties(package.id),remove_nasties(build_env_id),remove_nasties(arch.id),remove_nasties(suite.id),remove_nasties(dist.id),remove_nasties(pkg_format.id),remove_nasties(master)))
self.conn.commit()
res = cur.fetchall()
self.conn.commit()
Expand Down
12 changes: 9 additions & 3 deletions pybitweb/packageinstance.py
Expand Up @@ -94,14 +94,19 @@ def put_packageinstance():
version = request.forms.get('version')

build_env_id = request.forms.get('build_env_id')

# If thet chose "Not specified"
if (build_env_id == ""):
build_env_id = None

arch_id = request.forms.get('arch_id')
suite_id = request.forms.get('suite_id')
dist_id = request.forms.get('dist_id')
format_id = request.forms.get('format_id')
slave = request.forms.get('slave')

# This but is confusing
if slave:
if slave:
print "SLAVE NOT NULL:" + str (slave)
slave = "true"
master = "false"
Expand All @@ -111,9 +116,10 @@ def put_packageinstance():
master = "true"

if package and version and arch_id and suite_id and dist_id and format_id and slave:

build_env = None
package_obj = app.config['db'].get_package_byvalues(package,version)[0]
build_env = app.config['db'].get_build_env_id(build_env_id)
if (build_env_id):
build_env = app.config['db'].get_build_env_id(build_env_id)
arch = app.config['db'].get_arch_id(arch_id)
suite = app.config['db'].get_suite_id(suite_id)
dist = app.config['db'].get_dist_id(dist_id)
Expand Down
249 changes: 249 additions & 0 deletions pybitweb/static/blacklist.htm
@@ -0,0 +1,249 @@
<!DOCTYPE html>
<html lang="en">
<head>
<META HTTP-EQUIV='PRAGMA' CONTENT='NO-CACHE'>
<META HTTP-EQUIV="Expires" CONTENT="-1">
<meta charset="utf-8">
<title>pyBit - Lookups</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet">
<link rel="shortcut icon" href="favicon.ico">
<link rel="apple-touch-icon" href="favicon.png" />
<style type="text/css">
body
{
padding-top : 60px; /* 60px to make the container go all the way
* to the bottom of the topbar */
padding-bottom : 40px;
}
</style>
<link href="bootstrap/css/bootstrap-responsive.min.css" rel="stylesheet">
<script src="{{protocol}}{{jqueryurl}}" type="text/javascript"></script>
<script src="{{protocol}}{{jqueryformurl}}" type="text/javascript"></script>
<script src="bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
</head>
<body>
<div class="container-fluid">
<div class="row-fluid">
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="navbar-inner">
<div class="container-fluid">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse"> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </a>
<a class="brand" href="index.htm">pyBit</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li>
<a href="index.htm">Home</a>
</li>
<li class="active">
<a href="lookups.htm">Lookups</a>
</li>
<li>
<a href="package.htm">Packages</a>
</li>
<li>
<a href="packageinstance.htm">Package Instances</a>
</li>
<li>
<a href="job.htm">Jobs</a>
</li>
<li>
<a href="buildd.htm">Build Boxes</a>
</li>
</ul>
</div>
<!--/.nav-collapse -->
</div>
</div>
</div>
</div>
<div class="span2">
<!--Sidebar content-->
<div class="well sidebar-nav">
<ul class="nav nav-list">
<li class="nav-header">
Navigation
</li>
<li>
<a href="index.htm">Home</a>
</li>
<li class="nav-header">
Lookups
</li>
<li>
<a href="arches.htm">Architectures</a>
</li>
<li>
<a href="statuses.htm">Statuses</a>
</li>
<li>
<a href="dists.htm">Dists</a>
</li>
<li>
<a href="formats.htm">Formats</a>
</li>
<li>
<a href="suites.htm">Suites</a>
</li>
<li>
<a href="envs.htm">Build Environments</a>
</li>
<li class="nav-header">
Packages
</li>
<li>
<a href="package.htm">All Packages</a>
</li>
<li>
<a href="packageinstance.htm">Package Instances</a>
</li>
<li class="nav-header">
Jobs
</li>
<li>
<a href="job.htm">Jobs</a>
</li>
<li>
<a href="buildd.htm">BuildBoxes</a>
</li>
<li class="active">
<a href="blacklist.htm">Blacklist Rules</a>
</li>
</ul>
</div>
<!--/.well -->
</div>
<div class="span10">
<!--Body content-->
<div class="container-fluid">
<h1>PyBit - python Buildd Integration Toolkit.</h1>
<h3>Add Blacklist Rule</h3>
<div class="accordion" id="accordion1">
<div class="accordion-group">
<div class="accordion-heading">
<a class="accordion-toggle" data-toggle="collapse" data-parent="#accordion1" href="#collapseOne"> Blacklist Rules </a>
</div>
<div id="collapseOne" class="accordion-body collapse in">
<div class="accordion-inner">
<form class="form-inline" method="POST" action="blacklist" id="blacklist_form" name="blacklist_form">
<span class="help-block">Blacklist rules consist of a "field" and a "regex". If there is a pattern match on the field in question , we will not build.<br/>For example "name" and "(.*-dev)" will mean we do not autobuild any development packages, while "vcs_uri" and "(.*/users/*)" will block sources from locations such as /repo/users/jamesb/somebadcode</span>
<label for="field">Field</label>
<input name="field" type="text" />
<label for="regex">Regex</label>
<input name="regex" type="text" />
<button type="submit" class="btn btn-primary">
Submit
</button>
<button type="button" class="btn">
Cancel
</button>
</form>
<table id="tbl_blacklist" class="table table-bordered table-condensed">
<tr>
<th colspan='3'>Blacklist Rules</th>
</tr>
</table>
</div>
</div>
</div>
</div>
<hr>
<footer>
<p>
&copy; TCL 2012
</p>
</footer>
</div>
<!--/.fluid-container-->
<script type="text/javascript">
function getUrlVars ( )
{
var vars =
{
};
var parts = window.location.href.replace ( /[?&]+([^=&]+)=([^&]*)/gi , function ( m , key , value )
{
vars [ key ] = value;
} );
return vars;
}

function delete_click ( id , target )
{
switch (target)
{
case 3:
target = "blacklist"
break;
}
$.ajax (
{
type : "GET" ,
url : "" + window.location.protocol.toString ( ) + "//" + window.location.host.toString ( ) + "/" + target + "/" + id + "/delete" ,
error : function ( data )
{
alert ( 'Error deleting ' + target + ' with id: ' + id + "\n" + data.responseText );
location.reload ( );
} ,
success : function ( data )
{
alert ( 'OK deleting ' + target + ' with id: ' + id );
location.reload ( );
}

} );
}
$ ( ).ready ( function ( )
{
var blacklist_page = 1;
$ ( '#blacklist_form' ).ajaxForm ( function ( )
{
alert ( "blacklist Added!" );
location.reload ( );
} );
if ( getUrlVars() [ "blacklist_page" ] )
{
blacklist_page = getUrlVars() [ "blacklist_page" ]
var url = "" + window.location.protocol.toString ( ) + "//" + window.location.host.toString ( ) + "/blacklist/page/" + blacklist_page
}
else
{
var url = "" + window.location.protocol.toString ( ) + "//" + window.location.host.toString ( ) + "/blacklist/page/1"
}
new_blacklist_page = parseInt ( blacklist_page ) + 1;
last_blacklist_page = parseInt ( blacklist_page ) - 1;

$.getJSON ( url , function ( json )
{
$.each ( json , function ( i , field )
{
$ ( "#tbl_blacklist" ).append ( "<tr><td>" + field.field + "</td><td>" + field.regex + "</td><br><input id='delete' class='.btn-small btn-danger' type='button' value='Delete' onclick='delete_click(" + field.id + ",3)'></input></td></tr>" );
} );
var url2= "" + window.location.protocol.toString ( ) + "//" + window.location.host.toString ( ) + "/blacklist/count"
$.getJSON ( url2 , function ( json2 )
{

var html_part1 = "";
if (blacklist_page > 0)
{
html_part1 = "<li><a href='" + window.location.protocol.toString ( ) + "//" + window.location.host.toString ( ) + "/blacklist.htm?blacklist_page=" + last_blacklist_page + "'>Prev</a></li><li><a>" + blacklist_page + "/" + json2 + "</a></li>";
}

var html_part2 = "";
if (blacklist_page < json2) // Not last page
{
html_part2 = "<li><a href='" + window.location.protocol.toString ( ) + "//" + window.location.host.toString ( ) + "/blacklist.htm?blacklist_page=" + new_blacklist_page + "'>Next</a></li>";
}

$ ( '#tbl_blacklist' ).append ( "<div class='pagination'><ul>" + html_part1 + html_part2 + "</ul></div>" );

});
} );
} );
</script>
</div>
</div>
</body>
</html>
3 changes: 1 addition & 2 deletions pybitweb/static/envs.htm
Expand Up @@ -264,7 +264,6 @@ <h3> Add Build Environments</h3>
{
$.each ( json , function ( i , field )
{
console.log("test");
$ ( "#tbl_envs" ).append ( "<tr><td>" + field.name + "<br><input id='delete' class='.btn-small btn-danger' type='button' value='Delete' onclick='delete_click(" + field.id + ",1)'></input></td></tr>" );
} );

Expand Down Expand Up @@ -320,7 +319,7 @@ <h3> Add Build Environments</h3>

$ ( '#buildenv_suitearch_form' ).ajaxForm ( function ( )
{
alert ( "Environmrnt / Suite Arch Mapping Added!" );
alert ( "Environment / Suite Arch Mapping Added!" );
location.reload ( );
} );

Expand Down

0 comments on commit b37f333

Please sign in to comment.