[Thinlinc-technical] Klara sig utan nearest/Manage without nearest

Johan Dahl johan.dahl at sol.lu.se
Thu Oct 2 13:19:20 CEST 2008


[swedish]
Vi fick problem med att använda nearest skrivaren. När den var inställd
på en generell pstscriptdrivrutin så fick vi oönskade färgutskrifter.
När vi ställde in  drivrutinenen för den skrivare som användes mest så
fick vi oönskade multipla kopior vi utskrift av flera exemplar. Jag
löste det hela genom att skapa ett kommando som läser i nearest hive och
byter till rätt skrivare. Programmet bör sedan anropas vid inloggning
eller i 2.10 vid åternaslutning till sessionen.

[english]
The program finds the printer which is set for a terminal or a location 
of a terminal and sets it as the default printer. We had problems using
nearest so this is a workaround. Run the program in login script or on 
reconnecting in 2.10


---------------changeDefaultPrinter-------------------------------------------------
#!/usr/bin/python
# -*-mode: python; coding: UTF-8 -*-
# Read printer set for terminal in thinlinc hive
# Set it as default printer
# Johan Dahl 2008
import sys
sys.path = [ "/opt/thinlinc/modules" ] + sys.path
import os
import hiveconf

# Get hardware adress
p = os.popen("/opt/thinlinc/bin/tl-session-param /client_params/hwaddr
2> /dev/null")
hwaddr = p.read().strip()
p.close()

if hwaddr == "":
    print >>sys.stderr, "Hwaddr not found for client"
    sys.exit(1)

# Put colons inside and change to uppercase
hwaddr = "%s:%s:%s:%s:%s:%s" % (
    hwaddr[0:2], hwaddr[2:4], hwaddr[4:6], hwaddr[6:8], hwaddr[8:10],
hwaddr[10:12])
hwaddr = hwaddr.upper()



defaultPrinter = ""

# Open hive with nearest information
nearestRoot = hiveconf.open_hive ( "/opt/thinlinc/etc/conf.d/nearest.hconf")

printers =
nearestRoot.get_string("/printing/nearest/terminals/%s/printers" % hwaddr)

if printers == None:
    print >>sys.stderr, "Hwaddr %s not found in nearest.hconf" % hwaddr
    sys.exit(1)

if printers != "":
    defaultPrinter = printers
else:
    location =
nearestRoot.get_string("/printing/nearest/terminals/%s/location" % hwaddr)
    locationPrinters =
nearestRoot.get_string("/printing/nearest/locations/%s/printers" % location)
    if locationPrinters != "":
        defaultPrinter = locationPrinters
    else:
        print >>sys.stderr, "No printer found for location %s" % location
        sys.exit(1)

if defaultPrinter != "":
    result = os.system("/usr/bin/lpoptions -d %s" % locationPrinters)
    if result != 0:
        print >>sys.stderr, "Couldn't set %s as default printer [error =
%d]" % (defaultPrinter, result)
        sys.exit(1)
    else:
        print >>sys.stderr, "Set %s as default printer" % defaultPrinter

---------------changeDefaultPrinter-------------------------------------------------





Tänk på att python inte brukar gilla att bli mejlade. Det kan bli
problem med syntax-indragningarna

-- 
Johan Dahl, System Administrator
Centre for Languages and Literature
Lund University
Address: Box 201, 221 00 Lund, SWEDEN
Delivery address: Finngatan 1, 223 62 Lund, SWEDEN
Visiting address: Helgonabacken 12, 223 62 Lund, SWEDEN
Tel: +46-(0)46-2223226 Fax: +46-(0)46-2224210 Mob: 070-35 45 707
mailto:Johan.Dahl at sol.lu.se

"All science is either physics or stamp collecting." - Ernest Rutherford





More information about the Thinlinc-technical mailing list