Skip to content

Instantly share code, notes, and snippets.

@rmacy
Last active December 20, 2015 06:09
Show Gist options
  • Save rmacy/6083606 to your computer and use it in GitHub Desktop.
Save rmacy/6083606 to your computer and use it in GitHub Desktop.
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