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

Pavel Vinogradov blaze-guest at alioth.debian.org
Wed Aug 15 06:05:20 UTC 2007


Author: blaze-guest
Date: 2007-08-15 06:05:19 +0000 (Wed, 15 Aug 2007)
New Revision: 136

Modified:
   trunk/oval-server/src/dsaUpdater/DsaUpdater.py
   trunk/oval-server/src/dsaUpdater/DsaUpdater.pyc
   trunk/oval-server/src/dsaUpdater/dirUpdater.py
   trunk/oval-server/src/dsaUpdater/ftpUpdater.py
Log:
Update ftp sync

Modified: trunk/oval-server/src/dsaUpdater/DsaUpdater.py
===================================================================
--- trunk/oval-server/src/dsaUpdater/DsaUpdater.py	2007-08-13 19:39:36 UTC (rev 135)
+++ trunk/oval-server/src/dsaUpdater/DsaUpdater.py	2007-08-15 06:05:19 UTC (rev 136)
@@ -16,11 +16,13 @@
 	def __getLastUpdateDate (self):
 		time = datetime(1990, 1, 1, 00, 00, 00)
 		
-		for path in os.listdir(self.dsaStorage):
-			mtime = datetime.fromtimestamp(os.stat(self.dsaStorage+os.sep+path)[ST_MTIME])
-			if mtime > time:
-				time = mtime
-		
+		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):

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

Modified: trunk/oval-server/src/dsaUpdater/dirUpdater.py
===================================================================
--- trunk/oval-server/src/dsaUpdater/dirUpdater.py	2007-08-13 19:39:36 UTC (rev 135)
+++ trunk/oval-server/src/dsaUpdater/dirUpdater.py	2007-08-15 06:05:19 UTC (rev 136)
@@ -6,7 +6,6 @@
 class dirUpdater(DsaUpdater):
 	
 	result = []
-	
 	def cmpdir (self, directory):
 			
 		for file in os.listdir(directory):

Modified: trunk/oval-server/src/dsaUpdater/ftpUpdater.py
===================================================================
--- trunk/oval-server/src/dsaUpdater/ftpUpdater.py	2007-08-13 19:39:36 UTC (rev 135)
+++ trunk/oval-server/src/dsaUpdater/ftpUpdater.py	2007-08-15 06:05:19 UTC (rev 136)
@@ -1,10 +1,10 @@
 from DsaUpdater import DsaUpdater
-from stat import *
 from datetime import datetime
-import os
 from ftplib import FTP
-import re
+import os, re, logging
 
+logging.basicConfig()
+
 class ftpUpdater(DsaUpdater):
 	
 	ftphost = 'ftp://server'
@@ -12,7 +12,11 @@
 	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)
 		self.ftphost = ftpserver
@@ -25,15 +29,29 @@
 		patern = re.compile(r'[drxr\- ]+(\d) *\d+ *\d+ *\d+ (\w+) (\d+) (\d+:\d+) (.*)')
 		result = patern.search(line)
 		if result:
-			if result.groups()[0] == '1':
-				self.result.append(self.curdir+os.sep+result.groups()[4])
-			else: 
-				if result.groups()[0] == '3':
-					self.dirs.append(result.groups()[4])
-				else:
-					pass
+			month = self.month[result.groups()[1]]
+			day = int(result.groups()[2])
+			(hour, min) = result.groups()[3].split(':')
+			mtime = datetime(2007, month, day, int(hour), int(min), 0)
+
+			if mtime > self.actual:
+				if result.groups()[0] == '1':
+					self.result.append(self.curdir+os.sep+result.groups()[4])
+				else: 
+					if result.groups()[0] == '3':
+						self.dirs.append(result.groups()[4])
+					else:
+						pass
 					#print result.groups()
+		else:
+			#We need to parse line with date
+			pass
 		
+	def __writer (self, data):
+		file = open (self.curfile, data)
+		file.write(data)
+		file.close()
+		
 	def cmpdir (self, directory):
 		
 		self.ftp.retrlines('LIST', self.__parse)
@@ -45,38 +63,22 @@
 				self.ftp.cwd('../')
 				self.curdir = os.path.split(self.curdir)[0]
 			
-#		patern = re.compile(r'dsa-(\d+)')
-#		
-#		for line in ls:
-#			
-#			result = patern.search(line)
-#			if result:
-#				print line
-		return (0)	
-#			path = '%s/%s' % (directory, file)
-#			
-#			mtime = datetime.fromtimestamp(os.stat(path)[ST_MTIME])
-#			if mtime > self.actual:
-#				
-#				if os.access(path, os.R_OK) and os.path.isdir (path) and not os.path.islink (path) and file[0] != '.':
-#					self.cmpdir (path)
-#					
-#				if os.access(path, os.R_OK) and (file.endswith('.data') or file.endswith('.wml')) and file[0] != '.' and file[0] != '#':
-#					self.result.append (path)
-#	
 	def syncfile (self, dir, file):
-		from shutil import copyfile
-			
+
 		if dir:
 			path = self.dsaStorage + os.sep + dir
 			
 			if os.access(path, os.W_OK) and os.path.isdir (path):
-				copyfile ('%s/%s/%s' % (self.dsaSource, dir, file), path+os.sep+file)
+				self.curfile = '%s/%s/%s' % (self.dsaSource, dir, file)
+				logging.critical('sync %s' % (path+os.sep+file))
+				self.ftp.retrbinary('RETR %s' % (path+os.sep+file), self.__writer)
 			else:
 				os.mkdir(path)
+				logging.critical('sync dir %s' % path)
 				self.syncfile(dir, file)
 		else:
-			copyfile ('%s/%s' % (self.dsaSource, file), self.dsaStorage)
+			self.curfile = self.dsaSource
+			self.ftp.retrbinary('RETR %s' % (self.dsaSource + os.sep+file), self.__writer)
 				
 	def syncdirs (self):
 		for path in self.result:
@@ -87,12 +89,12 @@
 	def sync(self):
 		self.cmpdir (self.dsaSource)
 		
-		print self.result
-#		if self.result:
-#			self.syncdirs ()
+		#print self.result
+		if self.result:
+			self.syncdirs ()
 		
 if __name__ == '__main__':
-	upd = ftpUpdater('/debian/dsa', '/tmp/dsa', 'server')
+	upd = ftpUpdater('/repos/debian/dsa', '/tmp/dsa', 'nixdev')
 	upd.sync()
 	
 	
\ No newline at end of file




More information about the Oval-commits mailing list