Skip to content

Instantly share code, notes, and snippets.

@hectorddmx
Last active March 9, 2017 18:11
Show Gist options
  • Select an option

  • Save hectorddmx/8f212434c2938e8d97d001b27e0ee155 to your computer and use it in GitHub Desktop.

Select an option

Save hectorddmx/8f212434c2938e8d97d001b27e0ee155 to your computer and use it in GitHub Desktop.
If you ever need to print all your project files, use this script to join them in a single .txt file.
import fire
import os
from glob import glob
import subprocess
class Fjord(object):
def __init__(self, project_path, file_types, output_path, output_filename):
debugtext = ""
self.project_path = os.path.abspath(os.path.expanduser(project_path))
debugtext += "\nAbsolute project_path is {pp}"\
.format(pp=self.project_path)
self.output_path = os.path.abspath(os.path.expanduser(output_path))
debugtext += "\nAbsolute output_path is {op}"\
.format(op=self.output_path)
self.output_filename = output_filename
self.output_filetxt = "{op}/{of}.txt"\
.format(op=self.output_path, of=self.output_filename)
self.output_filepdf = "{op}/{of}.pdf"\
.format(op=self.output_path, of=self.output_filename)
debugtext += "\nThe output_filetxt is {fnt} and output_filepdf is {fnp}"\
.format(fnt=self.output_filetxt, fnp=self.output_filepdf)
self.file_types = file_types
self.file_list = []
print(debugtext)
def start(self):
for filetype in self.file_types:
self.file_list += self.find_filetype(filetype=filetype)
self.write_joinedfiles()
def find_filetype(self, filetype):
print("Getting filelist for filetype:{f}".format(f=filetype))
result = [y for x in os.walk(self.project_path) for y in glob(os.path.join(x[0], '*.{f}'.format(f=filetype)))]
return result
def write_joinedfiles(self):
print("Joining files in single file")
with open(self.output_filetxt, 'w') as outfile:
for single_file in self.file_list:
if os.path.isfile(single_file):
with open(single_file) as infile:
for line in infile:
outfile.write(line)
subprocess.call(["open", "-R", self.output_filetxt])
if __name__ == '__main__':
"""
Use it like this:
python fjord.py --project-path='./../../' --file-types='swift,m,h' --output-path='~/Desktop' --output-filename='woot' start
"""
fire.Fire(Fjord)
@hectorddmx
Copy link
Author

hectorddmx commented Mar 9, 2017

Just remember to use

pip install fire

And to run it like:

python fjord.py --project-path='./../../' --file-types='swift,m,h' --output-path='~/Desktop' --output-filename='woot' start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment