Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Radek Hušek
cups-pdf-postprocess
Commits
e36154f0
Commit
e36154f0
authored
Oct 18, 2017
by
Radek Hušek
Browse files
add support for config files
default config is /etc/cups/cups-pdf-postprocess.conf
parent
62d8f932
Changes
1
Hide whitespace changes
Inline
Side-by-side
cups-pdf-postprocess.py
View file @
e36154f0
...
...
@@ -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_
())
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment