def __init__(self, mediadir): # Where shall we save downloaded files? self.__cachedir = os.path.join(mediadir, "downloads") # Ensure the cache exists log.info("Initialising cache directory at %s", self.__cachedir) utils.ensuredirexists(self.__cachedir)
def installpack(self, mediadir): # Work out the pack directory we want to extract to packpath = utils.mkdirfallback(mediadir, self.name) log.info("Extracting downloaded media into %s", packpath) # Extract the ZIP into a new directory thezip = zipfile.ZipFile(self.zippath) for info in thezip.infolist(): # Create the directory extractfilepath = os.path.join(packpath, info.filename) utils.ensuredirexists(os.path.dirname(extractfilepath)) # Extract the file. NB: must use binary mode - this important for for Windows! file = open(extractfilepath, 'wb') file.write(thezip.read(info.filename)) file.close()