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

asset_src_schema = {
  "type":"object",
  "properties":{
    "graphics":{"type":"array"}
  }
}

class Job:
  next_id = 0
  def __init__(self, in_file, base_dir = None, out_dir = None):
    if not os.path.isfile(in_file):
      raise Exception("Failed: couldn't open " + in_file)
    self.id = Job.next_id
    Job.next_id += 1
    self.in_file = abspath(in_file)
    split = os.path.split(self.in_file)
    self.base_dir = base_dir if base_dir is not None else split[0]
    if not file_in_path(self.in_file, self.base_dir):
      raise Exception("Failed: " + in_file + " is not in base dir " + self.base_dir)
    self.name = os.path.splitext(split[1])[0]
    self.done = False
    self.graphics = []
    with open(self.in_file, mode="r") as f:
      graphics = []
      file_json = {}
      try:
        file_json = json.loads(f.read())
      except:
        raise Exception("Failed: " + in_file + " does not contain valid data")

    try:
      validate(instance=file_json, schema=asset_src_schema)
    except Exception, e:
      raise Exception("Faield: " + in_files + " " + str(e))

    for graphic_json in file_json["graphics"]:
      self.graphics.append(Graphic(graphic_json))

  def get_cmd(self):
    return {"graphics":[g.get_cmd() for g in self.graphic], "id":self.id}

class Graphic:
  def __init__(self, json):
    self.json = json
    
  def get_cmd():
    return {}