[Oval-commits] r150 - in trunk/oval-server: . src/dsaSync
Pavel Vinogradov
blaze-guest at alioth.debian.org
Sun Aug 19 18:27:17 UTC 2007
Author: blaze-guest
Date: 2007-08-19 18:27:17 +0000 (Sun, 19 Aug 2007)
New Revision: 150
Modified:
trunk/oval-server/oval-server.py
trunk/oval-server/src/dsaSync/directory.py
trunk/oval-server/src/dsaSync/ftp.py
trunk/oval-server/src/dsaSync/http.py
trunk/oval-server/src/dsaSync/sync.py
Log:
Updates and bugfixes in sync modules
Modified: trunk/oval-server/oval-server.py
===================================================================
--- trunk/oval-server/oval-server.py 2007-08-19 11:48:27 UTC (rev 149)
+++ trunk/oval-server/oval-server.py 2007-08-19 18:27:17 UTC (rev 150)
@@ -16,7 +16,7 @@
if self.type == 'local':
from dsaSync.directory import dirSync
- self.syncer = dirSync(self.source, self.storage)
+ self.syncer = dirSync(self.source, self.storage, self.logger)
self.logger.info('syncThread: Run local updater %s with: %s, %s' % (self.name, self.source, self.update_interval))
def startThread (self):
Modified: trunk/oval-server/src/dsaSync/directory.py
===================================================================
--- trunk/oval-server/src/dsaSync/directory.py 2007-08-19 11:48:27 UTC (rev 149)
+++ trunk/oval-server/src/dsaSync/directory.py 2007-08-19 18:27:17 UTC (rev 150)
@@ -9,13 +9,14 @@
result = []
def cmpdir (self, directory):
-
+ self.logger.debug ('directorySync: sync dir %s' % directory)
+
for file in os.listdir(directory):
path = '%s/%s' % (directory, file)
mtime = datetime.fromtimestamp(os.stat(path)[ST_MTIME])
if mtime > self.actual:
-
+ #self.logger.debug ('Check %s newwer then %s for %s' % (mtime, self.actual, path))
if os.access(path, os.R_OK) and os.path.isdir (path) and not os.path.islink (path) and file[0] != '.':
self.cmpdir (path)
@@ -37,19 +38,25 @@
copyfile ('%s/%s' % (self.dsaSource, file), self.dsaStorage+os.sep+file)
def syncdirs (self):
+ #Move this function to parrent
for path in self.result:
file = path[len(self.dsaSource)+1:]
(dir, file) = os.path.split(file)
self.syncfile (dir, file)
+ self.logger.info('directorySync: synced %d files' % len(self.result))
def sync(self):
+ #Move this function to parrent
+ self.result = []
+ self.getLastUpdateDate()
+ self.logger.info('Syncing %s with %s' % (self.dsaStorage, self.dsaSource))
+
self.cmpdir (self.dsaSource)
-
if self.result:
self.syncdirs ()
+ else:
+ self.logger.info('directorySync: no files to sync')
if __name__ == '__main__':
upd = dirSync('/home/blaze/tmp/oval/server/dsa', '/tmp/dsa')
- upd.sync()
-
-
\ No newline at end of file
+ upd.sync()
\ No newline at end of file
Modified: trunk/oval-server/src/dsaSync/ftp.py
===================================================================
--- trunk/oval-server/src/dsaSync/ftp.py 2007-08-19 11:48:27 UTC (rev 149)
+++ trunk/oval-server/src/dsaSync/ftp.py 2007-08-19 18:27:17 UTC (rev 150)
@@ -20,8 +20,8 @@
month = {'Jan' : 1, 'Feb' : 2, 'Mar' : 3, 'Apr' : 4, 'May' : 5, 'Jun' : 6,
'Jul' : 7, 'Aug' : 8, 'Sep' : 9, 'Oct' : 10, 'Nov' : 11, 'Dec' : 12}
- def __init__ (self, source, storage, server):
- DsaSync.__init__(self, source, storage)
+ def __init__ (self, source, storage, server, logger):
+ DsaSync.__init__(self, source, storage, logger)
try:
self.host = server
self.conn = FTP(self.host)
@@ -56,7 +56,6 @@
file = result.groups()[4]
mtime = datetime(year, month, day, 12, 12, 0)
if mtime:
- logging.critical ('File %s with mtime %s vs %s' % (file, mtime, self.actual))
if mtime > self.actual:
if type == '1':
self.result.append(self.curdir+os.sep+file)
@@ -64,9 +63,9 @@
if type == '3':
self.dirs.append(file)
else:
- logging.critical('Unknown file type: %s' % type)
+ self.logger.critical('Unknown file type: %s' % type)
else:
- logging.critical('Bad line format: %s' % line)
+ self.logger.debug('Bad line format: %s' % line)
def __writer (self, data):
file = open (self.curfile, 'w')
@@ -74,9 +73,9 @@
file.close()
def cmpdir (self):
+ self.logger.debug ('ftpSync: sync dir %s' % self.dirs)
self.dirs = []
- logging.critical('LIST %s' % self.curdir)
self.conn.cwd(self.curdir)
self.conn.retrlines('LIST', self.__parse)
@@ -96,30 +95,35 @@
if os.access(path, os.W_OK) and os.path.isdir (path):
self.curfile = '%s/%s/%s' % (self.dsaStorage, dir, file)
- logging.critical('sync %s' % (path+os.sep+file))
self.conn.retrbinary('RETR %s' % (self.dsaSource+os.sep+dir+os.sep+file), self.__writer)
else:
os.mkdir(path)
- logging.critical('sync dir %s' % path)
self.syncfile(dir, file)
else:
self.curfile = self.dsaStorage+os.sep+file
self.conn.retrbinary('RETR %s' % (self.dsaSource + os.sep+file), self.__writer)
def syncdirs (self):
+ #Move this function to parrent
for path in self.result:
file = path[len(self.dsaSource)+1:]
(dir, file) = os.path.split(file)
self.syncfile (dir, file)
-
+ self.logger.info('directorySync: synced %d files' % len(self.result))
+
def sync(self):
- logging.critical('Syncing %s with ftp://%s%s' % (self.dsaStorage, self.host, self.dsaSource))
+ #Move this function to parrent
+ self.result = []
+ self.getLastUpdateDate()
+ self.logger.info('Syncing %s with ftp://%s%s' % (self.dsaStorage, self.host, self.dsaSource))
self.curdir = self.dsaSource
+
self.cmpdir ()
-
if self.result:
self.syncdirs ()
-
+ else:
+ self.logger.info('directorySync: no files to sync')
+
if __name__ == '__main__':
try:
upd = ftpSync('/debian/dsa', '/tmp/dsa', 'server')
Modified: trunk/oval-server/src/dsaSync/http.py
===================================================================
--- trunk/oval-server/src/dsaSync/http.py 2007-08-19 11:48:27 UTC (rev 149)
+++ trunk/oval-server/src/dsaSync/http.py 2007-08-19 18:27:17 UTC (rev 150)
@@ -1,10 +1,8 @@
from sync import DsaSync
from datetime import datetime
-import os, re, logging
+import os, re
import httplib
-logging.basicConfig()
-
class httpConnectException (Exception):
pass
@@ -22,8 +20,8 @@
month = {'Jan' : 1, 'Feb' : 2, 'Mar' : 3, 'Apr' : 4, 'May' : 5, 'Jun' : 6,
'Jul' : 7, 'Aug' : 8, 'Sep' : 9, 'Oct' : 10, 'Nov' : 11, 'Dec' : 12}
- def __init__ (self, source, storage, server):
- DsaSync.__init__(self, source, storage)
+ def __init__ (self, source, storage, server, logger):
+ DsaSync.__init__(self, source, storage, logger)
try:
self.host = server
self.conn = httplib.HTTPConnection(self.host)
@@ -62,7 +60,6 @@
mtime = datetime(year, month, day, int(hour), int(min), 0)
if mtime:
- logging.critical ('%s %s with mtime %s vs %s' % (type, file, mtime, self.actual))
if mtime > self.actual:
if type == 'file':
self.result.append(self.curdir+os.sep+file)
@@ -70,10 +67,9 @@
if type == 'dir':
self.dirs.append(file)
else:
- logging.critical('Unknown file type: %s' % type)
+ self.logger.critical('Unknown file type: %s' % type)
else:
- pass
- #logging.critical('Bad line format: %s' % line)
+ self.logger.debug('Bad line format: %s' % line)
def __writer (self, data):
file = open (self.curfile, 'w')
@@ -81,6 +77,7 @@
file.close()
def cmpdir (self):
+ self.logger.debug ('httpSync: sync dir %s' % self.dirs)
self.dirs = []
logging.critical('LIST %s' % self.curdir)
@@ -104,13 +101,11 @@
if os.access(path, os.W_OK) and os.path.isdir (path):
self.curfile = '%s/%s/%s' % (self.dsaStorage, dir, file)
- logging.critical('sync %s' % (path+os.sep+file))
self.conn.request('GET', '%s' % (self.dsaSource+os.sep+dir+os.sep+file))
data = self.conn.getresponse().read()
self.__writer(data)
else:
os.mkdir(path)
- logging.critical('sync dir %s' % path)
self.syncfile(dir, file)
else:
self.curfile = self.dsaStorage+os.sep+file
@@ -119,13 +114,18 @@
self.__writer(data)
def sync(self):
- logging.critical('Syncing %s with http://%s%s' % (self.dsaStorage, self.host, self.dsaSource))
+ #Move this function to parrent
+ self.result = []
+ self.getLastUpdateDate()
+ self.logger.info('Syncing %s with http://%s%s' % (self.dsaStorage, self.host, self.dsaSource))
self.curdir = self.dsaSource
+
self.cmpdir ()
-
if self.result:
self.syncdirs ()
-
+ else:
+ self.logger.info('directorySync: no files to sync')
+
if __name__ == '__main__':
try:
upd = httpSync('/~blaze/debian/dsa/', '/tmp/dsa', 'server')
Modified: trunk/oval-server/src/dsaSync/sync.py
===================================================================
--- trunk/oval-server/src/dsaSync/sync.py 2007-08-19 11:48:27 UTC (rev 149)
+++ trunk/oval-server/src/dsaSync/sync.py 2007-08-19 18:27:17 UTC (rev 150)
@@ -1,20 +1,21 @@
from datetime import datetime
+import logging
from stat import *
import re
import os
class DsaSync:
-
- dsaSource = None
- dsaStorage = None
- actual = None
- def __init__ (self, source, storage):
+ def __init__ (self, source, storage, logger = None):
self.dsaSource = source
self.dsaStorage =storage
- self.__getLastUpdateDate()
+ if logger:
+ self.logger = logger
+ else:
+ self.logger = logging.basicConfig
+ self.getLastUpdateDate()
- def __getLastUpdateDate (self):
+ def getLastUpdateDate (self):
time = datetime(1990, 1, 1, 00, 00, 00)
if (os.access(self.dsaStorage, os.R_OK)):
@@ -25,6 +26,7 @@
else:
os.mkdir(self.dsaStorage)
self.actual = time
+ self.logger.debug('dsaSync: actual set to %s' % self.actual)
def syncfile (self, dir, file):
from dba import dba
@@ -44,3 +46,4 @@
file = path[len(self.dsaSource):]
(dir, file) = os.path.split(file)
self.syncfile (dir, file)
+ self.logger.info('directorySync: synced %d files' % len(self.result))
\ No newline at end of file
More information about the Oval-commits
mailing list