Exemplo n.º 1
0
def _main(args):
    args.pop(0)

    queue = common.get_default_printer()
    argstyle = None
    try:
        # common.SYSTEMS is a canonical order of preference for
        # printing systems, and order matters to common.parse_args
        optinfos = [(s, opts[s]) for s in common.SYSTEMS]

        argstyle, options, arguments = common.parse_args(args, optinfos)

        # Find the last queue specified in the arguments
        queue_args, options = common.extract_opt(options, '-P')
        if queue_args:
            queue = queue_args[-1][-1]

        # Deal with zephyr notifications
        if os.environ.get('ATHENA_USER'):
            system = common.find_queue(queue)[0]
            if system == common.SYSTEM_CUPS:
                options.append(('-m', ''))

        # Now that we've sliced up the arguments, put them back
        # together
        args = [o + a for o, a in options] + arguments
    except ValueError:
        # parse_args returned None, so we learned nothing. We'll just
        # go with the default queue
        pass

    if not queue:
        # We tried and couldn't figure it out, so not our problem
        common.error(2, ("\n"
                         "No default printer configured. Specify a -P option, or configure a\n"
                         "default printer via e.g. System | Administration | Printing.\n"
                         "\n"))

    system, server, queue = common.find_queue(queue)

    if server == None and common.get_cups_uri(queue) == None:
        # if there's no Hesiod server and no local queue, 
        # tell the user they're wrong
        # But let it fall through in case the user is doing 
        # stupid things with -h 
        sys.stderr.write(("\nWARNING: The print queue '%s' does not appear to exist.\n"
                         "If you're trying to print to a cluster or dorm printer,\n"
                         "you should now be using the 'mitprint' queue instead.\n"
                         "See http://mit.edu/printing/pharos for more information.\n\n" % queue))

    args.insert(0, '-P%s' % queue)
    if os.environ.get('ATHENA_USER'):
        args.insert(0, '-U%s' % os.environ['ATHENA_USER'])
    if server:
        os.environ['CUPS_SERVER'] = server

    if system == common.SYSTEM_CUPS and 'LPROPT' in os.environ:
        sys.stderr.write("Use of the $LPROPT environment variable is deprecated and\nits contents will be ignored.\nSee http://kb.mit.edu/confluence/x/awCxAQ\n")

    common.dispatch_command(system, 'lpr', args)
Exemplo n.º 2
0
def simple(command, optinfo, queue_opt, args):
    args.pop(0)

    # Sigh.  CUPS' lprm, in its infinite wisdom, accepts '-' as a
    # specifier for 'all jobs', which doesn't work with any option
    # parsing code, ever.  However, CUPS does require that it be the
    # last argument, so check for it, and save it because parse_args
    # will kill it
    lprmdash = False
    if (command == "lprm") and len(args) and (args[-1] == "-"):
        lprmdash = True

    queue = common.get_default_printer()
    try:
        argstyle, options, arguments = common.parse_args(args, optinfo)

        # Find the last queue specified in the arguments
        queue_args, options = common.extract_opt(options, queue_opt)
        if queue_args:
            queue = queue_args[-1][-1]

        # Now that we've sliced up the arguments, put them back
        # together
        args = [o + a for o, a in options] + arguments

    except ValueError:
        # parse_args returned None, so we learned nothing. We'll just
        # go with the default queue
        pass

    if not queue:
        # We tried and couldn't figure it out, so not our problem
        common.error(
            2,
            (
                "\n"
                "No default printer configured. Specify a %s option, or configure a\n"
                "default printer via e.g. System | Administration | Printing.\n"
                "\n" % queue_opt
            ),
        )

    system, server, queue = common.find_queue(queue)

    args.insert(0, "%s%s" % (queue_opt, queue))
    if server:
        os.environ["CUPS_SERVER"] = server

    # And now add it back (see above)
    if lprmdash and (system == common.SYSTEM_CUPS):
        args.append("-")

    common.dispatch_command(system, command, args)
Exemplo n.º 3
0
def simple(command, optinfo, queue_opt, args):
    args.pop(0)

    # Sigh.  CUPS' lprm, in its infinite wisdom, accepts '-' as a
    # specifier for 'all jobs', which doesn't work with any option
    # parsing code, ever.  However, CUPS does require that it be the
    # last argument, so check for it, and save it because parse_args
    # will kill it
    lprmdash = False
    if (command == 'lprm') and len(args) and (args[-1] == '-'):
        lprmdash = True

    queue = common.get_default_printer()
    try:
        argstyle, options, arguments = common.parse_args(args, optinfo)

        # Find the last queue specified in the arguments
        queue_args, options = common.extract_opt(options, queue_opt)
        if queue_args:
            queue = queue_args[-1][-1]

        # Now that we've sliced up the arguments, put them back
        # together
        args = [o + a for o, a in options] + arguments

    except ValueError:
        # parse_args returned None, so we learned nothing. We'll just
        # go with the default queue
        pass

    if not queue:
        # We tried and couldn't figure it out, so not our problem
        common.error(2, (
            "\n"
            "No default printer configured. Specify a %s option, or configure a\n"
            "default printer via e.g. System | Administration | Printing.\n"
            "\n" % queue_opt))

    system, server, queue = common.find_queue(queue)

    args.insert(0, '%s%s' % (queue_opt, queue))
    if server:
        os.environ['CUPS_SERVER'] = server

    # And now add it back (see above)
    if lprmdash and (system == common.SYSTEM_CUPS):
        args.append('-')

    common.dispatch_command(system, command, args)
Exemplo n.º 4
0
def _main(args):
    args.pop(0)

    queue = common.get_default_printer()
    try:
        argstyle, options, arguments = common.parse_args(args, opts)

        # Find the last queue specified in the arguments
        queue_args, options = common.extract_opt(options, queue_opt)
        if queue_args:
            queue = queue_args[-1][-1]

        # Now that we've sliced up the arguments, put them back
        # together
        args = [o + a for o, a in options] + arguments
    except ValueError:
        # parse_args returned None, so we learned nothing. We'll just
        # go with the default queue
        pass

    if not queue:
        # We tried and couldn't figure it out, so not our problem
        common.error(2, ("\n"
                         "No default printer configured. Specify a %s option, or configure a\n"
                         "default printer via e.g. System | Administration | Printing.\n"
                         "\n" % queue_opt))

    system, server, queue = common.find_queue(queue)

    if server == None and common.get_cups_uri(queue) == None:
        # if there's no Hesiod server and no local queue, 
        # tell the user they're wrong
        # But let it fall through in case the user is doing 
        # stupid things with -h 
        sys.stderr.write(("\nWARNING: The print queue '%s' does not appear to exist.\n"
                         "If you're trying to print to a cluster or dorm printer,\n"
                         "you should now be using the 'mitprint' queue instead.\n"
                         "See http://mit.edu/printing/pharos for more information.\n\n" % queue))

    if server and system == common.SYSTEM_CUPS and args == []:
        # CUPS clients before 1.4 and CUPS servers at least 1.4 don't
        # communicate well about lpq stuff, so just implement RFC 1179 lpq
        # ourselves since that works
        # Also, a hack to continue to support "lpq -Pbw" until we have
        # a better solution for querying the CUPS queue
        if cups_version_is_below_1_4() or (server == 'PHAROS-PRODP1.MIT.EDU'):
            try:
                s = socket.socket()
                s.settimeout(10)
                s.connect((server, 515))
                s.send("\x03" + queue + "\n")
                print s.makefile().read()
                return 0
            except (socket.error, socket.timeout):
                # Oh well.
                pass
        
    args.insert(0, '%s%s' % (queue_opt, queue))
    if server:
        os.environ['CUPS_SERVER'] = server

    common.dispatch_command(system, 'lpq', args)
Exemplo n.º 5
0
def _main(args):
    args.pop(0)

    queue = common.get_default_printer()
    try:
        argstyle, options, arguments = common.parse_args(args, opts)

        # Find the last queue specified in the arguments
        queue_args, options = common.extract_opt(options, queue_opt)
        if queue_args:
            queue = queue_args[-1][-1]

        # Now that we've sliced up the arguments, put them back
        # together
        args = [o + a for o, a in options] + arguments
    except ValueError:
        # parse_args returned None, so we learned nothing. We'll just
        # go with the default queue
        pass

    if not queue:
        # We tried and couldn't figure it out, so not our problem
        common.error(2, (
            "\n"
            "No default printer configured. Specify a %s option, or configure a\n"
            "default printer via e.g. System | Administration | Printing.\n"
            "\n" % queue_opt))

    system, server, queue = common.find_queue(queue)

    if server == None and common.get_cups_uri(queue) == None:
        # if there's no Hesiod server and no local queue,
        # tell the user they're wrong
        # But let it fall through in case the user is doing
        # stupid things with -h
        sys.stderr.write(
            ("\nWARNING: The print queue '%s' does not appear to exist.\n"
             "If you're trying to print to a cluster or dorm printer,\n"
             "you should now be using the 'mitprint' queue instead.\n"
             "See http://mit.edu/printing/pharos for more information.\n\n" %
             queue))

    if server and system == common.SYSTEM_CUPS and args == []:
        # CUPS clients before 1.4 and CUPS servers at least 1.4 don't
        # communicate well about lpq stuff, so just implement RFC 1179 lpq
        # ourselves since that works
        # Also, a hack to continue to support "lpq -Pbw" until we have
        # a better solution for querying the CUPS queue
        if cups_version_is_below_1_4() or (server == 'PHAROS-PRODP1.MIT.EDU'):
            try:
                s = socket.socket()
                s.settimeout(10)
                s.connect((server, 515))
                s.send("\x03" + queue + "\n")
                print s.makefile().read()
                return 0
            except (socket.error, socket.timeout):
                # Oh well.
                pass

    args.insert(0, '%s%s' % (queue_opt, queue))
    if server:
        os.environ['CUPS_SERVER'] = server

    common.dispatch_command(system, 'lpq', args)