from apt import OpProgress
from debian_bundle import deb822
+from apt_p2p_conf import config
from Hash import HashObject
apt_pkg.init()
@ivar essential_files: files that must be created for apt to work
@type cache_dir: L{twisted.python.filepath.FilePath}
@ivar cache_dir: the directory to use for storing all files
- @type unload_delay: C{int}
- @ivar unload_delay: the time to wait before unloading the apt cache
@ivar apt_config: the configuration parameters to use for apt
@type packages: L{PackageFileList}
@ivar packages: the persistent storage of tracked apt index files
'apt/lists/partial')
essential_files = ('apt/dpkg/status', 'apt/etc/sources.list',)
- def __init__(self, cache_dir, unload_delay):
+ def __init__(self, cache_dir):
"""Construct a new packages manager.
@param cache_dir: directory to use to store files for this mirror
"""
self.cache_dir = cache_dir
- self.unload_delay = unload_delay
self.apt_config = deepcopy(self.DEFAULT_APT_CONFIG)
# Create the necessary files and directories for apt
"""Make sure the package cache is initialized and loaded."""
# Reset the pending unload call
if self.unload_later and self.unload_later.active():
- self.unload_later.reset(self.unload_delay)
+ self.unload_later.reset(config.gettime('DEFAULT', 'UNLOAD_PACKAGES_CACHE'))
else:
- self.unload_later = reactor.callLater(self.unload_delay, self.unload)
+ self.unload_later = reactor.callLater(config.gettime('DEFAULT', 'UNLOAD_PACKAGES_CACHE'), self.unload)
# Make sure it's not already being loaded
if self.loading is None:
def setUp(self):
"""Initializes the cache with files found in the traditional apt location."""
- self.client = AptPackages(FilePath('/tmp/.apt-p2p'), 300)
+ self.client = AptPackages(FilePath('/tmp/.apt-p2p'))
# Find the largest index files that are for 'main'
self.packagesFile = os.popen('ls -Sr /var/lib/apt/lists/ | grep -E "_main_.*Packages$" | tail -n 1').read().rstrip('\n')
from twisted.web2.http import splitHostPort
from Hash import HashObject
+from apt_p2p_conf import config
DECOMPRESS_EXTS = ['.gz', '.bz2']
DECOMPRESS_FILES = ['release', 'sources', 'packages']
@ivar scanning: all the directories that are currectly being scanned or waiting to be scanned
"""
- def __init__(self, cache_dir, db, other_dirs = [], manager = None):
+ def __init__(self, cache_dir, db, manager = None):
"""Initialize the instance and remove any untracked files from the DB..
@type cache_dir: L{twisted.python.filepath.FilePath}
@param cache_dir: the directory to use for storing all files
@type db: L{db.DB}
@param db: the database to use for tracking files and hashes
- @type other_dirs: C{list} of L{twisted.python.filepath.FilePath}
- @param other_dirs: the other directories that have shared files in them
- (optional, defaults to only using the cache directory)
@type manager: L{apt_p2p.AptP2P}
@param manager: the main program object to send requests to
(optional, defaults to not calling back with cached files)
"""
self.cache_dir = cache_dir
- self.other_dirs = other_dirs
+ self.other_dirs = [FilePath(f) for f in config.getstringlist('DEFAULT', 'OTHER_DIRS')]
self.all_dirs = self.other_dirs[:]
self.all_dirs.insert(0, self.cache_dir)
self.db = db
from twisted.python.filepath import FilePath
from policies import ThrottlingFactory, ThrottlingProtocol, ProtocolWrapper
+from apt_p2p_conf import config
from apt_p2p_Khashmir.bencode import bencode
class FileDownloader(static.File):
addSlash = True
- def __init__(self, directory, db, manager, uploadLimit):
+ def __init__(self, directory, db, manager):
"""Initialize the instance.
@type directory: L{twisted.python.filepath.FilePath}
self.db = db
self.manager = manager
self.uploadLimit = None
- if uploadLimit > 0:
- self.uploadLimit = int(uploadLimit*1024)
+ if config.getint('DEFAULT', 'UPLOAD_LIMIT') > 0:
+ self.uploadLimit = int(config.getint('DEFAULT', 'UPLOAD_LIMIT')*1024)
self.factory = None
def getHTTPFactory(self):
file_hash = '\xf8~])+\x9d\xe5_B\xff\x1a\xc4!\xca \xb8\x0c\x00\xe7\x07'
def setUp(self):
- self.client = TopLevel(FilePath('/boot'), self, None, 0)
+ self.client = TopLevel(FilePath('/boot'), self, None)
def lookupHash(self, hash):
if hash == self.torrent_hash:
@type cache_dir: L{twisted.python.filepath.FilePath}
@ivar cache_dir: the directory to use for storing all files
- @type unload_delay: C{int}
- @ivar unload_delay: the time to wait before unloading the apt cache
@type apt_caches: C{dictionary}
@ivar apt_caches: the avaliable mirrors
"""
- def __init__(self, cache_dir, unload_delay):
+ def __init__(self, cache_dir):
self.cache_dir = cache_dir
- self.unload_delay = unload_delay
self.apt_caches = {}
def extractPath(self, url):
if baseDir not in self.apt_caches[site]:
site_cache = self.cache_dir.child(aptpkg_dir).child('mirrors').child(site + baseDir.replace('/', '_'))
site_cache.makedirs
- self.apt_caches[site][baseDir] = AptPackages(site_cache, self.unload_delay)
+ self.apt_caches[site][baseDir] = AptPackages(site_cache)
def updatedFile(self, url, file_path):
"""A file in the mirror has changed or been added.
client = None
def setUp(self):
- self.client = MirrorManager(FilePath('/tmp/.apt-p2p'), 300)
+ self.client = MirrorManager(FilePath('/tmp/.apt-p2p'))
def test_extractPath(self):
"""Test extracting the site and base directory from various mirrors."""
self.dht = dhtClass()
self.dht.loadConfig(config, config.get('DEFAULT', 'DHT'))
self.dht.join().addCallbacks(self.joinComplete, self.joinError)
- self.http_server = TopLevel(self.cache_dir.child(download_dir), self.db, self,
- config.getint('DEFAULT', 'UPLOAD_LIMIT'))
+ self.http_server = TopLevel(self.cache_dir.child(download_dir), self.db, self)
self.getHTTPFactory = self.http_server.getHTTPFactory
self.peers = PeerManager(self.cache_dir, self.dht)
- self.mirrors = MirrorManager(self.cache_dir, config.gettime('DEFAULT', 'UNLOAD_PACKAGES_CACHE'))
- other_dirs = [FilePath(f) for f in config.getstringlist('DEFAULT', 'OTHER_DIRS')]
- self.cache = CacheManager(self.cache_dir.child(download_dir), self.db, other_dirs, self)
+ self.mirrors = MirrorManager(self.cache_dir)
+ self.cache = CacheManager(self.cache_dir.child(download_dir), self.db, self)
self.my_contact = None
#{ DHT maintenance