diff options
author | 2008-06-17 17:43:56 +0530 | |
---|---|---|
committer | 2008-06-17 17:43:56 +0530 | |
commit | 290c595afc75526af6e026dd789f255bd46c4d69 (patch) | |
tree | f6702bfb476c550a79e0e8cc3f322df2b6934f09 /slave/autotua/fetch | |
parent | - Skeleton code notice in autotua.getjobs() (diff) | |
download | autotua-290c595afc75526af6e026dd789f255bd46c4d69.tar.gz autotua-290c595afc75526af6e026dd789f255bd46c4d69.tar.bz2 autotua-290c595afc75526af6e026dd789f255bd46c4d69.zip |
Restructure the code
Diffstat (limited to 'slave/autotua/fetch')
-rw-r--r-- | slave/autotua/fetch/__init__.py | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/slave/autotua/fetch/__init__.py b/slave/autotua/fetch/__init__.py new file mode 100644 index 0000000..1930356 --- /dev/null +++ b/slave/autotua/fetch/__init__.py @@ -0,0 +1,70 @@ +# vim: set sw=4 sts=4 et : +# Copyright: 2008 Gentoo Foundation +# Author(s): Nirbheek Chauhan <nirbheek.chauhan@gmail.com> +# License: GPL-2 +# +# Immortal lh! +# + +import os + +class Fetchable(object): + """class representing uri sources for a file and chksum information.""" + + def __init__(self, filename, uri=[], chksums=None): + """ + @param filename: filename... + @param uri: either None (no uri), + or a sequence of uri where the file is available + @param chksums: either None (no chksum data), + or a dict of chksum_type -> value for this file + """ + self.uri = uri + if chksums is None: + self.chksums = {} + else: + self.chksums = chksums + self.filename = filename + + def __str__(self): + return self.filename + + +class Fetcher(object): + + def __init__(self, tarballdir): + """ + @param tarballdir: directory to download files to + @type tarballdir: string + + @param command: shell command to fetch a file + @type command: string + """ + self.tarballdir = tarballdir + self.command = '/usr/bin/wget -c -t 5 -T 60 --tries=%(tries)s --passive-ftp -O "'+tarballdir+'/%(file)s" "%(uri)s"' + + def fetch(self, target): + """ + fetch a file + + @type target: L{Fetchable} instance + @return: None if fetching failed, + else on-disk location of the file + """ + + if not isinstance(target, Fetchable): + raise TypeError("target must be fetchable instance/derivative: %s" % target) + + #file_params = { 'mode': 0775 } + fp = os.path.join(self.tarballdir, target.filename) + filename = os.path.basename(fp) + status = 0 + index = len(target.uri) -1 + while index >= 0: + status = os.system(self.command % { 'file': filename, 'uri': target.uri[index], 'tries': 5 }) + index -= 1 + + if status == 0: + return os.path.join(self.tarballdir, filename) + else: + return None |