diff --git a/exporter.py b/exporter.py index e20dbc6..decd0a5 100755 --- a/exporter.py +++ b/exporter.py @@ -12,11 +12,11 @@ from driver import * def usage(): - print "usage 1: ./exporter.py [--port/-p wrapper_communication_port] [--type/-t (1,3)] [--scale/-s skeletal_scale] [--base/-b base_dir] input_files..." - print " Exports the given file(s) with the given settings" + print "usage 1: ./exporter.py [--port/-p wrapper_communication_port] [--base/-b base_dir] [--out/-o out_dir] input_file1.src,input_file2.src,..." + print " Exports the assets specified in the given source file(s)" print - print "usage 2: ./exporter.py [--port/-p wrapper_communication_port] [--base/-b base_dir] -" - print " Reads commands (everything after --port in usage 1) as lines from stdin" + print "usage 2: ./exporter.py [--port/-p wrapper_communication_port] [--base/-b base_dir] [--out/-o out_dir] -" + print " Reads full command lines (everything except --port) as lines from stdin" print print "usage 3: ./export.py --help|-h" print " Shows this help message" @@ -34,7 +34,7 @@ from_stdin = False if "-" in args["input"]: from_stdin = True - if len(args["input"]) > 1 or "type" in args or "scale" in args: + if len(args["input"]) > 1: print "If reading from stdin ('-') is specified, no other input may be given" usage() sys.exit(2) @@ -45,10 +45,6 @@ port = args["port"] if "port" in args else 7890 -def make_base_job_args(args): - return {"type": args["type"] if "type" in args else 1, \ - "scale": args["scale"] if "scale" in args else 1} - jobs = {} sent_all_jobs = False driver = Driver(port, from_stdin) diff --git a/exporter.py b/exporter.py index e20dbc6..decd0a5 100755 --- a/exporter.py +++ b/exporter.py @@ -12,11 +12,11 @@ from driver import * def usage(): - print "usage 1: ./exporter.py [--port/-p wrapper_communication_port] [--type/-t (1,3)] [--scale/-s skeletal_scale] [--base/-b base_dir] input_files..." - print " Exports the given file(s) with the given settings" + print "usage 1: ./exporter.py [--port/-p wrapper_communication_port] [--base/-b base_dir] [--out/-o out_dir] input_file1.src,input_file2.src,..." + print " Exports the assets specified in the given source file(s)" print - print "usage 2: ./exporter.py [--port/-p wrapper_communication_port] [--base/-b base_dir] -" - print " Reads commands (everything after --port in usage 1) as lines from stdin" + print "usage 2: ./exporter.py [--port/-p wrapper_communication_port] [--base/-b base_dir] [--out/-o out_dir] -" + print " Reads full command lines (everything except --port) as lines from stdin" print print "usage 3: ./export.py --help|-h" print " Shows this help message" @@ -34,7 +34,7 @@ from_stdin = False if "-" in args["input"]: from_stdin = True - if len(args["input"]) > 1 or "type" in args or "scale" in args: + if len(args["input"]) > 1: print "If reading from stdin ('-') is specified, no other input may be given" usage() sys.exit(2) @@ -45,10 +45,6 @@ port = args["port"] if "port" in args else 7890 -def make_base_job_args(args): - return {"type": args["type"] if "type" in args else 1, \ - "scale": args["scale"] if "scale" in args else 1} - jobs = {} sent_all_jobs = False driver = Driver(port, from_stdin) diff --git a/job.py b/job.py index d4e73e8..9c448e8 100644 --- a/job.py +++ b/job.py @@ -1,25 +1,40 @@ import os.path import base64 +import json 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) + 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.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.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 - def get_cmd(self): - with open(self.input, mode="rb") as f: - contents = f.read() + self.graphics = [] + with open(self.in_file, mode="r") as f: + graphics = [] + try: + file_json = json.loads(f.read()) + except: + raise Exception("Failed: " + in_file + " does not contain valid data") + if not "graphics" in file_json or not isinstance(file_json["graphics"], list): + raise Exception("Failed: " + in_file + " does not contain a \"graphics\" list") + for graphic_json in file_json["graphics"]: + self.graphics.append(Graphic(graphic_json)) - return {"type":self.type, "scale":self.scale, "id":self.id, "name":self.name, "input":base64.b64encode(contents)} + 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 {}