Skip to content

Commit

Permalink
* use a list for default mimetypes (same as what it is used for)
Browse files Browse the repository at this point in the history
* add get_info to printing interface
* dump get_info when using print tool

git-svn-id: https://xpra.org/svn/Xpra/trunk@11518 3bb7dfac-3a0b-4e04-842a-767bc560f471
  • Loading branch information
totaam committed Dec 29, 2015
1 parent 197acc6 commit 59b612a
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 18 deletions.
2 changes: 1 addition & 1 deletion src/xpra/platform/darwin/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@

# Printing PDF in landscape orientation does not work properly on OSX,
# so we use PS instead:
DEFAULT_MIMETYPES = "application/postscript"
DEFAULT_MIMETYPES = ["application/postscript"]
52 changes: 35 additions & 17 deletions src/xpra/platform/printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@ def cleanup_printing():
pass


DEFAULT_MIMETYPES = "application/pdf,application/postscript"
DEFAULT_MIMETYPES = ["application/pdf", "application/postscript"]

MIMETYPES = None
def get_mimetypes():
global MIMETYPES, DEFAULT_MIMETYPES
if MIMETYPES is None:
MIMETYPES = os.environ.get("XPRA_PRINTING_MIMETYPES", DEFAULT_MIMETYPES).split(",")
v = os.environ.get("XPRA_PRINTING_MIMETYPES", )
if v is not None:
MIMETYPES = v.split(",")
else:
MIMETYPES = DEFAULT_MIMETYPES
if os.environ.get("XPRA_PRINTER_RAW", "0")=="1":
MIMETYPES.append("raw")
#make it easier to test different mimetypes:
Expand All @@ -63,10 +67,17 @@ def get_mimetypes():
return MIMETYPES


def get_info():
return {
"mimetypes" : get_mimetypes(),
"mimetypes.default" : DEFAULT_MIMETYPES,
}


#default implementation uses pycups:
from xpra.platform import platform_import
try:
from xpra.platform.pycups_printing import get_printers, print_files, printing_finished, init_printing, cleanup_printing
from xpra.platform.pycups_printing import get_printers, print_files, printing_finished, init_printing, cleanup_printing, get_info
assert get_printers and print_files and printing_finished and init_printing, cleanup_printing
except Exception as e:
#ignore the error on win32:
Expand All @@ -81,6 +92,7 @@ def get_mimetypes():
"get_default_printer",
"print_files",
"printing_finished",
"get_info",
"DEFAULT_MIMETYPES")


Expand All @@ -99,24 +111,29 @@ def main():
pass

from xpra.util import nonl, pver
def dump_dict(d):
pk = None
try:
for pk,pv in d.items():
try:
if type(pv)==unicode:
sv = pv.encode("utf8")
else:
sv = nonl(pver(pv))
except Exception as e:
sv = repr(pv)
print(" %s : %s" % (pk.ljust(32), sv))
except Exception as e:
print(" error on %s: %s" % (pk, e))
print(" raw attributes: " % d)
def dump_info(d):
print("System Configuration:")
dump_dict(d)
def dump_printers(d):
for k in sorted(d.keys()):
v = d[k]
print("* %s" % k)
pk = None
try:
for pk,pv in v.items():
try:
if type(pv)==unicode:
sv = pv.encode("utf8")
else:
sv = nonl(pver(pv))
except Exception as e:
sv = repr(pv)
print(" %s : %s" % (pk.ljust(32), sv))
except Exception as e:
print(" error on %s: %s" % (pk, e))
print(" raw attributes: " % v)
dump_dict(v)
attr = get_printer_attributes(k)
if attr:
print(" attributes:")
Expand All @@ -129,6 +146,7 @@ def dump_printers(d):
enable_color()
if len(sys.argv)<=1:
dump_printers(get_printers())
dump_info(get_info())
return 0
printers = get_printers()
if len(printers)==0:
Expand Down
28 changes: 28 additions & 0 deletions src/xpra/platform/pycups_printing.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,34 @@ def printing_finished(printpid):
}


def get_info():
from xpra.platform.printing import get_mimetypes, DEFAULT_MIMETYPES
return {
"mimetypes" : get_mimetypes(),
"mimetypes.default" : DEFAULT_MIMETYPES,
"simulate-failure" : SIMULATE_PRINT_FAILURE,
"allow-user" : ALLOW,
"raw-mode" : RAW_MODE,
"generic" : GENERIC,
"tmpdir" : FORWARDER_TMPDIR,
"mimetype.default" : DEFAULT_MIMETYPE,
"lpadmin" : LPADMIN,
"lpinfo" : LPINFO,
"forwarder" : FORWARDER_BACKEND,
"skipped-printers" : SKIPPED_PRINTERS,
"add-local-printers": ADD_LOCAL_PRINTERS,
"printer-prefix" : PRINTER_PREFIX,
"cups-dbus.default" : DEFAULT_CUPS_DBUS,
"cups-dbus" : CUPS_DBUS,
"cups-dbus.poll-delay" : POLLING_DELAY,
"mimetypes.printers": MIMETYPE_TO_PRINTER,
"mimetypes.ppd" : MIMETYPE_TO_PPD,
"cups.default-options" : DEFAULT_CUPS_OPTIONS,
"printers.predefined" : UNPROBED_PRINTER_DEFS,
"printers" : get_printer_definitions(),
}


def main():
if "-v" in sys.argv or "--verbose" in sys.argv:
from xpra.log import add_debug_category, enable_debug_for
Expand Down

0 comments on commit 59b612a

Please sign in to comment.