logserverice initialised, fixed typos

This commit is contained in:
age 2006-08-20 08:16:45 +00:00
parent 4bcd42d615
commit eaed2ffb9d
3 changed files with 47 additions and 12 deletions

View file

@ -7,15 +7,17 @@ progress. So things might be confusing here. Hopefully not for long.
:) :)
''' '''
import logging
import CryptoBoxLogger import CryptoBoxLogger
import CryptoBoxContainer import CryptoBoxContainer
try:
import configobj # to read and write the config file
except:
print "Could not load configobj module! Try apt-get install python-configobj."
import re import re
import os import os
import sys import sys
try:
import configobj ## needed for reading and writing the config file
except:
print("Could't import 'configobj'! Try apt-get install python-configobj.")
sys.exit()
import types import types
import unittest import unittest
@ -40,19 +42,21 @@ class CryptoBoxProps:
#if os.geteuid() != 0: #if os.geteuid() != 0:
# sys.stderr.write("You need to be root to run this program!\n") # sys.stderr.write("You need to be root to run this program!\n")
# sys.exit(1) # sys.exit(1)
self.initLogging()
if conf_file == None: if conf_file == None:
for f in CONF_LOCATIONS: for f in CONF_LOCATIONS:
if os.path.exists(os.path.expanduser(f)): if os.path.exists(os.path.expanduser(f)):
conf_file = os.path.expanduser(f) conf_file = os.path.expanduser(f)
break break
else: else:
sys.stderr.write("Could not find a configuration file. I give up.\n") #sys.stderr.write("Could not find a configuration file. I give up.\n")
self.log.error("Could not find a configuration file. I give up.\n")
sys.exit(1) sys.exit(1)
try: try:
self.cbxPrefs = configobj.ConfigObj(conf_file) self.cbxPrefs = configobj.ConfigObj(conf_file)
except SyntaxError: except SyntaxError:
sys.stderr.write("Error during parsing of configuration file (%s).\n" % (conf_file, )) #sys.stderr.write("Error during parsing of configuration file (%s).\n" % (conf_file, ))
sys.exit(1) self.log.error("Could not find a configuration file. I give up.\n")
try: try:
nameDB_file = os.path.join( nameDB_file = os.path.join(
self.cbxPrefs["Main"]["DataDir"], self.cbxPrefs["Main"]["DataDir"],
@ -62,7 +66,8 @@ class CryptoBoxProps:
else: else:
self.nameDB = configobj.ConfigObj(nameDB_file, create_empty=True) self.nameDB = configobj.ConfigObj(nameDB_file, create_empty=True)
except SyntaxError: except SyntaxError:
sys.stderr.write("Error during parsing of name database file (%s).\n" % (nameDB_file, )) #sys.stderr.write("Error during parsing of name database file (%s).\n" % (nameDB_file, ))
self.log.error("Error during parsing of name database file (%s).\n" % (nameDB_file, ))
sys.exit(1) sys.exit(1)
self.__cboxUID = int(self.cbxPrefs["System"]["User"]) self.__cboxUID = int(self.cbxPrefs["System"]["User"])
self.__cboxGID = int(self.cbxPrefs["System"]["Group"]) self.__cboxGID = int(self.cbxPrefs["System"]["Group"])
@ -78,6 +83,20 @@ class CryptoBoxProps:
self.containers.append(CryptoBoxContainer.CryptoBoxContainer(device, self)) self.containers.append(CryptoBoxContainer.CryptoBoxContainer(device, self))
def initLogging(self):
'''initialises the logging system
use it with:
'self.log.[debug|info|warning|error|critical](logmessage)'''
## basicConfig(...) needs python >= 2.4
logging.basicConfig(level=logging.DEBUG,
format='%(asctime)s %(module)s %(levelname)s %(message)s',
#TODO: read the logfile from the config
filename='./cryptobox.log',
filemode='w')
self.log = logging.getLogger("CryptoBoxProps")
self.log.info("loggingsystem is up'n running")
def isDeviceAllowed(self, devicename): def isDeviceAllowed(self, devicename):
"check if a device is white-listed for being used as cryptobox containers" "check if a device is white-listed for being used as cryptobox containers"
"TODO: broken!" "TODO: broken!"
@ -277,12 +296,12 @@ Destination = /tmp/cryptobox.log
""" """
def setUp(self): def setUp(self):
if not os.path.exists(tmpdir): os.mkdir(tmpdir) if not os.path.exists(self.tmpdir): os.mkdir(self.tmpdir)
filehandling.write_file(self.configFile,self.configContent) self.filehandling.write_file(self.configFile,self.configContent)
def tearDown(self): def tearDown(self):
if os.path.exists(tmpdir): os.rmdir(tmpdir) if os.path.exists(self.tmpdir): os.rmdir(self.tmpdir)
if os.path.exists(self.configFile): os.remove(self.configFile) if os.path.exists(self.configFile): os.remove(self.configFile)
if os.path.exists(self.logFile): os.remove(self.logFile) if os.path.exists(self.logFile): os.remove(self.logFile)
if os.path.exists(self.nameDBFile): os.remove(self.nameDBFile) if os.path.exists(self.nameDBFile): os.remove(self.nameDBFile)

View file

@ -1,5 +1,8 @@
from CryptoBoxLogger import CryptoBoxLogger from CryptoBoxLogger import CryptoBoxLogger
import subprocess try:
import subprocess
except:
print "Couldn't import 'subprocess'. You need a python version >= 2.4"
import os import os
import re import re

View file

@ -12,6 +12,18 @@ except:
print "could not import clearsilver modules! Try apt-get install python-clearsilver." print "could not import clearsilver modules! Try apt-get install python-clearsilver."
<<<<<<< .mine
class RunCmd:
def index(self):
hdf = neo_util.HDF()
#hdf.setValue("hdf.loadpaths.0","/my/path")
hdf.readFile("../lang/de.hdf")
hdf.setValue("Settings.TemplateDir","../templates")
hdf.setValue("Settings.Stylesheet","cryptobox.css")
hdf.setValue("Data.Action","show_status")
cs = neo_cs.CS(hdf)
cs.parseFile("../templates/main.cs")
=======
class clearsilver: class clearsilver:
def __init__(self): def __init__(self):
pass pass
@ -33,6 +45,7 @@ class clearsilver:
hdf.setValue(key,str(settings[key])) hdf.setValue(key,str(settings[key]))
cs= neo_cs.CS(hdf) cs= neo_cs.CS(hdf)
cs.parseFile(cs_path) cs.parseFile(cs_path)
>>>>>>> .r387
return cs.render() return cs.render()