def make_default(path, fname=None, post_edit=True): path_values = re.search(r'(?P<dir>.*)\.(?P<userid>.*)__(?P<junk>.*)', configdir.get()).groupdict() default_config_path = "configs/defaults/%(userid)s.py" % path_values # check if it exists if os.path.exists(default_config_path): print "\nwriting default values from %s to current config file\n" % (default_config_path,) # check if one exists and delete it if os.path.exists(path): response = raw_input("you already have a config file - %s \nthis command will override it, do you wish to continue [y/n]: " % path) while response not in ('y', 'n'): response = raw_input('choose only one of [y/n]: ') if response == 'n': sys.exit(1) os.remove(path) make_file(path) with open(path, 'w') as fd: fd.write(open(default_config_path, 'r').read()) if post_edit: run_editor(path) else: print >>sys.stderr, "\ndefault config - %s does not exist. \nadd one or manually edit your local config.\n" % default_config_path
def config_module_to_path(): module_name = configdir.get() pathname = "%s/configs/%s.py" % (os.getcwd(), module_name.replace(".", "/")) return pathname