Last active
August 29, 2015 14:12
-
-
Save noisy/d71c4f05f523a2381a04 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import glob | |
| import os | |
| import tarfile | |
| from datetime import datetime | |
| from shutil import copytree, rmtree | |
| from tarfile import ReadError | |
| from git import * | |
| repo = Repo(os.path.dirname(__file__)) | |
| def copy_and_overwrite(from_path, to_path): | |
| if os.path.exists(to_path): | |
| rmtree(to_path) | |
| copytree(from_path, to_path) | |
| data_dir = os.path.join(os.path.dirname(__file__), 'data') | |
| xml_dir = os.path.join(os.path.dirname(__file__), 'xml') | |
| services = [ | |
| 'allegro', | |
| ] | |
| for service in services: | |
| os.chdir(os.path.join(data_dir, service)) | |
| archive_names = glob.glob("*.tar.bz2") | |
| archive_names.sort() | |
| for archive_name in archive_names: | |
| service_xml_dir = os.path.join(xml_dir, service) | |
| unpacked_data_dir = archive_name.replace('.tar.bz2', '') | |
| commit_date = datetime.strptime(unpacked_data_dir, '%Y%m%d%H%M%S') | |
| commit_date_str = commit_date.strftime("%Y-%m-%d %H:%M:%S") | |
| try: | |
| tar = tarfile.open(archive_name) | |
| tar.extractall() | |
| tar.close() | |
| except ReadError, e: | |
| with open(os.path.join(service_xml_dir, 'errors.log'), 'a') as f: | |
| msg = "File %s: %s" % (archive_name, str(e)) | |
| print >> f, msg, | |
| commit_msg = msg | |
| else: | |
| copy_and_overwrite(unpacked_data_dir, service_xml_dir) | |
| rmtree(unpacked_data_dir) | |
| commit_msg = "Service: %s\nDate: %s" % (service, commit_date_str) | |
| repo.index.add([service_xml_dir]) | |
| os.environ["GIT_AUTHOR_DATE"] = os.environ["GIT_COMMITTER_DATE"] = commit_date_str | |
| repo.index.commit(commit_msg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment