Last active
December 20, 2015 06:09
-
-
Save rmacy/6083606 to your computer and use it in GitHub Desktop.
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
import sys | |
import os | |
import glob | |
def get_contents(file): | |
with open(file, mode='rU') as f: | |
for line in f: | |
yield line | |
def write_contents(file, iterable): | |
with open(file, mode='a') as f: | |
f.writelines(iterable) | |
def squash(final, files): | |
for file in files: | |
write_contents(final, get_contents(file)) | |
def run(): | |
try: | |
if not len(sys.argv) > 2: | |
print("Expecting: [destination_file] (glob pattern) as arguments.") | |
return 1 | |
final = os.path.join(os.getcwd(), sys.argv[1]) | |
files = glob.iglob(os.path.join(os.getcwd(), sys.argv[2])) | |
squash(final, files) | |
return 0 | |
except Exception as e: | |
print(e) | |
return 1 | |
if __name__ == '__main__': | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment