Skip to content

Instantly share code, notes, and snippets.

@gnmerritt gnmerritt/
Created Feb 22, 2017

What would you like to do?
Reflux store dependency parser
from __future__ import print_function
import os
import re
import sys
from subprocess import check_output
IMPORT_RE = r".*from '(.*)';"
class RefluxParser(object):
def __init__(self, working_dir):
self.working_dir = working_dir
self.stores = self.find_stores()
def run(self, args, split="\n"):
output_byt = check_output(args)
return output_byt.decode("utf-8").split(split)
def reset(self):
self.deps_by_store = {}
self.paths_by_store = {}
for store in self.stores:
filename = self.store_filename(store)
self.deps_by_store[filename] = set()
self.paths_by_store[filename] = store
def store_filename(self, store):
filename = os.path.basename(store)
return filename.replace(u'.js', '')
def find_stores(self):
return [s for s in['grep', '-rl', 'createStore', '.']) if s]
def process_stores(self):
for store, filename in self.paths_by_store.items():
path = os.path.join(self.working_dir, filename)
if not os.path.isfile(path):
with open(path, 'r') as store_file:
for line in store_file:
if line.find('import ') == 0:
self.check_import(line, store)
def check_import(self, line, store_name):
matches =, line)
if matches:
imported_filename =
imported_store = os.path.basename(imported_filename)
if imported_store in self.deps_by_store:
def print_output(self):
print("digraph reflux {")
for store, deps in self.deps_by_store.items():
for dep in deps:
print(" {} -> {}".format(store, dep))
if __name__ == "__main__":
if not len(sys.argv) == 2:
print("Usage: python <path-to-ui-dir>")
working_dir = sys.argv[1]
parser = RefluxParser(working_dir)
$ python3 'path-to-ui-directory'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.