Ejemplo 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)
Ejemplo n.º 2
0
    def test(self):
        """Test printing with LPROPT unset.

        Taken from Trac #509, reported on Mar 12, 2010."""
        # We now call common.find_queue twice
        common._hesiod_lookup('ajax', 'pcap').AndReturn(['ajax:rp=ajax:rm=GET-PRINT.MIT.EDU:ka#0:mc#0:'])
        common.get_default_printer().AndReturn(None)
        common.get_cups_uri('ajax').AndReturn(None)
        # We no longer call "is_cups_server"
        # common.is_cups_server('GET-PRINT.MIT.EDU').AndReturn(True)
        common._hesiod_lookup('ajax', 'pcap').AndReturn(['ajax:rp=ajax:rm=GET-PRINT.MIT.EDU:ka#0:mc#0:'])
        common.get_cups_uri('ajax').AndReturn(None)
        # We no longer call "is_cups_server"
        # common.is_cups_server('GET-PRINT.MIT.EDU').AndReturn(True)

        # Result:
        os.execvp('cups-lpr', ['lpr', '-Ujdreed', '-Pajax', '-m'])

        self.mox.ReplayAll()

        lpr._main(['lpr', '-P', 'ajax'])
Ejemplo n.º 3
0
    def test(self):
        """Test printing with LPROPT unset.

        Taken from Trac #509, reported on Mar 12, 2010."""
        # We now call common.find_queue twice
        common._hesiod_lookup('ajax', 'pcap').AndReturn(
            ['ajax:rp=ajax:rm=GET-PRINT.MIT.EDU:ka#0:mc#0:'])
        common.get_default_printer().AndReturn(None)
        common.get_cups_uri('ajax').AndReturn(None)
        # We no longer call "is_cups_server"
        # common.is_cups_server('GET-PRINT.MIT.EDU').AndReturn(True)
        common._hesiod_lookup('ajax', 'pcap').AndReturn(
            ['ajax:rp=ajax:rm=GET-PRINT.MIT.EDU:ka#0:mc#0:'])
        common.get_cups_uri('ajax').AndReturn(None)
        # We no longer call "is_cups_server"
        # common.is_cups_server('GET-PRINT.MIT.EDU').AndReturn(True)

        # Result:
        os.execvp('cups-lpr', ['lpr', '-Ujdreed', '-Pajax', '-m'])

        self.mox.ReplayAll()

        lpr._main(['lpr', '-P', 'ajax'])
Ejemplo n.º 4
0
    def test(self):
        """Test printing to a printer that is not in Hesiod.

        Taken from -c debathena, reported by quentin on May 14, 2010."""
        # We now call common.find_queue twice
        common._hesiod_lookup('stark', 'pcap').AndReturn([])
        common.get_cups_uri('stark').AndReturn(None)
        common.get_default_printer().AndReturn(None)
        common._hesiod_lookup('stark', 'pcap').AndReturn([])
        common.get_cups_uri('stark').AndReturn(None)
        common.get_cups_uri('stark').AndReturn(None)

        # Result:
        os.execvp('cups-lpr', ['lpr', '-Uquentin', '-Pstark', '-m', 'puppies biting nose.jpg'])

        self.mox.ReplayAll()

        lpr._main(['lpr', '-Pstark', 'puppies biting nose.jpg'])
Ejemplo n.º 5
0
    def test(self):
        """Test printing to a printer that is not in Hesiod.

        Taken from -c debathena, reported by quentin on May 14, 2010."""
        # We now call common.find_queue twice
        common._hesiod_lookup('stark', 'pcap').AndReturn([])
        common.get_cups_uri('stark').AndReturn(None)
        common.get_default_printer().AndReturn(None)
        common._hesiod_lookup('stark', 'pcap').AndReturn([])
        common.get_cups_uri('stark').AndReturn(None)
        common.get_cups_uri('stark').AndReturn(None)

        # Result:
        os.execvp(
            'cups-lpr',
            ['lpr', '-Uquentin', '-Pstark', '-m', 'puppies biting nose.jpg'])

        self.mox.ReplayAll()

        lpr._main(['lpr', '-Pstark', 'puppies biting nose.jpg'])
Ejemplo n.º 6
0
 def test_local_only_name(self):
     """Test canonicalize_queue on a local-only queue"""
     common.get_cups_uri('patience').AndReturn('mdns://patience._printer._tcp.local.')
     self.mox.ReplayAll()
     self.assertEqual(common.canonicalize_queue('patience'),
                      None)
Ejemplo n.º 7
0
 def test_non_local_queue(self):
     """Test canonicalize_queue with a non-local queue name"""
     common.get_cups_uri('python').AndReturn(None)
     self.mox.ReplayAll()
     self.assertEqual(common.canonicalize_queue('python'),
                      'python')
Ejemplo n.º 8
0
 def test_valid_class(self):
     """Test a locally configured bounce queue to an Athena class"""
     common.get_cups_uri('ajax2').AndReturn('ipp://cluster-printers.mit.edu:631/classes/ajax2')
     self.mox.ReplayAll()
     self.assertEqual(common.canonicalize_queue('ajax2'),
                      'ajax2')
Ejemplo n.º 9
0
 def test_misnamed_valid_printer(self):
     """Test a local bounce queue with a different name from the Athena queue"""
     common.get_cups_uri('w20').AndReturn('ipp://cluster-printers.mit.edu:631/printers/ajax')
     self.mox.ReplayAll()
     self.assertEqual(common.canonicalize_queue('w20'),
                      'ajax')
Ejemplo n.º 10
0
 def test_invalid_queue_uri(self):
     """Test canonicalize_queue with a URL we don't understand"""
     common.get_cups_uri('screwedup').AndReturn('ipp://PRINTERS.MIT.EDU/stuff/screwedup')
     self.mox.ReplayAll()
     self.assertEqual(common.canonicalize_queue('screwedup'),
                      None)
Ejemplo n.º 11
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)
Ejemplo n.º 12
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)