Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
Add find_coffee_requirements.py so you can find coffee
Browse files Browse the repository at this point in the history
  • Loading branch information
eeue56 authored Oct 26, 2016
1 parent d7bf1bb commit a233d8f
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions find_coffee_requirements
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#! /usr/bin/env python
from __future__ import print_function

import argparse
import re

# = require blah
#= require blah
#= require "blah"
#=require blah
require_regex = re.compile("#[ ]*=[ ]*require[ \"']*(.+?)[\"'\s]+")


def get_require_lines(filename):
require_lines = []

with open(filename) as f:
for line in f:
matches = re.match(require_regex, line)

if matches is not None:
require = matches.groups()[0]
require_lines.append(require)
return require_lines


# get_requirement_filenames(starting_filename: str) -> Tuple[List[str], List[str]]
def get_requirement_filenames(assets_dir, starting_filename):
all_file_names = []
missing_file_names = []

require_lines = get_require_lines(starting_filename)

for require in require_lines:
try:
current_require_lines, current_missing_filenames = get_requirement_filenames(
assets_dir,
"{assets_dir}{require}.js.coffee".format(
assets_dir=assets_dir,
require=require
)
)
all_file_names.extend(current_require_lines)
missing_file_names.extend(current_missing_filenames)
except IOError:
missing_file_names.append(require)
continue

all_file_names.extend(
require for require in require_lines
if require not in missing_file_names
)

return (list(set(all_file_names)), list(set(missing_file_names)))



def main():
parser = argparse.ArgumentParser(description='Check deps matching between a parent and a sub')

# example 'app/assets/javascripts/teach/course-creation-component.js.coffee'
parser.add_argument('filename', help='The file to use for starting the requirement search')
args = parser.parse_args()
parser.add_argument('--asset_dir', help='Asset dir to look into', default='./')

(requirement_filenames, missing_filenames) = get_requirement_filenames(args.asset_dir, args.filename)

print('\n'.join(requirement_filenames))
print('--------------\n But I couldn\'t find the following files:\n\n')
print('\n'.join(missing_filenames))


if __name__ == '__main__':
main()

0 comments on commit a233d8f

Please sign in to comment.