Commit 669fe5b3 authored by D1plo1d's avatar D1plo1d

Fixing change_job so that setting the position changes the print job's position in the queue.

parent a1123637
...@@ -329,6 +329,8 @@ class Pronserve(pronsole.pronsole, EventEmitter): ...@@ -329,6 +329,8 @@ class Pronserve(pronsole.pronsole, EventEmitter):
self.jobs.remove(int(job_id)) self.jobs.remove(int(job_id))
def do_change_job(self, job_id, **kwargs): def do_change_job(self, job_id, **kwargs):
print job_id
print kwargs
self.jobs.update(int(job_id), kwargs) self.jobs.update(int(job_id), kwargs)
def do_get_jobs(self): def do_get_jobs(self):
...@@ -345,7 +347,7 @@ class Pronserve(pronsole.pronsole, EventEmitter): ...@@ -345,7 +347,7 @@ class Pronserve(pronsole.pronsole, EventEmitter):
self.fire("job_finished", self.jobs.sanitize(self.current_job)) self.fire("job_finished", self.jobs.sanitize(self.current_job))
if len(self.jobs.list) > 0: if len(self.jobs.list) > 0:
print "Starting the next print job" print "Starting the next print job"
self.current_job = self.jobs.list.popleft() self.current_job = self.jobs.list.pop(0)
self.p.startprint(self.current_job['body'].split("\n")) self.p.startprint(self.current_job['body'].split("\n"))
self.fire("job_started", self.jobs.sanitize(self.current_job)) self.fire("job_started", self.jobs.sanitize(self.current_job))
else: else:
...@@ -361,7 +363,6 @@ class Pronserve(pronsole.pronsole, EventEmitter): ...@@ -361,7 +363,6 @@ class Pronserve(pronsole.pronsole, EventEmitter):
gen.Task(self.ioloop.add_timeout(next_timeout, self.run_print_queue_loop)) gen.Task(self.ioloop.add_timeout(next_timeout, self.run_print_queue_loop))
def update_job_progress(self, progress): def update_job_progress(self, progress):
print progress
if progress != self.previous_job_progress and self.current_job != None: if progress != self.previous_job_progress and self.current_job != None:
self.previous_job_progress = progress self.previous_job_progress = progress
self.fire("job_progress_changed", progress) self.fire("job_progress_changed", progress)
...@@ -428,7 +429,7 @@ class PrintJobQueue(EventEmitter): ...@@ -428,7 +429,7 @@ class PrintJobQueue(EventEmitter):
def __init__(self): def __init__(self):
super(PrintJobQueue, self).__init__() super(PrintJobQueue, self).__init__()
self.list = deque([]) self.list = []
self.__last_id = 0 self.__last_id = 0
def public_list(self): def public_list(self):
...@@ -441,19 +442,13 @@ class PrintJobQueue(EventEmitter): ...@@ -441,19 +442,13 @@ class PrintJobQueue(EventEmitter):
def sanitize(self, job): def sanitize(self, job):
return dict( return dict(
id = job["id"], id = job["id"],
original_file_name = job["original_file_name"], file_name = job["original_file_name"],
rank = job["rank"]
) )
def order(self):
sorted(self.list, key=lambda job: job['rank'])
def add(self, original_file_name, body): def add(self, original_file_name, body):
ext = os.path.splitext(original_file_name)[1] ext = os.path.splitext(original_file_name)[1]
job = dict( job = dict(
id = self.__last_id, id = self.__last_id,
rank = len(self.list),
original_file_name=original_file_name, original_file_name=original_file_name,
body= body, body= body,
) )
...@@ -482,9 +477,14 @@ class PrintJobQueue(EventEmitter): ...@@ -482,9 +477,14 @@ class PrintJobQueue(EventEmitter):
job = self.find_by_id(job_id) job = self.find_by_id(job_id)
if job == None: if job == None:
return False return False
job['rank'] = job_attrs['position'] # proposed future print quantity functionality
self.order() # if hasattr(job_attrs, 'qty'): job['qty'] = qty
print "Print Job Updated" if job_attrs['position']:
position = int(job_attrs['position'])
self.list.remove(job)
self.list.insert(position, job)
print int(job_attrs['position'])
print "Print #%s Job Updated ( %s )."%(job['id'], job['original_file_name'])
self.fire("job_updated", job) self.fire("job_updated", job)
def find_by_id(self, job_id): def find_by_id(self, job_id):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment