예제 #1
0
	def link(filename, orig_dir):
		goodfile = join(orig_dir, filename)
		assert goodfile in allfiles

		for (dirpath, dirnames, filenames) in walkfiles:
			for f in filenames:
				if f == filename:
					sym = join(dirpath, f)
					sys.stderr.write("\tLinking %s (to %s)\n" % (path.shorten(sym), path.shorten(goodfile)))
					os.symlink(goodfile, sym)
예제 #2
0
def update_file(file, updates):
	variable_regexes = []
	for var in updates:
		assert valid_variable.match(var)
		grep_variable = "^\s*%s\s*=\s*.*" % fix_dollar.sub('\$', var)
		variable_regexes.append(re.compile(grep_variable))

	sys.stderr.write("Updating: %s\n" % path.shorten(file))
	origfile = file
	if not isfile(origfile):
		tmpl = file + ".tmpl"
		sys.stderr.write("\tNOTE: %s does not exist. Using %s...\n" % (path.shorten(file), path.shorten(tmpl)))
		origfile = tmpl
	assert isfile(origfile)

	newtxt = ""
	newtxt += "\n"
	vars = updates.keys()
	vars.sort()
#	newtxt += "home_dir = \"/home/turian\"\n"
	for var in vars:
		newtxt += "%s = \"%s\";\n" % (var, dir[updates[var]])
	newtxt += "\n"
	newtxt += "\n"

	f = open(origfile, "rt")
	for l in f:
		# Skip any line that matches one of the variables
		found = False
		for r in variable_regexes:
			if r.match(l):
				#sys.stderr.write("Skipping: %s" % l)
				found = True
				break
		if not found: newtxt += l
	f.close()

	newtxt = header + replace_header.sub("", newtxt)
	f = open(file, "wt")
	f.write(newtxt)
	f.close()