<commit_before>"""envRunner

Usage:
  envRunner (-h | --help)
  envRunner <config> exec [COMMAND ...]

Options:
  -h --help   Shows this screen.
  --version
"""
from docopt import docopt
from urlparse import urlparse
import json
import os
import requests
import subprocess
import yaml

def read_local_file(filename):
  _,ext = os.path.splitext(filename)
  ext = ext.lower()

  if ext == ".yaml" or ext == ".yml":
    return _read_yaml_file(filename)
  elif ext == ".js" or ext == ".json":
    return _read_json_file(filename)
  else:
    raise Exception("Could not read" + filename)

def _read_yaml_file(filename):
  return yaml.load(open(filename, "r"))

def _read_json_file(filename):
  return json.load(open(filename, "r"))

if __name__ == '__main__':
  arguments = docopt(__doc__, version='envRunner v0.1')
  parsed_uri = urlparse(arguments["<config>"])

  environment = {}
  if "http" in parsed_uri.scheme:
    #read from web
    pass
  elif "file" in parsed_uri.scheme or parsed_uri.scheme == "":
   environment = read_local_file(parsed_uri.path) 

  for k, v in environment.items():
    print k, "=", v

  env = dict(os.environ, **environment) 
  process = subprocess.Popen(arguments["COMMAND"], env=env)

  process.wait()<commit_msg>Remote config loading<commit_after>"""envRunner

Usage:
  envRunner (-h | --help)
  envRunner <config> exec [COMMAND ...]

Options:
  -h --help   Shows this screen.
  --version
"""
from docopt import docopt
from urlparse import urlparse
import json
import os
import requests
import subprocess
import yaml

def read_local_file(filename):
  _,ext = os.path.splitext(filename)
  ext = ext.lower()

  if ext == ".yaml" or ext == ".yml":
    return _read_yaml_file(filename)
  elif ext == ".js" or ext == ".json":
    return _read_json_file(filename)
  else:
    raise Exception("Could not read" + filename)

def _read_yaml_file(filename):
  return yaml.load(open(filename, "r"))

def _read_json_file(filename):
  return json.load(open(filename, "r"))

def read_remote_file(url):
  r = requests.get(url)

  try:
    return json.loads(r.text)
  except (ValueError):
    return yaml.load(r.text)

if __name__ == '__main__':
  arguments = docopt(__doc__, version='envRunner v0.1')
  parsed_uri = urlparse(arguments["<config>"])

  environment = {}
  if "http" in parsed_uri.scheme:
    #read from web
    environment = read_remote_file(parsed_uri.geturl())
    print environment
  elif "file" in parsed_uri.scheme or parsed_uri.scheme == "":
    environment = read_local_file(parsed_uri.path) 

  env = dict(os.environ, **{ k: str(environment[k]) for k in environment})
  if arguments["exec"]:
    process = subprocess.Popen(arguments["COMMAND"], env=env)
{'fraction_non_alphanumeric': 0.13541666666666666, 'fraction_numerical': 0.001488095238095238, 'mean_word_length': 4.121904761904762, 'pattern_counts': {'":': 6, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3567405', 'n_tokens_mistral': 906, 'n_tokens_neox': 898, 'n_words': 239}