Skip to content

Instantly share code, notes, and snippets.

@umurkontaci
Created February 26, 2016 21:35
Show Gist options
  • Save umurkontaci/7818f9baaddd9d96b5bb to your computer and use it in GitHub Desktop.
Save umurkontaci/7818f9baaddd9d96b5bb to your computer and use it in GitHub Desktop.
# coding: utf-8
# In[88]:
import json
def loadfile(path):
with open(path, 'r') as f:
return json.loads(f.read())
# In[89]:
import os
def get_files(path):
for f in os.listdir(path):
if f.endswith('.json'):
yield os.path.join(path, f)
# In[90]:
from collections import defaultdict
data = [{'cfg': loadfile(path), 'path': path} for path in get_files('config')]
features = {}
features_seen_in = defaultdict(set)
for item in data:
config = item['cfg']
path = item['path']
if 'features' not in config or not isinstance(config, dict) or not isinstance(config['features'], dict):
continue
seen_features = []
for feature_name, enabled in config['features'].iteritems():
seen_features.append(feature_name)
features_seen_in[feature_name].add(path[7:-5])
if feature_name in features and not features[feature_name]:
features[feature_name] = False
else:
features[feature_name] = enabled
# In[91]:
from itertools import chain
all_envs = set(chain(*features_seen_in.itervalues()))
all_envs
# In[101]:
final = dict([(key, value) for key, value in features.iteritems() if value and features_seen_in[key] == all_envs])
for x in sorted(final.iterkeys()):
print x
# In[ ]:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment