Created
November 15, 2011 21:51
-
-
Save nicferrier/1368492 to your computer and use it in GitHub Desktop.
new vc agnostic veh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_config(repo, rev=None): | |
"""Get the config from the veh root. | |
We try and work out what version control system is being used from | |
the location of the veh config file. | |
We currently only support Mercurial and GIT. | |
The veh.conf MUST exist in the file system though we might read a | |
completly different version of course.""" | |
repo_root = find_root_with_file(".veh.conf", repo) | |
cfgfile = os.path.join(repo_root, '.veh.conf') | |
if not pathexists(cfgfile): | |
raise ConfigMissing(cfgfile) | |
if not rev: | |
with open(cfgfile) as fd: | |
cfg = ConfigParser() | |
cfg.readfp(fd, '.veh.conf') | |
return cfg | |
else: | |
# FIXME: Moar DVCS! Moar! | |
repo_command = None | |
if pathexists(os.path.join(repo_root, ".git")): | |
repo_command = "git show %(rev)s:%(path)s" % { | |
"rev": rev, | |
"path": path | |
} | |
elif pathexists(os.path.join(repo_root, ".hg")): | |
repo_command = "hg cat -r %(rev)s %(path)s" % { | |
"rev": rev, | |
"path": path | |
} | |
if repo_command: | |
# FIXE we need to mark that this is a verion problem? | |
raise ConfigMissing(cfgfile) | |
cfgdata = subprocess.check_output(repo_command.split(" ")) | |
cfg = ConfigParser() | |
cfg.readfp(StringIO(cfgdata), '.veh.conf') | |
return cfg |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment