Browse files

Add getter functions to PackageInstance class in models.

  • Loading branch information...
1 parent 977b583 commit 34aff3e4804607a36be24509d0b2c026f065a85a Simon Haswell committed Feb 13, 2013
Showing with 59 additions and 42 deletions.
  1. +23 −0 pybit/models.py
  2. +20 −20 pybitweb/controller.py
  3. +16 −22 pybitweb/job.py
View
23 pybit/models.py
@@ -115,6 +115,29 @@ def __init__(self, packageinstance_id, package, arch, build_env, suite, distribu
self.distribution = distribution
self.format = pkg_format
self.master = master
+
+ def get_package_name(self):
+ return self.package.name
+
+ def get_package_version(self):
+ return self.package.version
+
+ def get_arch_name(self):
+ return self.arch.name
+
+ def get_buildenv_name(self):
+ if self.build_env is None:
+ return None
+ return self.build_env.name
+
+ def get_suite_name(self):
+ return self.suite.name
+
+ def get_distribution_name(self):
+ return self.distribution.name
+
+ def get_format_name(self):
+ return self.format.name
class Job(Model):
View
40 pybitweb/controller.py
@@ -116,26 +116,26 @@ def process_job(self, dist, architectures, version, name, suite, pkg_format, tra
#print "SENDING REQUEST WITH DATA", str(build_req)
msg = amqp.Message(build_req)
msg.properties["delivery_mode"] = 2
- routing_key = pybit.get_build_route_name(new_job.packageinstance.distribution.name,
- new_job.packageinstance.arch.name,
- new_job.packageinstance.suite.name,
- new_job.packageinstance.format.name)
- build_queue = pybit.get_build_queue_name(new_job.packageinstance.distribution.name,
- new_job.packageinstance.arch.name,
- new_job.packageinstance.suite.name,
- new_job.packageinstance.format.name)
+ routing_key = pybit.get_build_route_name(new_job.packageinstance.get_distribution_name(),
+ new_job.packageinstance.get_arch_name(),
+ new_job.packageinstance.get_suite_name(),
+ new_job.packageinstance.get_format_name())
+ build_queue = pybit.get_build_queue_name(new_job.packageinstance.get_distribution_name(),
+ new_job.packageinstance.get_arch_name(),
+ new_job.packageinstance.get_suite_name(),
+ new_job.packageinstance.get_format_name())
self.add_message_queue(build_queue, routing_key, chan)
chan.basic_publish(msg,exchange=pybit.exchange_name,routing_key=routing_key,mandatory=True)
#self.log.debug("\n____________SENDING %s ____________TO____________ %s", build_req, routing_key)
self.log.debug("SENDING BUILD REQUEST FOR JOB ID %i %s %s %s %s %s %s",
new_job.id,
- new_job.packageinstance.package.name,
- new_job.packageinstance.package.version,
- new_job.packageinstance.distribution.name,
- new_job.packageinstance.arch.name,
- new_job.packageinstance.suite.name,
- new_job.packageinstance.format.name)
+ new_job.packageinstance.get_distribution_name(),
+ new_job.packageinstance.get_package_version(),
+ new_job.packageinstance.get_distribution_name(),
+ new_job.packageinstance.get_arch_name(),
+ new_job.packageinstance.get_suite_name(),
+ new_job.packageinstance.get_format_name())
else :
self.log.warn("FAILED TO ADD JOB")
response.status = "404 - failed to add job."
@@ -266,12 +266,12 @@ def cancel_superceded_jobs(self, new_job) :
unfinished_jobs_list = self.db.get_unfinished_jobs()
chan = self.get_amqp_channel()
for unfinished_job in unfinished_jobs_list:
- unfinished_job_package_name = unfinished_job.packageinstance.package.name
- if unfinished_job_package_name == packageinstance.package.name :
+ unfinished_job_package_name = unfinished_job.packageinstance.get_package_name()
+ if unfinished_job_package_name == packageinstance.get_package_name() :
if new_job.id != unfinished_job.id :
- unfinished_job_package_version = unfinished_job.packageinstance.package.version
- command = "dpkg --compare-versions %s '<<' %s" % (packageinstance.package.version, unfinished_job_package_version)
- if (unfinished_job_package_version == packageinstance.package.version) or (os.system (command)) :
+ unfinished_job_package_version = unfinished_job.packageinstance.get_package_version()
+ command = "dpkg --compare-versions %s '<<' %s" % (packageinstance.get_package_version(), unfinished_job_package_version)
+ if (unfinished_job_package_version == packageinstance.get_package_version()) or (os.system (command)) :
unfinished_job_dist_id = unfinished_job.packageinstance.distribution.id
unfinished_job_arch_id = unfinished_job.packageinstance.arch.id
unfinished_job_suite_id = unfinished_job.packageinstance.suite.id
@@ -309,7 +309,7 @@ def cancel_package(self, package_id):
else :
unfinished_jobs_list = self.db.get_unfinished_jobs()
for unfinished_job in unfinished_jobs_list:
- if (unfinished_job.packageinstance.package.name == package.name) and (unfinished_job.packageinstance.package.version == package.version):
+ if (unfinished_job.packageinstance.get_package_name() == package.name) and (unfinished_job.packageinstance.get_package_version() == package.version):
chan = self.get_amqp_channel()
self.process_cancel(unfinished_job, chan)
return
View
38 pybitweb/job.py
@@ -165,23 +165,20 @@ def retry_job(jobid):
job = app.config['db'].get_job(jobid)
transport = app.config['db'].get_jobTransportDetails(jobid)
- package_version = job.packageinstance.package.version
- package_name = job.packageinstance.package.name
- arch = job.packageinstance.arch.name # TODO: parse list
- dist = job.packageinstance.distribution.name
- suite = job.packageinstance.suite.name
- pkg_format = job.packageinstance.format.name
- build_environment = None
+ package_version = job.packageinstance.get_package_version()
+ package_name = job.packageinstance.get_package_name()
+ arch = job.packageinstance.get_arch_name() # TODO: parse list
+ dist = job.packageinstance.get_distribution_name()
+ suite = job.packageinstance.get_suite_name()
+ pkg_format = job.packageinstance.get_format_name()
+ build_environment = job.packageinstance.get_buildenv_name()
method = transport.method
vcs_id = transport.vcs_id
uri = transport.uri
- if (job.packageinstance.build_env) :
- build_environment = job.packageinstance.build_env.name # Lookup build_environment name for the package instance
-
# Pass to controller to queue up - Pass build_environment if any.
- if app.config['controller'].process_job(dist, arch, package_version, package_name, suite, pkg_format, transport,build_environment):
+ if app.config['controller'].process_job(dist,arch,package_version,package_name,suite,pkg_format,transport,build_environment):
app.log.debug("Retry job processed OK!")
return
else:
@@ -202,20 +199,17 @@ def put_job():
if packageinstance_id and method and uri:
packageinstance = app.config['db'].get_packageinstance_id(packageinstance_id)
- package_version = packageinstance.package.version
- package_name = packageinstance.package.name
- arch = packageinstance.arch.name # TODO: parse list
- dist = packageinstance.distribution.name
- suite = packageinstance.suite.name
- pkg_format = packageinstance.format.name
- build_environment = None
-
- if (packageinstance.build_env) :
- build_environment = packageinstance.build_env.name # Lookup build_environment name for the package instance
+ package_version = packageinstance.get_package_version()
+ package_name = packageinstance.get_package_name()
+ arch = packageinstance.get_arch_name() # TODO: parse list
+ dist = packageinstance.get_distribution_name()
+ suite = packageinstance.get_suite_name()
+ pkg_format = packageinstance.get_format_name()
+ build_environment = packageinstance.get_buildenv_name()
# Pass to controller to queue up - Pass build_environment if any.
transport = Transport(None, method, uri, vcs_id)
- if app.config['controller'].process_job(dist, arch, package_version, package_name, suite, pkg_format, transport,build_environment):
+ if app.config['controller'].process_job(dist,arch,package_version,package_name,suite,pkg_format,transport,build_environment):
return
else:
return False

0 comments on commit 34aff3e

Please sign in to comment.