def getInfo(self): """Return mirror status and bandwidth""" launch_html = getHTML(self.launch_url) if not launch_html: return text = BeautifulSoup(launch_html).get_text() status = self.__reFind(self.regex[0], text) if not status: print("Unable to parse status info from %s", self.launch_url) return if "unknown" in status: status = "unknown" if status not in statuses: return speed = self.__reFind(self.regex[1], text) if not speed: return else: return (self.url, (status, speed))
notUbuntu() else: release = [s.strip() for s in release.decode('utf-8').split()] hardware = check_output("uname -m", shell=True).strip().decode('utf-8') if release[0] == 'Debian': errorExit("Debian is not currently supported", 1) elif release[0] != 'Ubuntu': notUbuntu() codename = release[1][0].upper() + release[1][1:] ubuntu_url = "mirrors.ubuntu.com" mirror_list = "http://%s/mirrors.txt" % ubuntu_url print("Getting list of mirrors ...", end=" ") archives = getHTML(mirror_list) print("done.") def parseURL(path): path = path.split('//', 1)[-1] return path.split('/', 1)[0] urls = {} for archive in archives.splitlines(): urls[parseURL(archive)] = None def progressUpdate(processed, total, status=None): if total > 1: stdout.write('\r') percent = int((float(processed) / total) * 100) if not status:
errorExit("Debian is not currently supported", 1) elif release[0] != 'Ubuntu': notUbuntu() directory = '/etc/apt/' apt_file = 'sources.list' sources_path = directory + apt_file if not path.isfile(sources_path): errorExit("%s must exist as file" % sources_path, 1) codename = release[1][0].upper() + release[1][1:] ubuntu_url = "mirrors.ubuntu.com" mirror_list = "http://%s/mirrors.txt" % ubuntu_url print("Getting list of mirrors ...") archives = getHTML(mirror_list) print("done.") def parseURL(path): path = path.split('//', 1)[-1] return path.split('/', 1)[0] urls = {} for archive in archives.splitlines(): urls[parseURL(archive)] = None def progressUpdate(processed, total, message): if total > 1: stdout.write('\r') percent = int((float(processed) / total) * 100) stdout.write("%s [%d/%d] %d%%" % (message, processed, total, percent))