Created
March 3, 2012 23:10
-
-
Save dcosson/1968853 to your computer and use it in GitHub Desktop.
A post-merge script to go with the ableton-pre-commit.py
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
#!/usr/bin/env python | |
""" Converts all the .xml files back to .als (i.e. gzips them) | |
""" | |
import os | |
import sys | |
import subprocess | |
import gzip | |
ABLETON_FILE_EXT = '.als' | |
CONVERTED_XML_EXT = ABLETON_FILE_EXT + '.xml' | |
### | |
### find path to the root project directory | |
### | |
try: | |
_GIT_DIR = subprocess.check_output(['git', 'rev-parse', '--git-dir']).rstrip('\n').rstrip('\r') # returns the .git dir | |
except subprocess.CalledProcessError: | |
# if not in a git repository, do nothing | |
exit(0) | |
ROOT_DIR = os.path.join(_GIT_DIR, '../') # got one directory up | |
### | |
### Convert xml files back to live sets files | |
### | |
for filepath in filter(lambda x: x.endswith(CONVERTED_XML_EXT), os.listdir(ROOT_DIR)): | |
outfile = filepath.rstrip(CONVERTED_XML_EXT) + ABLETON_FILE_EXT | |
outpath = os.path.join(ROOT_DIR, outfile) | |
with open(filepath, 'r') as f_xml: | |
with gzip.open(outpath, 'w') as f_als: | |
f_als.write(f_xml.read()) | |
print "xml converted back to als file: %s" % (outfile,) | |
sys.exit(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment