Skip to content

Instantly share code, notes, and snippets.

@umurkontaci
Created February 26, 2016 21:34
Show Gist options
  • Save umurkontaci/91df8c5a45b10c3a0dc4 to your computer and use it in GitHub Desktop.
Save umurkontaci/91df8c5a45b10c3a0dc4 to your computer and use it in GitHub Desktop.
import json

def loadfile(path):
    with open(path, 'r') as f:
        return json.loads(f.read())
    
import os

def get_files(path):
    for f in os.listdir(path):
        if f.endswith('.json'):
            yield os.path.join(path, f)
            
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
from itertools import chain
all_envs = set(chain(*features_seen_in.itervalues()))
all_envs
{'desktop',
 'desktop-mac-app-store',
 'development',
 'horizon',
 'production',
 'stage',
 'wpcalypso'}
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
community-translator
manage/ads
manage/ads/jetpack
manage/customize
manage/edit-user
manage/jetpack
manage/jetpack-plans
manage/menus
manage/menus-jetpack
manage/pages
manage/people
manage/people/readers
manage/plans
manage/plugins
manage/plugins/browser
manage/posts
manage/security
manage/sharing
manage/site-settings/analytics
manage/site-settings/delete-site
manage/stats
manage/themes
manage/themes-jetpack
me/account
me/billing-history
me/my-profile
me/next-steps
me/notifications
me/security
muse
post-editor
post-editor/iframe-preview
post-editor/live-image-updates
post-editor/pages
reader
reader/activities
reader/discover
reader/following-edit
reader/lists
reader/recommendations
reader/share
reader/teams
settings/security/monitor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment