def on_install(self, reporthook=None): """ We will take the approach of installing by copying the lists to /var/lib/apt/lists and the packages to /var/cache/apt/archives and calling apt-get update and then apt-get install on the packages which have the status of "to be installed". This prevents tampering with sources.list and works more or less the exact same if we made a local repository. """ if not os.geteuid() == 0: raise PermissionsError, "You may only install as root" # Copy lists over for repo in self.__iter_repositories(): url = to_url(repo, self.architecture, "Packages") filename = to_filename(os.path.join(self.download_directory, "lists"), url) try: # Extract the gz g = gzip.open("%s.gz" % filename, "rb") f = open(os.path.join("/var/lib/apt/lists", os.path.basename(filename)), "wb") f.write(g.read()) f.close() g.close() except IOError, e: # We will just ignore this, it only trip out if the user did download=False on update() pass
def _download_lists(self, reporthook=None): """ on_update helper function """ if not reporthook: reporthook = textprogress directory = os.path.join(self.download_directory, "lists") # If the download directory does not exist, create it if not os.path.exists(directory): os.makedirs(directory) for repo in self.__iter_repositories(): # Build the strings url = to_url(repo, self.architecture, "Packages") filename = to_filename(directory, url) display_name = "Repository => %s / %s" % (repo["dist"], repo["section"]) # Download #TODO: catch exceptions #TODO: Support bz2 and unarchived Packages files filename = "%s.gz" % filename download_url("%s.gz" % url, filename, display_name, progress=reporthook, proxy=self.proxy["proxy"], username=self.proxy["user"], password=self.proxy["pass"])
def _build_lists(self, directory, lists=[]): # Build the strings for repo in self.__iter_repositories(): url = to_url(repo, self.architecture, "Packages") filename = to_filename(directory, url) filename = "%s.gz" % filename # Works only if the index files are gz lists.append((repo, filename)) return lists
def process_response(self, request, response): if hasattr(request, "session"): request.session['last_csrf_cookie'] = \ request.META.get("CSRF_COOKIE", '') if isinstance( response, HttpResponseRedirect ) and request.agent.COOKIELESS: purl = urlparse(response.url) if not purl.netloc or purl.netloc == request.get_host(): response = HttpResponseRedirect( utils.to_url(purl, request.session.session_key)) return super(UrlBasedSessionMiddleware, self).process_response(request, response)