[Oval-commits] r137 - trunk/oval-server/src/dsaUpdater
Pavel Vinogradov
blaze-guest at alioth.debian.org
Wed Aug 15 09:21:50 UTC 2007
Author: blaze-guest
Date: 2007-08-15 09:21:50 +0000 (Wed, 15 Aug 2007)
New Revision: 137
Modified:
trunk/oval-server/src/dsaUpdater/ftpUpdater.py
Log:
Optimizations for ftp sync
Modified: trunk/oval-server/src/dsaUpdater/ftpUpdater.py
===================================================================
--- trunk/oval-server/src/dsaUpdater/ftpUpdater.py 2007-08-15 06:05:19 UTC (rev 136)
+++ trunk/oval-server/src/dsaUpdater/ftpUpdater.py 2007-08-15 09:21:50 UTC (rev 137)
@@ -2,9 +2,13 @@
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'
@@ -19,12 +23,14 @@
def __init__ (self, source, storage, ftpserver):
DsaUpdater.__init__(self, source, storage)
- self.ftphost = ftpserver
- self.ftp = FTP(self.ftphost)
- self.ftp.login()
- self.ftp.cwd(self.dsaSource)
- self.curdir = self.dsaSource
-
+ try:
+ self.ftphost = ftpserver
+ self.ftp = FTP(self.ftphost)
+ self.ftp.login()
+ self.curdir = '/'
+ except Exception:
+ raise ftpConnectException
+
def __parse(self, line):
patern = re.compile(r'[drxr\- ]+(\d) *\d+ *\d+ *\d+ (\w+) (\d+) (\d+:\d+) (.*)')
result = patern.search(line)
@@ -48,18 +54,22 @@
pass
def __writer (self, data):
- file = open (self.curfile, data)
+ file = open (self.curfile, 'a')
file.write(data)
file.close()
- def cmpdir (self, directory):
+ 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:
- for dir in self.dirs[:]:
- self.ftp.cwd(dir)
+ dirs = self.dirs[:]
+ for dir in dirs:
self.curdir += '/%s' % dir
- self.ftp.retrlines('LIST', self.__parse)
+ self.cmpdir()
self.ftp.cwd('../')
self.curdir = os.path.split(self.curdir)[0]
@@ -69,15 +79,15 @@
path = self.dsaStorage + os.sep + dir
if os.access(path, os.W_OK) and os.path.isdir (path):
- self.curfile = '%s/%s/%s' % (self.dsaSource, dir, file)
+ self.curfile = '%s/%s/%s' % (self.dsaStorage, dir, file)
logging.critical('sync %s' % (path+os.sep+file))
- self.ftp.retrbinary('RETR %s' % (path+os.sep+file), self.__writer)
+ 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.dsaSource
+ self.curfile = self.dsaStorage+os.sep+file
self.ftp.retrbinary('RETR %s' % (self.dsaSource + os.sep+file), self.__writer)
def syncdirs (self):
@@ -87,14 +97,18 @@
self.syncfile (dir, file)
def sync(self):
- self.cmpdir (self.dsaSource)
-
- #print self.result
+ 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__':
- upd = ftpUpdater('/repos/debian/dsa', '/tmp/dsa', 'nixdev')
- upd.sync()
-
+ try:
+ upd = ftpUpdater('/debian/dsa', '/tmp/dsa', 'server')
+ upd.sync()
+ except ftpConnectException:
+ logging.critical('Ftp server not available.')
+
\ No newline at end of file
More information about the Oval-commits
mailing list