def get_dists_helper(ds,dists): for distfile, dist in ds: fp = distfile #path.join(dir,dist.split("/")[-1]) if fp not in dists: if not path.isfile(fp): print "== Download the dist (%s) to tmp!" % (dist) req = urllib2.Request(dist) try: urllib2.urlopen(req) except urllib2.URLError, e: error("Could not fetch dist file: %s, error: %s" % (dist,e)) except ValueError, e: pass tmpfld = "tmp" if not path.isdir(tmpfld): os.makedirs(tmpfld) file = path.join(tmpfld,dist.split("/")[-1]) urllib.urlretrieve(dist, file) dists.append( file ) else: dists.append( fp ) get_dists_helper(parse(fp)['dist'], dists)
def parse(*args): """ Parse a list of distribution files. Returns a dictionary of path*resource mapping for each type of distribution file operation. """ # set args as file list or find dist files in the oe root dir if args: files = list(args) else: files = [ f for f in os.listdir(".") if f.endswith(".dist") and f[0] not in (".","#") ] # check that all files exist invalid = [f for f in files if not path.isfile(f)] if invalid: error("Could not find the distribution files:\n" + ", ".join(invalid)) # error queue errors = [] # entry dict with types: # git : [(path, resource, branch)] # darcs : [(path, resource)] # data : [(sys, path, resource)] entries = { "darcs":[], "darcs-dev":[], "data":[], "dist":[], "git":[]} # parse each line in each file for file in files: f = open(file, "r") line = 0 for l in f: line += 1 l = l.strip() # ignore blank lines and comments if len(l) == 0 or l[0] == "#": continue # validate entry length e = filter(len, l.split()) if len(e) < 3: errors.append("%s(%i): invalid entry." % (file, line)) # check if the entry path is valid if e[1][0] != "/": errors.append("%s(%i): invalid path '%s'" % (file, line, e[1])) # if no errors were found and the tuple is not in the set add it if not errors: p = path.join(os.getcwd(), e[1][1:]) if e[0] == "darcs": typ = "darcs" elm = (p, e[2]) elif e[0] == "git": typ = "git" branch = "master" if len(e) >= 4: branch = e[3] elm = (p, e[2], branch) elif e[0] == "darcs-dev": typ = "darcs-dev" elm = (p, e[2]) elif e[0] == "dist": typ = "dist" elm = (p, e[2]) else: typ = "data" elm = (e[0], p, e[2]) if elm not in entries[typ]: entries[typ].append(elm) # exit if errors were found if errors: error("\n".join(errors)) return entries