[Oval-commits] r141 - in trunk/oval-server/src: . dsaSync
Pavel Vinogradov
blaze-guest at alioth.debian.org
Thu Aug 16 05:40:03 UTC 2007
Author: blaze-guest
Date: 2007-08-16 05:40:02 +0000 (Thu, 16 Aug 2007)
New Revision: 141
Added:
trunk/oval-server/src/dsaSync/
trunk/oval-server/src/dsaSync/DsaUpdater.py
trunk/oval-server/src/dsaSync/DsaUpdater.pyc
trunk/oval-server/src/dsaSync/ftpUpdater.py
trunk/oval-server/src/dsaSync/httpUpdater.py
Removed:
trunk/oval-server/src/dsaSync/DsaUpdater.py
trunk/oval-server/src/dsaSync/DsaUpdater.pyc
trunk/oval-server/src/dsaSync/ftpUpdater.py
trunk/oval-server/src/dsaUpdater/
Log:
Rename module dsaUpdater to dsaSync
Copied: trunk/oval-server/src/dsaSync (from rev 138, trunk/oval-server/src/dsaUpdater)
Deleted: trunk/oval-server/src/dsaSync/DsaUpdater.py
===================================================================
--- trunk/oval-server/src/dsaUpdater/DsaUpdater.py 2007-08-15 10:38:23 UTC (rev 138)
+++ trunk/oval-server/src/dsaSync/DsaUpdater.py 2007-08-16 05:40:02 UTC (rev 141)
@@ -1,29 +0,0 @@
-from datetime import datetime
-from stat import *
-import os
-
-class DsaUpdater:
-
- dsaSource = None
- dsaStorage = None
- actual = None
-
- def __init__ (self, source, storage):
- self.dsaSource = source
- self.dsaStorage =storage
- self.__getLastUpdateDate()
-
- def __getLastUpdateDate (self):
- time = datetime(1990, 1, 1, 00, 00, 00)
-
- if (os.access(self.dsaStorage, os.R_OK)):
- for path in os.listdir(self.dsaStorage):
- mtime = datetime.fromtimestamp(os.stat(self.dsaStorage+os.sep+path)[ST_MTIME])
- if mtime > time:
- time = mtime
- else:
- os.mkdir(self.dsaStorage)
- self.actual = time
-
- def syncronize (self):
- pass
\ No newline at end of file
Copied: trunk/oval-server/src/dsaSync/DsaUpdater.py (from rev 140, trunk/oval-server/src/dsaUpdater/DsaUpdater.py)
===================================================================
--- trunk/oval-server/src/dsaSync/DsaUpdater.py (rev 0)
+++ trunk/oval-server/src/dsaSync/DsaUpdater.py 2007-08-16 05:40:02 UTC (rev 141)
@@ -0,0 +1,29 @@
+from datetime import datetime
+from stat import *
+import os
+
+class DsaUpdater:
+
+ dsaSource = None
+ dsaStorage = None
+ actual = None
+
+ def __init__ (self, source, storage):
+ self.dsaSource = source
+ self.dsaStorage =storage
+ self.__getLastUpdateDate()
+
+ def __getLastUpdateDate (self):
+ time = datetime(1990, 1, 1, 00, 00, 00)
+
+ if (os.access(self.dsaStorage, os.R_OK)):
+ for path in os.listdir(self.dsaStorage):
+ mtime = datetime.fromtimestamp(os.stat(self.dsaStorage+os.sep+path)[ST_MTIME])
+ if mtime > time:
+ time = mtime
+ else:
+ os.mkdir(self.dsaStorage)
+ self.actual = time
+
+ def syncronize (self):
+ pass
\ No newline at end of file
Deleted: trunk/oval-server/src/dsaSync/DsaUpdater.pyc
===================================================================
(Binary files differ)
Copied: trunk/oval-server/src/dsaSync/DsaUpdater.pyc (from rev 140, trunk/oval-server/src/dsaUpdater/DsaUpdater.pyc)
===================================================================
(Binary files differ)
Deleted: trunk/oval-server/src/dsaSync/ftpUpdater.py
===================================================================
--- trunk/oval-server/src/dsaUpdater/ftpUpdater.py 2007-08-15 10:38:23 UTC (rev 138)
+++ trunk/oval-server/src/dsaSync/ftpUpdater.py 2007-08-16 05:40:02 UTC (rev 141)
@@ -1,128 +0,0 @@
-from DsaUpdater import DsaUpdater
-from datetime import datetime
-from ftplib import FTP
-import os, re, logging
-import socket
-
-logging.basicConfig()
-
-class ftpConnectException (Exception):
- pass
-
-class ftpUpdater(DsaUpdater):
-
- ftphost = 'ftp://server'
- dirs = []
- result = []
- ftp = None
- curdir = '/'
- curfile = None
-
- 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, ftpserver):
- DsaUpdater.__init__(self, source, storage)
- try:
- self.ftphost = ftpserver
- self.ftp = FTP(self.ftphost)
- self.ftp.login()
- self.curdir = '/'
- except Exception:
- raise ftpConnectException
-
- def __parse(self, line):
- mtime = None
- type = None
-
- #year = 2007, in this case LIST return time instead of year
- patern = re.compile(r'[drxr\- ]+(\d) *\d+ *\d+ *\d+ (\w+) (\d+) (\d+:\d+) (.*)')
- result = patern.search(line)
- if result:
- type = result.groups()[0]
- month = self.month[result.groups()[1]]
- day = int(result.groups()[2])
- (hour, min) = result.groups()[3].split(':')
- file = result.groups()[4]
- mtime = datetime(2007, month, day, int(hour), int(min), 0)
- else:
- #year != 2007
- patern = re.compile(r'[drxr\- ]+(\d) *\d+ *\d+ *\d+ (\w+) (\d+) *(\d+) (.*)')
- result = patern.search(line)
- if result:
- type = result.groups()[0]
- month = self.month[result.groups()[1]]
- day = int(result.groups()[2])
- year = int(result.groups()[3])
- 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)
- else:
- if type == '3':
- self.dirs.append(file)
- else:
- logging.critical('Unknown file type: %s' % type)
- else:
- logging.critical('Bad line format: %s' % line)
-
- def __writer (self, data):
- file = open (self.curfile, 'a')
- file.write(data)
- file.close()
-
- def cmpdir (self):
-
- self.dirs = []
- logging.critical('LIST %s' % self.curdir)
- self.ftp.cwd(self.curdir)
- self.ftp.retrlines('LIST', self.__parse)
-
- if self.dirs:
- dirs = self.dirs[:]
- for dir in dirs:
- self.curdir += '/%s' % dir
- self.cmpdir()
- self.ftp.cwd('../')
- self.curdir = os.path.split(self.curdir)[0]
-
- def syncfile (self, dir, file):
-
- if dir:
- path = self.dsaStorage + os.sep + dir
-
- 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.ftp.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.ftp.retrbinary('RETR %s' % (self.dsaSource + os.sep+file), self.__writer)
-
- def syncdirs (self):
- for path in self.result:
- file = path[len(self.dsaSource)+1:]
- (dir, file) = os.path.split(file)
- self.syncfile (dir, file)
-
- def sync(self):
- logging.critical('Syncing %s with ftp://%s%s' % (self.dsaStorage, self.ftphost, self.dsaSource))
- self.curdir = self.dsaSource
- self.cmpdir ()
-
- if self.result:
- self.syncdirs ()
-
-if __name__ == '__main__':
- try:
- upd = ftpUpdater('/debian/dsa', '/tmp/dsa', 'server')
- upd.sync()
- except ftpConnectException:
- logging.critical('Ftp server not available.')
\ No newline at end of file
Copied: trunk/oval-server/src/dsaSync/ftpUpdater.py (from rev 140, trunk/oval-server/src/dsaUpdater/ftpUpdater.py)
===================================================================
--- trunk/oval-server/src/dsaSync/ftpUpdater.py (rev 0)
+++ trunk/oval-server/src/dsaSync/ftpUpdater.py 2007-08-16 05:40:02 UTC (rev 141)
@@ -0,0 +1,127 @@
+from DsaUpdater import DsaUpdater
+from datetime import datetime
+from ftplib import FTP
+import os, re, logging
+
+logging.basicConfig()
+
+class ftpConnectException (Exception):
+ pass
+
+class ftpUpdater(DsaUpdater):
+
+ host = 'ftp://server'
+ dirs = []
+ result = []
+ ftp = None
+ curdir = '/'
+ curfile = None
+
+ 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):
+ DsaUpdater.__init__(self, source, storage)
+ try:
+ self.host = server
+ self.ftp = FTP(self.host)
+ self.ftp.login()
+ self.curdir = '/'
+ except Exception:
+ raise ftpConnectException
+
+ def __parse(self, line):
+ mtime = None
+ type = None
+
+ #year = 2007, in this case LIST return time instead of year
+ patern = re.compile(r'[drxr\- ]+(\d) *\d+ *\d+ *\d+ (\w+) (\d+) (\d+:\d+) (.*)')
+ result = patern.search(line)
+ if result:
+ type = result.groups()[0]
+ month = self.month[result.groups()[1]]
+ day = int(result.groups()[2])
+ (hour, min) = result.groups()[3].split(':')
+ file = result.groups()[4]
+ mtime = datetime(2007, month, day, int(hour), int(min), 0)
+ else:
+ #year != 2007
+ patern = re.compile(r'[drxr\- ]+(\d) *\d+ *\d+ *\d+ (\w+) (\d+) *(\d+) (.*)')
+ result = patern.search(line)
+ if result:
+ type = result.groups()[0]
+ month = self.month[result.groups()[1]]
+ day = int(result.groups()[2])
+ year = int(result.groups()[3])
+ 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)
+ else:
+ if type == '3':
+ self.dirs.append(file)
+ else:
+ logging.critical('Unknown file type: %s' % type)
+ else:
+ logging.critical('Bad line format: %s' % line)
+
+ def __writer (self, data):
+ file = open (self.curfile, 'w')
+ file.write(data)
+ file.close()
+
+ def cmpdir (self):
+
+ self.dirs = []
+ logging.critical('LIST %s' % self.curdir)
+ self.ftp.cwd(self.curdir)
+ self.ftp.retrlines('LIST', self.__parse)
+
+ if self.dirs:
+ dirs = self.dirs[:]
+ for dir in dirs:
+ self.curdir += '/%s' % dir
+ self.cmpdir()
+ self.ftp.cwd('../')
+ self.curdir = os.path.split(self.curdir)[0]
+
+ def syncfile (self, dir, file):
+
+ if dir:
+ path = self.dsaStorage + os.sep + dir
+
+ 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.ftp.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.ftp.retrbinary('RETR %s' % (self.dsaSource + os.sep+file), self.__writer)
+
+ def syncdirs (self):
+ for path in self.result:
+ file = path[len(self.dsaSource)+1:]
+ (dir, file) = os.path.split(file)
+ self.syncfile (dir, file)
+
+ def sync(self):
+ logging.critical('Syncing %s with ftp://%s%s' % (self.dsaStorage, self.host, self.dsaSource))
+ self.curdir = self.dsaSource
+ self.cmpdir ()
+
+ if self.result:
+ self.syncdirs ()
+
+if __name__ == '__main__':
+ try:
+ upd = ftpUpdater('/debian/dsa', '/tmp/dsa', 'server')
+ upd.sync()
+ except ftpConnectException:
+ logging.critical('Ftp server not available.')
\ No newline at end of file
Copied: trunk/oval-server/src/dsaSync/httpUpdater.py (from rev 140, trunk/oval-server/src/dsaUpdater/httpUpdater.py)
===================================================================
--- trunk/oval-server/src/dsaSync/httpUpdater.py (rev 0)
+++ trunk/oval-server/src/dsaSync/httpUpdater.py 2007-08-16 05:40:02 UTC (rev 141)
@@ -0,0 +1,138 @@
+from DsaUpdater import DsaUpdater
+from datetime import datetime
+import os, re, logging
+import httplib
+
+logging.basicConfig()
+
+class httpConnectException (Exception):
+ pass
+
+class httpUpdater(DsaUpdater):
+
+ host = 'htttp://server'
+ conn = None
+
+ dirs = []
+ result = []
+
+ curdir = '/'
+ curfile = None
+
+ 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):
+ DsaUpdater.__init__(self, source, storage)
+ try:
+ self.host = server
+ self.conn = httplib.HTTPConnection(self.host)
+ except Exception:
+ raise httpConnectException
+
+ def __parse(self, data):
+ mtime = None
+ type = None
+
+ paternDIR = re.compile(r'<td><a href="\d+/">(\d+/)</a></td>.*>(\d+)\-(\w+)\-(\d+) (\d+:\d+) *</td>')
+ paternFILE = re.compile(r'<td><a href="[\w\d\.\-]+">(dsa\-\d+\.(wml|data))</a></td>.*>(\d+)\-(\w+)\-(\d+) (\d+:\d+) *</td>')
+
+ for line in data.split('\n'):
+ mtime = None
+ type = None
+
+ result = paternDIR.search(line)
+ if result:
+ type = 'dir'
+ file = result.groups()[0]
+ day = int(result.groups()[1])
+ month = self.month[result.groups()[2]]
+ year = int(result.groups()[3])
+ (hour, min) = result.groups()[4].split(':')
+ mtime = datetime(year, month, day, int(hour), int(min), 0)
+ else:
+ result = paternFILE.search(line)
+ if result:
+ type = 'file'
+ file = result.groups()[0]
+ day = int(result.groups()[2])
+ month = self.month[result.groups()[3]]
+ year = int(result.groups()[4])
+ (hour, min) = result.groups()[5].split(':')
+ 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)
+ else:
+ if type == 'dir':
+ self.dirs.append(file)
+ else:
+ logging.critical('Unknown file type: %s' % type)
+ else:
+ pass
+ #logging.critical('Bad line format: %s' % line)
+
+ def __writer (self, data):
+ file = open (self.curfile, 'w')
+ file.write(data)
+ file.close()
+
+ def cmpdir (self):
+
+ self.dirs = []
+ logging.critical('LIST %s' % self.curdir)
+ self.conn.request('GET',self.curdir)
+ self.__parse(self.conn.getresponse().read())
+
+ if self.dirs:
+ dirs = self.dirs[:]
+ for dir in dirs:
+ self.curdir += '/%s' % dir
+ self.cmpdir()
+ self.curdir = os.path.split(self.curdir)[0]
+ self.curdir = os.path.split(self.curdir)[0]
+
+ def syncfile (self, dir, file):
+
+ if dir:
+ path = self.dsaStorage + os.sep + dir
+
+ 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
+ self.conn.request('GET', '%s' % (self.dsaSource+os.sep+file))
+ data = self.conn.getresponse().read()
+ self.__writer(data)
+
+ def syncdirs (self):
+ for path in self.result:
+ file = path[len(self.dsaSource):]
+ (dir, file) = os.path.split(file)
+ self.syncfile (dir, file)
+
+ def sync(self):
+ logging.critical('Syncing %s with http://%s%s' % (self.dsaStorage, self.host, self.dsaSource))
+ self.curdir = self.dsaSource
+ self.cmpdir ()
+
+ if self.result:
+ self.syncdirs ()
+
+if __name__ == '__main__':
+ try:
+ upd = httpUpdater('/~blaze/debian/dsa/', '/tmp/dsa', 'server')
+ upd.sync()
+ except httpConnectException:
+ logging.critical('Http server not available.')
\ No newline at end of file
More information about the Oval-commits
mailing list