def update(self, box=None, ip=None, port=None, status=None, key=None): """Update data on printer :ip: IP address to set to :port: Port to set to :status: Status to set to. Must be in ["ready", "paused", "printing", "errored", "offline", "cancelled", "completed"]: :returns: Boolean of sucess """ if status: ret = self.state(status) if ret == False: return False if key: self.key = key if ip: self.ip = ip if port: self.port = port if box: if box != self.blackbox.id: node = Node.get_by_id(box) if node == None: node = Node(box, None) power = Sensor(box, 2, "POWER") trigger = Sensor(box, 3, "TRIG") led = Sensor(box, 4, "LED") self.blackbox = node db_session.commit() return True
def remove_sensor(self, sensor_id): sensor = Sensor.get_by_id(sensor_id) if sensor.node_id != self.id: return False self.sensors.remove(sensor) db_session.commit() return True
def __init__(self, account_name, web_token, web_refresh_token, token_endpoint): self.account_name = account_name self.web_token = web_token self.web_refresh_token = web_refresh_token self.token_endpoint = token_endpoint db_session.add(self) db_session.commit()
def set_webid(self, webid): """Sets the web id for the printer :webid: ID that web gave back to communicate :returns: boolean of success. """ self.webid = webid db_session.commit() return True
def set_remote_name(self, remote_name): """Sets the remote name of the job. :remote_name: name that is on the octopi :returns: boolean of success """ self.remote_name = remote_name db_session.commit() return True
def set_webid(self, webid): """Sets the webid of the job. ATM is the same as ID and set at creation :webid: ID used by the web api :returns: boolean of success """ self.webid = webid db_session.commit() return True
def set_file(self, file): """Set a file for the job. Fails if job already holds a file :file: File object to be set as the file :returns: boolean of success """ if self.file != None: return False self.file = file db_session.commit() return True pass
def set_ip(self, ip, port=None): """Set the ip for a given printer :ip: IP to set on the printer :port: port to set to :returns: boolean of success """ self.ip = ip if port: self.port = port db_session.commit() return True
def __init__(self, webid, status="queued"): """Create a job object. A file object should be created first. :id: id of the job :file: file that the job refers to :status: status of the job. Leave blank by default :position: position within the list. Leave blank by default :returns: nothing """ self.webid = webid self.status = status self.file = None db_session.add(self) db_session.commit()
def complete_job(self): """Does the proper handling of a job completing. :returns: boolean of success """ job = self.current_job() if job == None: return False if self.status != "completed": return False self.jobs.remove(job) self.status = "ready" db_session.commit() return True
def __init__(self, name, path, ext=None, size=0, date=0, origin="remote"): self.name = name self.path = path self.origin = origin if ext == None: ext = name.rsplit(".", 1)[1] if date == 0: date = int(time.time()) if size == 0: size = os.stat(path).st_size self.ext = ext self.date = date self.size = size db_session.add(self) db_session.commit()
def __init__(self, node_id, sensor_type, webid=None, value=None, raw=None, friendly_id=None, state='DISCONNECTED'): self.node_id = node_id self.sensor_type = sensor_type self.webid = webid self.value self.raw self.friendly_id self.state db_session.add(self) db_session.commit()
def __init__(self, id, box, key=None, ip=None, port=80, status="offline", friendly_id=None, manufacturer=None, model=None, description=None, webid=None): """Creates a new Printer, adds to database. If printer exists or params aren't formatted correctly, will throw and exception :id: id of the printer :status: State of the printer, must be in ["ready", "paused", "printing", "errored", "offline", "cancelled", "completed"] """ self.id = id self.webid = webid self.key = key self.ip = ip self.port = port self.model = model self.friendly_id = friendly_id self.description = description self.manufacturer = manufacturer node = Node.get_by_id(box) if node == None: node = Node(box, None) power = Sensor(box, 2, "POWER") trigger = Sensor(box, 3, "TRIG") led = Sensor(box, 4, "LED") self.blackbox = node if not status in [ "ready", "paused", "printing", "errored", "offline", "cancelled", "completed" ]: status = "offline" self.status = status db_session.add(self) db_session.commit()
def state(self, state): """Set the status of the current job :state: State of the print job, must be in ["processing", "slicing", "printing", "completed", "paused", "errored", "queued"]: :returns: boolean of success """ if state == self.status: return True if self.status == "cancelled": return False if state in [ "processing", "slicing", "printing", "completed", "paused", "errored", "queued", "cancelled" ]: self.status = state db_session.commit() return True return False
def remove_job(self, job_id): """Removes the job from the job queue Fails if job is the current job :job_id: id of the job to be removed :returns: boolean of success """ job = Job.get_by_id(job_id) if job.printer_id != self.id: return False if job: if job.position == 0: if self.status == "ready" and job.status == "errored": self.jobs.remove(job) db_session.commit() return True return False self.jobs.remove(job) db_session.commit() return True return False
def add_job(self, job, position=-1): """Add a job to the printer. This will set it to the position. If another job is in that location, it bumps it back. Cannot add to front of queue :job: Adds job to the the printer queue :position: Position to be added to the queue. If -1, appends :returns: Boolean of success """ if position == 0: return False for j in self.jobs: if j.id == job.id: return False if position == -1: job.state("queued") self.jobs.append(job) db_session.commit() return True if position >= len(self.jobs): job.state("queued") self.jobs.append(job) db_session.commit() return True else: job.state("queued") self.jobs.insert(position, job) db_session.commit() return True
def set_meta(self, job): jf = job.get("job").get("file") if jf.get('name') == None: return False filament = job.get("job").get("filament") if filament: filament = json.dumps(filament) progress = job.get("progress") estimated_print_time = job.get("job").get("estimatedPrintTime") if progress: prog = {} completion = progress.get("completion") if completion == None: completion = 0 prog["completion"] = int(completion) prog["file_position"] = progress.get("filepos") prog["print_time"] = progress.get("printTime") prog["print_time_left"] = progress.get("printTimeLeft") progress = json.dumps(prog) self.filament = str(filament) self.progress = str(progress) self.estimated_print_time = str(estimated_print_time) db_session.commit() return True
def state(self, state): """Sets the status of the printer :state: Status to set to. Must be in ["ready", "paused", "printing", "errored", "offline", "cancelled", "completed"]: :returns: boolean of success """ if self.status == state: return True # if setting to offline, store the previous state if state == "offline": if self.status != "offline": if self.status in ["printing", "paused"]: self.status = "cancelled" self.prev_status = self.status self.status = "offline" db_session.commit() return True #If the printer was offline, load the prev status # and try setting the state. Makes sure cancelled and completed # still stay in that mode if self.status == "offline": self.status = self.prev_status db_session.commit() return self.state(state) if self.status == "completed": return False elif self.status == "cancelled": return False if state in [ "ready", "paused", "printing", "errored", "completed", "cancelled" ]: self.status = state db_session.commit() return True return False
def update(self): db_session.commit()
def __init__(self, id, ip, friendly_id=None): self.id = id self.ip = ip self.friendly_id = friendly_id db_session.add(self) db_session.commit()
def update(self, ip=None): if ip: self.ip = ip db_session.commit() return True
def update(self, web_token=None, web_refresh_token=None): if web_token and web_refresh_token: self.web_token = web_token self.web_refresh_token = web_refresh_token db_session.commit() return True
def set_webid(self, webid): self.webid = webid db_session.commit() return True