[Oval-commits] r139 - trunk/oval-server/src/dsaUpdater

Pavel Vinogradov blaze-guest at alioth.debian.org
Wed Aug 15 18:17:21 UTC 2007


Author: blaze-guest
Date: 2007-08-15 18:17:21 +0000 (Wed, 15 Aug 2007)
New Revision: 139

Added:
   trunk/oval-server/src/dsaUpdater/httpUpdater.py
Modified:
   trunk/oval-server/src/dsaUpdater/DsaUpdater.py
   trunk/oval-server/src/dsaUpdater/DsaUpdater.pyc
   trunk/oval-server/src/dsaUpdater/ftpUpdater.py
Log:
Start implementing httpUpdater module

Modified: trunk/oval-server/src/dsaUpdater/DsaUpdater.py
===================================================================
--- trunk/oval-server/src/dsaUpdater/DsaUpdater.py	2007-08-15 10:38:23 UTC (rev 138)
+++ trunk/oval-server/src/dsaUpdater/DsaUpdater.py	2007-08-15 18:17:21 UTC (rev 139)
@@ -3,7 +3,7 @@
 import os
  
 class DsaUpdater:
-	
+
 	dsaSource = None
 	dsaStorage = None
 	actual = None

Modified: trunk/oval-server/src/dsaUpdater/DsaUpdater.pyc
===================================================================
(Binary files differ)

Modified: trunk/oval-server/src/dsaUpdater/ftpUpdater.py
===================================================================
--- trunk/oval-server/src/dsaUpdater/ftpUpdater.py	2007-08-15 10:38:23 UTC (rev 138)
+++ trunk/oval-server/src/dsaUpdater/ftpUpdater.py	2007-08-15 18:17:21 UTC (rev 139)
@@ -2,7 +2,6 @@
 from datetime import datetime
 from ftplib import FTP
 import os, re, logging
-import socket
 
 logging.basicConfig()
 
@@ -11,7 +10,7 @@
 
 class ftpUpdater(DsaUpdater):
 	
-	ftphost = 'ftp://server'
+	host = 'ftp://server'
 	dirs = []
 	result = []
 	ftp = None
@@ -21,11 +20,11 @@
 	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):
+	def __init__ (self, source, storage, server):
 		DsaUpdater.__init__(self, source, storage)
 		try:
-			self.ftphost = ftpserver
-			self.ftp = FTP(self.ftphost)
+			self.host = server
+			self.ftp = FTP(self.host)
 			self.ftp.login()
 			self.curdir = '/'
 		except Exception:
@@ -113,7 +112,7 @@
 			self.syncfile (dir, file)
 			
 	def sync(self):
-		logging.critical('Syncing %s with ftp://%s%s' % (self.dsaStorage, self.ftphost, self.dsaSource))
+		logging.critical('Syncing %s with ftp://%s%s' % (self.dsaStorage, self.host, self.dsaSource))
 		self.curdir = self.dsaSource
 		self.cmpdir ()
 

Added: trunk/oval-server/src/dsaUpdater/httpUpdater.py
===================================================================
--- trunk/oval-server/src/dsaUpdater/httpUpdater.py	                        (rev 0)
+++ trunk/oval-server/src/dsaUpdater/httpUpdater.py	2007-08-15 18:17:21 UTC (rev 139)
@@ -0,0 +1,143 @@
+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
+		#print data
+		#year = 2007, in this case LIST return time instead of year
+		patern = re.compile(r'<td><a href="\d+/">(\d+/)</a></td>.*(\d+)\-(\w+)\-(\d+) (\d+:\d+) *</td>')
+		for line in data.split('\n'):
+			result = patern.search(line)
+			if result:
+				print result.groups()
+#				type = 'dir'
+#				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)
+#				
+				
+				print 'match'
+			else:
+				print line
+				
+#			
+#			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.conn.request('GET',self.curdir)
+		self.__parse(self.conn.getresponse().read())
+		return 0
+		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 http://%s%s' % (self.dsaStorage, self.host, self.dsaSource))
+		self.curdir = self.dsaSource
+		self.cmpdir ()
+
+		if self.result:
+			print 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