started to implement logTools properly
git-svn-id: http://svn.sabayonlinux.org/projects/entropy/trunk@304 cd1c1023-2f26-0410-ae45-c471fc1f0318
This commit is contained in:
@@ -1,5 +1,11 @@
|
||||
TODO list (for developers only):
|
||||
- implement logTools inside handlers
|
||||
- databaseTools
|
||||
- entropyTools
|
||||
- activatorTools
|
||||
- reagentTools
|
||||
- mirrorTools
|
||||
- portageTools
|
||||
- enzyme: add stronger support to broken packages check
|
||||
- reagent: complete smartapps section
|
||||
- enzyme, reagent: test kernel dependent packages
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
# Project Entropy 1.0 Entropy configuration file
|
||||
|
||||
# Log level
|
||||
# 0: No Logging
|
||||
# 1: Normal Logging
|
||||
# 2: Verbose Logging
|
||||
loglevel|1
|
||||
|
||||
@@ -35,7 +35,7 @@ import time
|
||||
|
||||
# Logging initialization
|
||||
import logTools
|
||||
activatorLog = logTools.LogFile(level=etpConst['activatorloglevel'],filename = etpConst['activatorlogfile'])
|
||||
activatorLog = logTools.LogFile(level=etpConst['activatorloglevel'],filename = etpConst['activatorlogfile'], header = "[Activator]")
|
||||
|
||||
def sync(options, justTidy = False):
|
||||
|
||||
|
||||
+26
-12
@@ -36,7 +36,7 @@ import string
|
||||
|
||||
# Logging initialization
|
||||
import logTools
|
||||
dbLog = logTools.LogFile(level=etpConst['databaseloglevel'],filename = etpConst['databaselogfile'])
|
||||
dbLog = logTools.LogFile(level = etpConst['databaseloglevel'],filename = etpConst['databaselogfile'], header = "[DBase]")
|
||||
|
||||
|
||||
# TIP OF THE DAY:
|
||||
@@ -51,7 +51,6 @@ def database(options):
|
||||
|
||||
# do some check, print some warnings
|
||||
print_info(green(" * ")+red("Initializing Entropy database..."), back = True)
|
||||
dbLog.log(0,"[DB OP] Called database --initialize")
|
||||
# database file: etpConst['etpdatabasefilepath']
|
||||
if os.path.isfile(etpConst['etpdatabasefilepath']):
|
||||
print_info(red(" * ")+bold("WARNING")+red(": database file already exists. Overwriting."))
|
||||
@@ -59,15 +58,12 @@ def database(options):
|
||||
if rc == "No":
|
||||
sys.exit(0)
|
||||
os.system("rm -f "+etpConst['etpdatabasefilepath'])
|
||||
dbLog.log(0,"[DB OP] Removed old database file")
|
||||
|
||||
# initialize the database
|
||||
dbLog.log(0,"[DB OP] Connecting to the database")
|
||||
dbconn = etpDatabase(readOnly = False, noUpload = True)
|
||||
dbconn.initializeDatabase()
|
||||
|
||||
# sync packages directory
|
||||
dbLog.log(0,"Syncing binary packages")
|
||||
import activatorTools
|
||||
activatorTools.packages(["sync","--ask"])
|
||||
|
||||
@@ -75,24 +71,18 @@ def database(options):
|
||||
pkglist = os.listdir(etpConst['packagesbindir'])
|
||||
|
||||
print_info(green(" * ")+red("Reinitializing Entropy database using Packages in the repository ..."))
|
||||
dbLog.log(0,"[DB OP] Preparing to start reinitialization")
|
||||
currCounter = 0
|
||||
atomsnumber = len(pkglist)
|
||||
import reagentTools
|
||||
for pkg in pkglist:
|
||||
dbLog.log(0,"[DB OP] Analyzing "+str(pkg))
|
||||
print_info(green(" * ")+red("Analyzing: ")+bold(pkg), back = True)
|
||||
currCounter += 1
|
||||
print_info(green(" (")+ blue(str(currCounter))+"/"+red(str(atomsnumber))+green(") ")+red("Analyzing ")+bold(pkg)+red(" ..."))
|
||||
etpData = reagentTools.extractPkgData(etpConst['packagesbindir']+"/"+pkg)
|
||||
dbLog.log(3,"[DB OP] etpData status (should be properly filled now):")
|
||||
for i in etpData:
|
||||
dbLog.log(3,i+": "+etpData[i])
|
||||
|
||||
# remove shait
|
||||
os.system("rm -rf "+etpConst['packagestmpdir']+"/"+pkg)
|
||||
# fill the db entry
|
||||
dbLog.log(0,"[DB OP] Launching etpDatabase.addPackage()")
|
||||
dbconn.addPackage(etpData)
|
||||
dbconn.commitChanges()
|
||||
|
||||
@@ -669,6 +659,9 @@ def database(options):
|
||||
class databaseStatus:
|
||||
|
||||
def __init__(self):
|
||||
|
||||
dbLog.log(ETP_LOG_VERBOSE,"DatabaseStatus.__init__ called.")
|
||||
|
||||
self.databaseBumped = False
|
||||
self.databaseInfoCached = False
|
||||
self.databaseLock = False
|
||||
@@ -677,52 +670,67 @@ class databaseStatus:
|
||||
self.databaseAlreadyTainted = False
|
||||
|
||||
if os.path.isfile(etpConst['etpdatabasedir']+"/"+etpConst['etpdatabasetaintfile']):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"DatabaseStatus: database tainted.")
|
||||
self.databaseAlreadyTainted = True
|
||||
|
||||
def isDatabaseAlreadyBumped(self):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"DatabaseStatus: already bumped? "+str(self.databaseBumped))
|
||||
return self.databaseBumped
|
||||
|
||||
def isDatabaseAlreadyTainted(self):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"DatabaseStatus: tainted? "+str(self.databaseAlreadyTainted))
|
||||
return self.databaseAlreadyTainted
|
||||
|
||||
def setDatabaseTaint(self,bool):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"DatabaseStatus: setting database taint to: "+str(bool))
|
||||
self.databaseAlreadyTainted = bool
|
||||
|
||||
def setDatabaseBump(self,bool):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"DatabaseStatus: setting database bump to: "+str(bool))
|
||||
self.databaseBumped = bool
|
||||
|
||||
def setDatabaseLock(self):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"DatabaseStatus: Locking database (upload)")
|
||||
self.databaseLock = True
|
||||
|
||||
def unsetDatabaseLock(self):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"DatabaseStatus: Unlocking database (upload)")
|
||||
self.databaseLock = False
|
||||
|
||||
def getDatabaseLock(self):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"DatabaseStatus: getting database lock info (upload), status: "+str(self.databaseLock))
|
||||
return self.databaseLock
|
||||
|
||||
def setDatabaseDownloadLock(self):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"DatabaseStatus: Locking database (download)")
|
||||
self.databaseDownloadLock = True
|
||||
|
||||
def unsetDatabaseDownloadLock(self):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"DatabaseStatus: Unlocking database (download)")
|
||||
self.databaseDownloadLock = False
|
||||
|
||||
def getDatabaseDownloadLock(self):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"DatabaseStatus: getting database lock info (download), status: "+str(self.databaseDownloadLock))
|
||||
return self.databaseDownloadLock
|
||||
|
||||
class etpDatabase:
|
||||
|
||||
def __init__(self, readOnly = False, noUpload = False):
|
||||
|
||||
dbLog.log(ETP_LOG_VERBOSE,"etpDatabase.__init__ called.")
|
||||
|
||||
self.readOnly = readOnly
|
||||
self.noUpload = noUpload
|
||||
|
||||
if (self.readOnly):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"etpDatabase: database opened readonly")
|
||||
# if the database is opened readonly, we don't need to lock the online status
|
||||
# FIXME: add code for locking the table
|
||||
self.connection = sqlite.connect(etpConst['etpdatabasefilepath'])
|
||||
self.cursor = self.connection.cursor()
|
||||
# set the table read only
|
||||
return
|
||||
|
||||
dbLog.log(ETP_LOG_VERBOSE,"etpDatabase: database opened in read/write mode")
|
||||
|
||||
# check if the database is locked locally
|
||||
if os.path.isfile(etpConst['etpdatabasedir']+"/"+etpConst['etpdatabaselockfile']):
|
||||
@@ -780,11 +788,14 @@ class etpDatabase:
|
||||
|
||||
# if the class is opened readOnly, close and forget
|
||||
if (self.readOnly):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"closeDB: closing database opened in readonly.")
|
||||
#self.connection.rollback()
|
||||
self.cursor.close()
|
||||
self.connection.close()
|
||||
return
|
||||
|
||||
dbLog.log(ETP_LOG_VERBOSE,"closeDB: closing database opened in read/write.")
|
||||
|
||||
# FIXME verify all this shit, for now it works...
|
||||
if (entropyTools.dbStatus.isDatabaseAlreadyTainted()) and (not entropyTools.dbStatus.isDatabaseAlreadyBumped()):
|
||||
# bump revision, setting DatabaseBump causes the session to just bump once
|
||||
@@ -802,12 +813,15 @@ class etpDatabase:
|
||||
|
||||
def commitChanges(self):
|
||||
if (not self.readOnly):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"commitChanges: writing changes to database.")
|
||||
self.connection.commit()
|
||||
self.taintDatabase()
|
||||
else:
|
||||
dbLog.log(ETP_LOG_VERBOSE,"commitChanges: discarding changes to database (opened readonly).")
|
||||
self.discardChanges() # is it ok?
|
||||
|
||||
def taintDatabase(self):
|
||||
dbLog.log(ETP_LOG_VERBOSE,"taintDatabase: called.")
|
||||
# taint the database status
|
||||
f = open(etpConst['etpdatabasedir']+"/"+etpConst['etpdatabasetaintfile'],"w")
|
||||
f.write(etpConst['currentarch']+" database tainted\n")
|
||||
|
||||
@@ -124,6 +124,8 @@ ETP_SMARTAPPSDIR = "/smartapps/"+ETP_ARCH_CONST
|
||||
ETP_CONF_DIR = "/etc/entropy"
|
||||
ETP_ROOT_DIR = "/"
|
||||
ETP_LOG_DIR = ETP_DIR+"/"+"logs"
|
||||
ETP_LOG_NORMAL = 1
|
||||
ETP_LOG_VERBOSE = 2
|
||||
# NEVER APPEND another \n to this file because it will break the md5 check of reagent
|
||||
ETP_HEADER_TEXT = "# Sabayon Linux (C - 2007) - Entropy Package Specifications (GPLv2)\n"
|
||||
MAX_ETP_REVISION_COUNT = 99999
|
||||
@@ -143,13 +145,14 @@ etpConst = {
|
||||
'overlays': "", # variable PORTDIR_OVERLAY
|
||||
'overlaysconffile': ETP_CONF_DIR+"/layman.cfg", # layman configuration file
|
||||
'confdir': ETP_CONF_DIR, # directory where entropy stores its configuration
|
||||
'entropyconf': ETP_CONF_DIR+"/entropy.conf", # entropy.conf file
|
||||
'repositoriesconf': ETP_CONF_DIR+"/repositories.conf", # repositories.conf file
|
||||
'enzymeconf': ETP_CONF_DIR+"/enzyme.conf", # enzyme.conf file
|
||||
'activatorconf': ETP_CONF_DIR+"/activator.conf", # activator.conf file
|
||||
'reagentconf': ETP_CONF_DIR+"/reagent.conf", # reagent.conf file
|
||||
'databaseconf': ETP_CONF_DIR+"/database.conf", # database.conf file
|
||||
'activatoruploaduris': [],# list of URIs that activator can use to upload files (parsed from activator.conf)
|
||||
'activatordownloaduris': [],# list of URIs that activator can use to fetch data
|
||||
'activatoruploaduris': [], # list of URIs that activator can use to upload files (parsed from activator.conf)
|
||||
'activatordownloaduris': [], # list of URIs that activator can use to fetch data
|
||||
'binaryurirelativepath': "packages/"+ETP_ARCH_CONST+"/", # Relative remote path for the binary repository.
|
||||
'etpurirelativepath': "database/"+ETP_ARCH_CONST+"/", # Relative remote path for the .etp repository.
|
||||
# TO BE REMOVED? CHECK
|
||||
@@ -166,6 +169,7 @@ etpConst = {
|
||||
'enzymeloglevel': 1 , # Enzyme log level (default: 1 - see enzyme.conf for more info)
|
||||
'reagentloglevel': 1 , # Reagent log level (default: 1 - see reagent.conf for more info)
|
||||
'activatorloglevel': 1, # # Activator log level (default: 1 - see activator.conf for more info)
|
||||
'entropyloglevel': 1, # # Entropy log level (default: 1 - see entropy.conf for more info)
|
||||
'logdir': ETP_LOG_DIR , # Log dir where ebuilds store their shit
|
||||
'databaselogfile': ETP_LOG_DIR+"/database.log", # database operations log file
|
||||
'enzymelogfile': ETP_LOG_DIR+"/enzyme.log", # Enzyme operations log file
|
||||
|
||||
@@ -34,6 +34,10 @@ import databaseTools
|
||||
import mirrorTools
|
||||
dbStatus = databaseTools.databaseStatus()
|
||||
|
||||
# Logging initialization
|
||||
import logTools
|
||||
entropyLog = logTools.LogFile(level=etpConst['entropyloglevel'],filename = etpConst['entropylogfile'], header = "[Entropy]")
|
||||
|
||||
# EXIT STATUSES: 100-199
|
||||
|
||||
def isRoot():
|
||||
|
||||
@@ -32,7 +32,7 @@ import string
|
||||
|
||||
# Logging initialization
|
||||
import logTools
|
||||
enzymeLog = logTools.LogFile(level=etpConst['enzymeloglevel'],filename = etpConst['enzymelogfile'])
|
||||
enzymeLog = logTools.LogFile(level=etpConst['enzymeloglevel'],filename = etpConst['enzymelogfile'], header = "[Enzyme]")
|
||||
|
||||
# EXIT STATUSES: 200-299
|
||||
|
||||
|
||||
@@ -26,11 +26,13 @@
|
||||
'''
|
||||
|
||||
import sys
|
||||
import time
|
||||
|
||||
class LogFile:
|
||||
def __init__ (self, level = 0, filename = None):
|
||||
def __init__ (self, level = 0, filename = None, header = "[LOG]"):
|
||||
self.handler = self.default_handler
|
||||
self.level = level
|
||||
self.header = header
|
||||
self.logFile = None
|
||||
self.open(filename)
|
||||
|
||||
@@ -66,7 +68,10 @@ class LogFile:
|
||||
|
||||
def log(self, level, message):
|
||||
if self.level >= level:
|
||||
self.handler(message)
|
||||
self.handler(self.getTimeDateHeader()+self.header+' '+message)
|
||||
|
||||
def getTimeDateHeader(self):
|
||||
return time.strftime('[%X %x %Z] ')
|
||||
|
||||
def ladd(self, level, file, message):
|
||||
if self.level >= level:
|
||||
|
||||
@@ -35,7 +35,7 @@ from portageTools import unpackTbz2, synthetizeRoughDependencies, getPackageRunt
|
||||
|
||||
# Logging initialization
|
||||
import logTools
|
||||
reagentLog = logTools.LogFile(level=etpConst['reagentloglevel'],filename = etpConst['reagentlogfile'])
|
||||
reagentLog = logTools.LogFile(level=etpConst['reagentloglevel'],filename = etpConst['reagentlogfile'], header = "[Reagent]")
|
||||
|
||||
def generator(package, enzymeRequestBump = False, dbconnection = None):
|
||||
|
||||
|
||||
Reference in New Issue
Block a user