#!/usr/bin/python import portage import urllib2 import os from urlparse import urlparse def fetch_pkgindex(): lines = [] binhost = portage.settings["PORTAGE_BINHOST"] if not binhost: return urldata = urlparse(binhost) tmpdir = "/var/cache/edb/binhost/"+urldata[1]+"/"+urldata[2] if not os.path.exists(tmpdir): try: os.makedirs(tmpdir) except: portage.writemsg(portage.output.red(" *")+" Failed to mkdirs"+tmpdir+"\n") return timestamp = "0" try: fp = open(tmpdir+"/Packages", "r") line = fp.readline() while line: if line[:10] == "TIMESTAMP:": timestamp = line[11:] timestamp = timestamp[:-1] break line = fp.readline() fp.close() except: pass try: fp = urllib2.urlopen(binhost+"/Packages") except: return line = fp.readline() lines.append(line) while line: if line[:10] == "TIMESTAMP:": ts = line[11:] ts = ts[:-1] if ts == timestamp: fp.close() return line = fp.readline() if line: lines.append(line) fp.close() if not lines: return try: fp = open(tmpdir+"/Packages", "w") for line in lines: fp.write(line) fp.close() except: portage.writemsg(portage.output.red(" *")+" Failed to write "+tmpdir+"/Packages\n") if __name__ == "__main__": fetch_pkgindex()