<commit_before>#!/usr/bin/env python

'''
client initialization: part of expfactory package

Copyright (c) 2017, <NAME>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

'''

from glob import glob
import argparse
import sys
import os


def get_parser():

    parser = argparse.ArgumentParser(
    description="expfactory: produce a reproducible battery of container experiments")


    subparsers = parser.add_subparsers(help='Experiment Factory actions',
                                       title='actions',
                                       description='actions for expfactory tools',
                                       dest="command")

    # Users manager
    users = subparsers.add_parser("users",
                                     help="Manager for interacting with users")
    users.add_argument('--new', dest="new",
                       help="generate new user tokens, recommended for headless runtime.",
                       default=None, type=int)

    # List
    listy = subparsers.add_parser("list", 
                                   help="List available Expfactory Experiments from Github")

    # Install
    install = subparsers.add_parser("install", 
                                     help="install an Experiment from Github")

    install.add_argument('src', nargs=1, help='source url or folder of experiment')
    install.add_argument("--folder", dest='folder', 
                          help="empty folder to install experiment, defaults to pwd", 
                          type=str, default=None)

    install.add_argument('--force', '-f',dest="force",
                         help="force installation into non empty directory",
                         default=False, action='store_true')

    install.add_argument("--base",'-b', dest='base', 
                         help="expfactory install base (defaults to application base)",
                         type=str, default=None)


    # Generate Build Recipe
    build = subparsers.add_parser("build", 
                                   help="Build an experiment container (or just recipe)")

    build.add_argument("--output",'-o', dest='output', 
                         help="output name for Dockerfile (if you want a custom path)", 
                         type=str, required=True)

    build.add_argument('experiments', nargs="+",
                        help='experiments to build in image')

    build.add_argument("--studyid", dest='studyid', 
                        help="study id for saving database",
                        type=str, default="expfactory")

    build.add_argument("--database", dest='database', 
                        choices=['fllesystem', 'sqlite'],
                        help="database for application (default filesystem)",
                        type=str, default="filesystem")

    # Experiment Runtime Arguments
    parser.add_argument("--experiments", dest='experiments', 
                         help="comma separated list of experiments for a local battery", 
                         type=str, default=None)

    parser.add_argument("--subid", dest='subid', 
                         help="subject id for saving database",
                         type=str, default=None)

    parser.add_argument("--headless", dest='headless', 
                         help="headless runtime will require generation of tokens or ids.",
                         default=False, action="store_true")

    parser.add_argument('--no-random', dest="disable_randomize",
                         help="present experiments serially",
                         default=True, action='store_false')

    parser.add_argument("--base", dest='base', 
                         help="experiments base (default /scif/apps)",
                         type=str, default=None)

    return parser


def get_subparsers(parser):
    '''get a dictionary of subparsers to help with printing help
    '''
    actions = [action for action in parser._actions 
               if isinstance(action, argparse._SubParsersAction)]

    subparsers = dict()
    for action in actions:
        # get all subparsers and print help
        for choice, subparser in action.choices.items():
            subparsers[choice] = subparser

    return subparsers


def main():

    parser = get_parser()
    subparsers = get_subparsers(parser)

    try:
        args = parser.parse_args()
    except:
        sys.exit(0)

    # Does the use want to install?
    command = args.command

    # Options that shouldn't produce output
    if command in ['users']:
        os.environ['MESSAGELEVEL'] = 0<commit_msg>needs to be string<commit_after>#!/usr/bin/env python

'''
client initialization: part of expfactory package

Copyright (c) 2017, <NAME>
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
  list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
  contributors may be used to endorse or promote products derived from
  this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

'''

from glob import glob
import argparse
import sys
import os


def get_parser():

    parser = argparse.ArgumentParser(
    description="expfactory: produce a reproducible battery of container experiments")


    subparsers = parser.add_subparsers(help='Experiment Factory actions',
                                       title='actions',
                                       description='actions for expfactory tools',
                                       dest="command")

    # Users manager
    users = subparsers.add_parser("users",
                                     help="Manager for interacting with users")
    users.add_argument('--new', dest="new",
                       help="generate new user tokens, recommended for headless runtime.",
                       default=None, type=int)

    # List
    listy = subparsers.add_parser("list", 
                                   help="List available Expfactory Experiments from Github")

    # Install
    install = subparsers.add_parser("install", 
                                     help="install an Experiment from Github")

    install.add_argument('src', nargs=1, help='source url or folder of experiment')
    install.add_argument("--folder", dest='folder', 
                          help="empty folder to install experiment, defaults to pwd", 
                          type=str, default=None)

    install.add_argument('--force', '-f',dest="force",
                         help="force installation into non empty directory",
                         default=False, action='store_true')

    install.add_argument("--base",'-b', dest='base', 
                         help="expfactory install base (defaults to application base)",
                         type=str, default=None)


    # Generate Build Recipe
    build = subparsers.add_parser("build", 
                                   help="Build an experiment container (or just recipe)")

    build.add_argument("--output",'-o', dest='output', 
                         help="output name for Dockerfile (if you want a custom path)", 
                         type=str, required=True)

    build.add_argument('experiments', nargs="+",
                        help='experiments to build in image')

    build.add_argument("--studyid", dest='studyid', 
                        help="study id for saving database",
                        type=str, default="expfactory")

    build.add_argument("--database", dest='database', 
                        choices=['fllesystem', 'sqlite'],
                        help="database for application (default filesystem)",
                        type=str, default="filesystem")

    # Experiment Runtime Arguments
    parser.add_argument("--experiments", dest='experiments', 
                         help="comma separated list of experiments for a local battery", 
                         type=str, default=None)

    parser.add_argument("--subid", dest='subid', 
                         help="subject id for saving database",
                         type=str, default=None)

    parser.add_argument("--headless", dest='headless', 
                         help="headless runtime will require generation of tokens or ids.",
                         default=False, action="store_true")

    parser.add_argument('--no-random', dest="disable_randomize",
                         help="present experiments serially",
                         default=True, action='store_false')

    parser.add_argument("--base", dest='base', 
                         help="experiments base (default /scif/apps)",
                         type=str, default=None)

    return parser


def get_subparsers(parser):
    '''get a dictionary of subparsers to help with printing help
    '''
    actions = [action for action in parser._actions 
               if isinstance(action, argparse._SubParsersAction)]

    subparsers = dict()
    for action in actions:
        # get all subparsers and print help
        for choice, subparser in action.choices.items():
            subparsers[choice] = subparser

    return subparsers


def main():

    parser = get_parser()
    subparsers = get_subparsers(parser)

    try:
        args = parser.parse_args()
    except:
        sys.exit(0)

    # Does the use want to install?
    command = args.command

    # Options that shouldn't produce output
    if command in ['users']:
        os.environ['MESSAGELEVEL'] = "0"
{'fraction_non_alphanumeric': 0.08360396369389625, 'fraction_numerical': 0.001165792322424848, 'mean_word_length': 2.2994505494505493, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7118936', 'n_tokens_mistral': 2996, 'n_tokens_neox': 2715, 'n_words': 1040}