def __init__( self, lang="", charset=None, doc="PyKota v%(__version__)s (c) %(__years__)s %(__author__)s"): """Initializes the command line tool.""" self.debug = True # in case of early failure self.logger = logger.openLogger("stderr") # did we drop priviledges ? self.privdropped = 0 # locale stuff try: locale.setlocale(locale.LC_ALL, (lang, charset)) except (locale.Error, IOError): locale.setlocale(locale.LC_ALL, None) (self.language, self.charset) = locale.getlocale() self.language = self.language or "C" try: self.charset = self.charset or locale.getpreferredencoding() except locale.Error: self.charset = sys.getfilesystemencoding() # Dirty hack : if the charset is ASCII, we can safely use UTF-8 instead # This has the advantage of allowing transparent support for recent # versions of CUPS which (en-)force charset to UTF-8 when printing. # This should be needed only when printing, but is probably (?) safe # to do when using interactive commands. if self.charset.upper() in ('ASCII', 'ANSI_X3.4-1968'): self.charset = "UTF-8" # translation stuff try: try: trans = gettext.translation( "pykota", languages=["%s.%s" % (self.language, self.charset)], codeset=self.charset) except TypeError: # Python <2.4 trans = gettext.translation( "pykota", languages=["%s.%s" % (self.language, self.charset)]) trans.install() except: gettext.NullTranslations().install() # pykota specific stuff self.documentation = doc
def deferredInit(self): """Deferred initialization.""" confdir = os.environ.get("PYKOTA_HOME") environHome = True missingUser = False if confdir is None: environHome = False # check for config files in the 'pykota' user's home directory. try: self.pykotauser = pwd.getpwnam("pykota") confdir = self.pykotauser[5] except KeyError: self.pykotauser = None confdir = "/etc/pykota" missingUser = True self.config = config.PyKotaConfig(confdir) self.debug = self.config.getDebug() self.smtpserver = self.config.getSMTPServer() self.maildomain = self.config.getMailDomain() self.logger = logger.openLogger(self.config.getLoggingBackend()) # now drop priviledge if possible self.dropPriv() # We NEED this here, even when not in an accounting filter/backend self.softwareJobSize = 0 self.softwareJobPrice = 0.0 if environHome: self.printInfo( "PYKOTA_HOME environment variable is set. Configuration files were searched in %s" % confdir, "info") else: if missingUser: self.printInfo( "The 'pykota' system account is missing. Configuration files were searched in %s instead." % confdir, "warn") self.logdebug("Language in use : %s" % self.language) self.logdebug("Charset in use : %s" % self.charset) arguments = " ".join(['"%s"' % arg for arg in sys.argv]) self.logdebug("Command line arguments : %s" % arguments)
def __init__(self, lang="", charset=None, doc="PyKota v%(__version__)s (c) %(__years__)s %(__author__)s") : """Initializes the command line tool.""" self.debug = True # in case of early failure self.logger = logger.openLogger("stderr") # did we drop priviledges ? self.privdropped = 0 # locale stuff try : locale.setlocale(locale.LC_ALL, (lang, charset)) except (locale.Error, IOError) : locale.setlocale(locale.LC_ALL, None) (self.language, self.charset) = locale.getlocale() self.language = self.language or "C" try : self.charset = self.charset or locale.getpreferredencoding() except locale.Error : self.charset = sys.getfilesystemencoding() # Dirty hack : if the charset is ASCII, we can safely use UTF-8 instead # This has the advantage of allowing transparent support for recent # versions of CUPS which (en-)force charset to UTF-8 when printing. # This should be needed only when printing, but is probably (?) safe # to do when using interactive commands. if self.charset.upper() in ('ASCII', 'ANSI_X3.4-1968') : self.charset = "UTF-8" # translation stuff try : try : trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)], codeset=self.charset) except TypeError : # Python <2.4 trans = gettext.translation("pykota", languages=["%s.%s" % (self.language, self.charset)]) trans.install() except : gettext.NullTranslations().install() # pykota specific stuff self.documentation = doc
def deferredInit(self) : """Deferred initialization.""" confdir = os.environ.get("PYKOTA_HOME") environHome = True missingUser = False if confdir is None : environHome = False # check for config files in the 'pykota' user's home directory. try : self.pykotauser = pwd.getpwnam("pykota") confdir = self.pykotauser[5] except KeyError : self.pykotauser = None confdir = "/etc/pykota" missingUser = True self.config = config.PyKotaConfig(confdir) self.debug = self.config.getDebug() self.smtpserver = self.config.getSMTPServer() self.maildomain = self.config.getMailDomain() self.logger = logger.openLogger(self.config.getLoggingBackend()) # now drop priviledge if possible self.dropPriv() # We NEED this here, even when not in an accounting filter/backend self.softwareJobSize = 0 self.softwareJobPrice = 0.0 if environHome : self.printInfo("PYKOTA_HOME environment variable is set. Configuration files were searched in %s" % confdir, "info") else : if missingUser : self.printInfo("The 'pykota' system account is missing. Configuration files were searched in %s instead." % confdir, "warn") self.logdebug("Language in use : %s" % self.language) self.logdebug("Charset in use : %s" % self.charset) arguments = " ".join(['"%s"' % arg for arg in sys.argv]) self.logdebug("Command line arguments : %s" % arguments)
def __init__(self, doc="PyKota v%(__version__)s (c) %(__years__)s %(__author__)s") : """Initializes the command line tool.""" self.debug = True # in case of early failure self.logger = logger.openLogger("stderr") # Saves a copy of the locale settings (self.language, self.charset) = locale.getlocale() if not self.language : self.language = "C" if not self.charset : self.charset = "UTF-8" # pykota specific stuff self.documentation = doc # Extract the effective username uid = os.geteuid() try : self.effectiveUserName = pwd.getpwuid(uid)[0] except (KeyError, IndexError), msg : self.printInfo(_("Strange problem with uid(%s) : %s") % (uid, msg), "warn") self.effectiveUserName = os.getlogin()