Newer
Older
exporter / job.py
import os.path
import base64
from args import *

class Job:
  next_id = 0
  def __init__(self, input, type = 1, scale = 1, base = None):
    if not os.path.isfile(input):
      raise Exception("Failed: couldn't open " + input)
    self.id = Job.next_id
    Job.next_id += 1
    self.input = abspath(input)
    split = os.path.split(input)
    self.base = base if base is not None else split[0]
    if not file_in_path(self.input, self.base):
      raise Exception("Failed: " + input + " is not in base dir " + self.base)
    self.type = type
    self.scale = scale
    self.name = os.path.splitext(split[1])[0]
    self.done = False
  def get_cmd(self):
    with open(self.input, mode="rb") as f:
      contents = f.read()

    return {"type":self.type, "scale":self.scale, "id":self.id, "name":self.name, "input":base64.b64encode(contents)}