Commit e36154f0 authored by Radek Hušek's avatar Radek Hušek
Browse files

add support for config files

default config is

  /etc/cups/cups-pdf-postprocess.conf
parent 62d8f932
...@@ -14,6 +14,8 @@ import subprocess as sp ...@@ -14,6 +14,8 @@ import subprocess as sp
import ast import ast
import os import os
CONFIG_FILE = "/etc/cups/cups-pdf-postprocess.conf"
def exec_pipeline(pipeline, inp, out = None, err_callback = None): def exec_pipeline(pipeline, inp, out = None, err_callback = None):
def make_proc(cmd): def make_proc(cmd):
p = QProcess() p = QProcess()
...@@ -55,21 +57,13 @@ def exec_pipeline(pipeline, inp, out = None, err_callback = None): ...@@ -55,21 +57,13 @@ def exec_pipeline(pipeline, inp, out = None, err_callback = None):
QApplication.instance().processEvents() 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): class CPP(QWidget):
def __init__(self, pdf, user): def __init__(self, config, pdf, user):
super().__init__() super().__init__()
self._pdf = pdf self._pdf = pdf
self._config = config
vbox = QVBoxLayout() vbox = QVBoxLayout()
vbox.addStretch(1) vbox.addStretch(1)
...@@ -232,7 +226,28 @@ class CPP(QWidget): ...@@ -232,7 +226,28 @@ class CPP(QWidget):
DIR = os.path.dirname(os.path.realpath(sys.argv[0])) DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
if __name__ == '__main__': if __name__ == '__main__':
app = QApplication(sys.argv[2:]) args = sys.argv
ex = CPP(sys.argv[1], sys.argv[2]) 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_()) sys.exit(app.exec_())
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment