diff --git a/cups-pdf-postprocess.py b/cups-pdf-postprocess.py index c13e02d3d2f81f6c81889eb752b5169b447b57be..e3602f9f7904766820671611598ef21648391f87 100755 --- a/cups-pdf-postprocess.py +++ b/cups-pdf-postprocess.py @@ -14,6 +14,8 @@ import subprocess as sp import ast import os +CONFIG_FILE = "/etc/cups/cups-pdf-postprocess.conf" + def exec_pipeline(pipeline, inp, out = None, err_callback = None): def make_proc(cmd): p = QProcess() @@ -55,21 +57,13 @@ def exec_pipeline(pipeline, inp, out = None, err_callback = None): QApplication.instance().processEvents() -SAVE_AS_FILE = object() - -PRINTERS = ast.literal_eval("[\n%s\n]" % "".join(sys.stdin)) -PRINTERS.append(("Save as ...", SAVE_AS_FILE)) -for l in sp.check_output(["lpstat", "-a"]).decode("UTF-8").split("\n"): - p = l.split(" ")[0] - if p == "": - continue - PRINTERS.append((p, ["lp", "-d", p])) class CPP(QWidget): - def __init__(self, pdf, user): + def __init__(self, config, pdf, user): super().__init__() self._pdf = pdf + self._config = config vbox = QVBoxLayout() vbox.addStretch(1) @@ -232,7 +226,28 @@ class CPP(QWidget): DIR = os.path.dirname(os.path.realpath(sys.argv[0])) if __name__ == '__main__': - app = QApplication(sys.argv[2:]) - ex = CPP(sys.argv[1], sys.argv[2]) + args = sys.argv + if args[1] == '-c': + CONFIG_FILE = args[2] + args = args[2:] + else: + CONFIG_FILE = os.getenv('CUPS_PDF_POSTPROCESS_CONFIG', CONFIG_FILE) + + with open(CONFIG_FILE) as config: + CONFIG = ast.literal_eval("{\n%s\n}" % config.read()) + + SAVE_AS_FILE = object() + + PRINTERS = CONFIG.get("printers", []) + PRINTERS.append(("Save as ...", SAVE_AS_FILE)) + + for l in sp.check_output(["lpstat", "-a"]).decode("UTF-8").split("\n"): + p = l.split(" ")[0] + if p == "": + continue + PRINTERS.append((p, ["lp", "-d", p])) + + app = QApplication(args[2:]) + ex = CPP(CONFIG, args[1], args[2]) sys.exit(app.exec_())