예제 #1
0
def main():
    if "-v" in sys.argv or "--verbose" in sys.argv:
        from xpra.log import add_debug_category, enable_debug_for
        add_debug_category("printing")
        enable_debug_for("printing")
        try:
            sys.argv.remove("-v")
        except:
            pass
        try:
            sys.argv.remove("--verbose")
        except:
            pass

    from xpra.util import nonl, pver

    def print_dict(d):
        for k in sorted(d.keys()):
            v = d[k]
            print("* %s : %s" % (k.ljust(32), nonl(pver(v))))

    from xpra.platform import init, clean
    try:
        init("Printing", "Printing")
        if len(sys.argv) < 3:
            print_dict(get_printers())
        else:
            printer = sys.argv[1]
            print_files(printer, sys.argv[2:], "Print Command", {})
    finally:
        clean()
예제 #2
0
파일: printing.py 프로젝트: svn2github/Xpra
def main():
    if "-v" in sys.argv or "--verbose" in sys.argv:
        from xpra.log import add_debug_category, enable_debug_for

        add_debug_category("printing")
        enable_debug_for("printing")
        try:
            sys.argv.remove("-v")
        except:
            pass
        try:
            sys.argv.remove("--verbose")
        except:
            pass

    from xpra.util import nonl, pver

    def print_dict(d):
        for k in sorted(d.keys()):
            v = d[k]
            print("* %s : %s" % (k.ljust(32), nonl(pver(v))))

    from xpra.platform import init, clean

    try:
        init("Printing", "Printing")
        if len(sys.argv) < 3:
            print_dict(get_printers())
        else:
            printer = sys.argv[1]
            print_files(printer, sys.argv[2:], "Print Command", {})
    finally:
        clean()
예제 #3
0
def main():
    if "-v" in sys.argv or "--verbose" in sys.argv:
        from xpra.log import add_debug_category, enable_debug_for
        add_debug_category("printing")
        enable_debug_for("printing")
        try:
            sys.argv.remove("-v")
        except ValueError:
            pass
        try:
            sys.argv.remove("--verbose")
        except ValueError:
            pass

    from xpra.util import nonl, pver

    def dump_dict(d):
        pk = None
        try:
            for pk, pv in d.items():
                try:
                    if isinstance(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:")
        print_nested_dict(d)

    def dump_printers(d):
        for k in sorted(d.keys()):
            v = d[k]
            print("Printers:")
            print("* %s" % k)
            dump_dict(v)
            attr = get_printer_attributes(k)
            if attr:
                print(" attributes:")
                for a in attr:
                    print("        %s" % a)

    from xpra.platform import program_context
    from xpra.log import enable_color
    from xpra.util import csv
    with program_context("Printing", "Printing"):
        enable_color()
        try:
            init_printing()
        except Exception as e:
            print("Error: initializing the printing tool")
            print(" %s" % e)
        if len(sys.argv) <= 1:
            dump_printers(get_printers())
            print("")
            dump_info(get_info())
            return 0
        printers = get_printers()
        if not printers:
            print("Cannot print: no printers found")
            return 1
        if len(sys.argv) == 2:
            filename = sys.argv[1]
            if not os.path.exists(filename):
                print("Cannot print file '%s': file does not exist" % filename)
                return 1
            printer = get_default_printer()
            if not printer:
                printer = printers.keys()[0]
                if len(printers) > 1:
                    print("More than one printer found: %s",
                          csv(printer.keys()))
            print("Using printer '%s'" % printer)
            filenames = [filename]
        if len(sys.argv) > 2:
            printer = sys.argv[1]
            if printer not in printers:
                print("Invalid printer '%s'" % printer)
                return 1
            filenames = sys.argv[2:]
            for filename in filenames:
                if not os.path.exists(filename):
                    print("File '%s' does not exist" % filename)
                    return 1
        print("Printing: %s" % csv(filenames))
        print_files(printer, filenames, "Print Command", {})
        return 0
예제 #4
0
파일: printing.py 프로젝트: svn2github/Xpra
def main():
    if "-v" in sys.argv or "--verbose" in sys.argv:
        from xpra.log import add_debug_category, enable_debug_for
        add_debug_category("printing")
        enable_debug_for("printing")
        try:
            sys.argv.remove("-v")
        except:
            pass
        try:
            sys.argv.remove("--verbose")
        except:
            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)
            dump_dict(v)
            attr = get_printer_attributes(k)
            if attr:
                print(" attributes:")
                for a in attr:
                    print("        %s" % a)
    from xpra.platform import program_context
    from xpra.log import enable_color
    from xpra.util import csv
    with program_context("Printing", "Printing"):
        enable_color()
        init_printing()
        if len(sys.argv)<=1:
            dump_printers(get_printers())
            dump_info(get_info())
            return 0
        printers = get_printers()
        if len(printers)==0:
            print("Cannot print: no printers found")
            return 1
        if len(sys.argv)==2:
            filename = sys.argv[1]
            if not os.path.exists(filename):
                print("Cannot print file '%s': file does not exist" % filename)
                return 1
            printer = get_default_printer()
            if not printer:
                printer = printers.keys()[0]
                if len(printers)>1:
                    print("More than one printer found: %s", csv(printer.keys()))
            print("Using printer '%s'" % printer)
            filenames = [filename]
        if len(sys.argv)>2:
            printer = sys.argv[1]
            if printer not in printers:
                print("Invalid printer '%s'" % printer)
                return 1
            filenames = sys.argv[2:]
            for filename in filenames:
                if not os.path.exists(filename):
                    print("File '%s' does not exist" % filename)
                    return 1
        print("Printing: %s" % csv(filenames))
        print_files(printer, filenames, "Print Command", {})
        return 0
예제 #5
0
def main():
    if "-v" in sys.argv or "--verbose" in sys.argv:
        from xpra.log import add_debug_category, enable_debug_for
        add_debug_category("printing")
        enable_debug_for("printing")
        try:
            sys.argv.remove("-v")
        except:
            pass
        try:
            sys.argv.remove("--verbose")
        except:
            pass

    from xpra.util import nonl, pver
    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)
            attr = get_printer_attributes(k)
            if attr:
                print(" attributes:")
                for a in attr:
                    print("        %s" % a)
    from xpra.platform import init, clean
    from xpra.log import enable_color
    from xpra.util import csv
    try:
        init("Printing", "Printing")
        enable_color()
        if len(sys.argv)<=1:
            dump_printers(get_printers())
            return 0
        printers = get_printers()
        if len(printers)==0:
            print("Cannot print: no printers found")
            return 1
        if len(sys.argv)==2:
            filename = sys.argv[1]
            if not os.path.exists(filename):
                print("Cannot print file '%s': file does not exist" % filename)
                return 1
            printer = get_default_printer()
            if not printer:
                printer = printers.keys()[0]
                if len(printers)>1:
                    print("More than one printer found: %s", csv(printer.keys()))
            print("Using printer '%s'" % printer)
            filenames = [filename]
        if len(sys.argv)>2:
            printer = sys.argv[1]
            if printer not in printers:
                print("Invalid printer '%s'" % printer)
                return 1
            filenames = sys.argv[2:]
            for filename in filenames:
                if not os.path.exists(filename):
                    print("File '%s' does not exist" % filename)
                    return 1
        print("Printing: %s" % csv(filenames))
        print_files(printer, filenames, "Print Command", {})
        return 0
    finally:
        clean()