From 59b612a309224b45e97464f77c6e4c65709ac620 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Tue, 29 Dec 2015 08:47:12 +0000 Subject: [PATCH] * use a list for default mimetypes (same as what it is used for) * 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 --- src/xpra/platform/darwin/printing.py | 2 +- src/xpra/platform/printing.py | 52 +++++++++++++++++++--------- src/xpra/platform/pycups_printing.py | 28 +++++++++++++++ 3 files changed, 64 insertions(+), 18 deletions(-) diff --git a/src/xpra/platform/darwin/printing.py b/src/xpra/platform/darwin/printing.py index d83f5cba4f..e8872b44bd 100644 --- a/src/xpra/platform/darwin/printing.py +++ b/src/xpra/platform/darwin/printing.py @@ -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"] diff --git a/src/xpra/platform/printing.py b/src/xpra/platform/printing.py index c2f4d97fc9..10bcdb7803 100755 --- a/src/xpra/platform/printing.py +++ b/src/xpra/platform/printing.py @@ -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: @@ -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: @@ -81,6 +92,7 @@ def get_mimetypes(): "get_default_printer", "print_files", "printing_finished", + "get_info", "DEFAULT_MIMETYPES") @@ -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:") @@ -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: diff --git a/src/xpra/platform/pycups_printing.py b/src/xpra/platform/pycups_printing.py index 4e84baf25a..667fcb6551 100755 --- a/src/xpra/platform/pycups_printing.py +++ b/src/xpra/platform/pycups_printing.py @@ -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