<commit_before>#!/usr/bin/env python
import os
import re
import sys
from string import Template
from shutil import copytree

def usage():
    return "Usage: python start-project.py < path to project directory > < object name > < OPTIONAL key=value pairs to override template variables >"

def main(args):
    try:
        pdir = os.path.abspath(args[1])
        biothing_name = args[2]
        clargs = dict([arg.split('=', maxsplit=1) for arg in sys.argv[3:]])
    except:
        print("Valid project destination directory and object name must be included.")
        print(usage())
        sys.exit(1)

    cwd = os.getcwd()
    template_dir = os.path.join(os.path.dirname(os.path.realpath(__file__)), 'biothings_templates')

    if not os.path.exists(template_dir):
        print("Could not find template directory.  Exiting.")
        sys.exit(1)

    # create settings dict
    settings_dict = {
        "src_package": 'my' + biothing_name.lower(),
        "settings_class": "My" + biothing_name.title() + "Settings",
        "annotation_endpoint": biothing_name.lower(),
        "query_endpoint": "query",
        "annotation_handler_name": biothing_name.title() + "Handler",
        "query_handler_name": "QueryHandler",
        "es_doctype": biothing_name.lower(),
        "base_url": "My" + biothing_name.title() + ".info"
    }

    # override any key value pairs from the command line
    settings_dict.update(clargs)
    
    # Make top level directory
    pdir = os.path.join(pdir, settings_dict["src_package"])
    os.mkdir(pdir)

    # Start to template files out
    os.chdir(template_dir)

    # Template files out<commit_msg>Getting closer to a django like install.<commit_after>#!/usr/bin/env python
import os
import re
import sys
import biothings
from string import Template
from shutil import copytree

def usage():
    return "Usage: python start-project.py < path to project directory > < object name > < OPTIONAL key=value pairs to override template variables >"

def main(args):
    try:
        pdir = os.path.abspath(args[1])
        biothing_name = args[2]
        clargs = dict([arg.split('=', maxsplit=1) for arg in sys.argv[3:]])
    except:
        print("Valid project destination directory and object name must be included.")
        print(usage())
        sys.exit(1)

    cwd = os.getcwd()
    template_dir = os.path.join(os.path.split(biothings.__file__)[0], 'conf', 'biothings_templates')

    if not os.path.exists(template_dir):
        print("Could not find template directory.  Exiting.")
        sys.exit(1)

    # create settings dict
    settings_dict = {
        "src_package": 'my' + biothing_name.lower(),
        "settings_class": "My" + biothing_name.title() + "Settings",
        "annotation_endpoint": biothing_name.lower(),
        "query_endpoint": "query",
        "annotation_handler_name": biothing_name.title() + "Handler",
        "query_handler_name": "QueryHandler",
        "es_doctype": biothing_name.lower(),
        "base_url": "My" + biothing_name.title() + ".info"
    }

    # override any key value pairs from the command line
    settings_dict.update(clargs)
    
    # Make top level directory
    pdir = os.path.join(pdir, settings_dict["src_package"])
    os.mkdir(pdir)

    # Start to template files out
    os.chdir(template_dir)

    # Template files out
{'fraction_non_alphanumeric': 0.12098468928249775, 'fraction_numerical': 0.003902731912338637, 'mean_word_length': 3.11358024691358, 'pattern_counts': {'":': 16, '<': 9, '<?xml version=': 0, '>': 9, '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': '2624755', 'n_tokens_mistral': 1029, 'n_tokens_neox': 1011, 'n_words': 268}