<commit_before>import getpass
import operator
import os
import sys
import tarfile
import tempfile
import builtins
import click
import yaml
import json
import websocket
import base64

from .comm import change_json, router_request, LOCAL_DEFAULT_USERNAME, LOCAL_DEFAULT_PASSWORD


@click.group()
@click.option('--address', default='192.168.1.1', help='IP address of the ParaDrop device (default=192.168.1.1)')
@click.pass_context
def device(ctx, address):
    """
    Commands to work with a ParaDrop device.
    """
    ctx.obj['address'] = address
    ctx.obj['base_url'] = "http://{}/api/v1".format(address)
    ctx.obj['ws_url'] = "ws://{}//ws".format(address)


@device.group()
@click.pass_context
def chutes(ctx):
    """
    View or install chutes on the router.
    """
    pass


@chutes.command()
@click.pass_context
def list(ctx):
    """
    List chutes installed on the router.
    """
    url = "{}/chutes/".format(ctx.obj['base_url'])
    router_request("GET", url)


@chutes.command()
@click.pass_context
def install(ctx):
    """
    Install a chute from the working directory.
    """
    url = "{}/chutes/".format(ctx.obj['base_url'])
    headers = {'Content-Type': 'application/x-tar'}

    if not os.path.exists("paradrop.yaml"):
        raise Exception("No paradrop.yaml file found in working directory.")

    with tempfile.TemporaryFile() as temp:
        tar = tarfile.open(fileobj=temp, mode="w")
        for dirName, subdirList, fileList in os.walk('.'):
            for fname in fileList:
                path = os.path.join(dirName, fname)
                arcname = os.path.normpath(path)
                tar.add(path, arcname=arcname)
        tar.close()

        temp.seek(0)
        router_request("POST", url, headers=headers, data=temp)


@device.group()
@click.argument('chute_name')
@click.pass_context
def chute(ctx, chute):
    """
    Operations on a chute.
    """
    ctx.obj['chute'] = chute_name
    ctx.obj['chute_url'] = "{}/chutes/{}".format(ctx.obj['base_url'], chute_name)


@chute.command()
@click.pass_context
def start(ctx):
    """
    Start the chute.
    """
    url = ctx.obj['chute_url'] + "/start"
    router_request("POST", url)


@chute.command()
@click.pass_context
def stop(ctx):
    """
    Stop the chute.
    """
    url = ctx.obj['chute_url'] + "/stop"
    router_request("POST", url)<commit_msg>Fixed a minor mistake in pdtools<commit_after>import getpass
import operator
import os
import sys
import tarfile
import tempfile
import builtins
import click
import yaml
import json
import websocket
import base64

from .comm import change_json, router_request, LOCAL_DEFAULT_USERNAME, LOCAL_DEFAULT_PASSWORD


@click.group()
@click.option('--address', default='192.168.1.1', help='IP address of the ParaDrop device (default=192.168.1.1)')
@click.pass_context
def device(ctx, address):
    """
    Commands to work with a ParaDrop device.
    """
    ctx.obj['address'] = address
    ctx.obj['base_url'] = "http://{}/api/v1".format(address)
    ctx.obj['ws_url'] = "ws://{}//ws".format(address)


@device.group()
@click.pass_context
def chutes(ctx):
    """
    View or install chutes on the router.
    """
    pass


@chutes.command()
@click.pass_context
def list(ctx):
    """
    List chutes installed on the router.
    """
    url = "{}/chutes/".format(ctx.obj['base_url'])
    router_request("GET", url)


@chutes.command()
@click.pass_context
def install(ctx):
    """
    Install a chute from the working directory.
    """
    url = "{}/chutes/".format(ctx.obj['base_url'])
    headers = {'Content-Type': 'application/x-tar'}

    if not os.path.exists("paradrop.yaml"):
        raise Exception("No paradrop.yaml file found in working directory.")

    with tempfile.TemporaryFile() as temp:
        tar = tarfile.open(fileobj=temp, mode="w")
        for dirName, subdirList, fileList in os.walk('.'):
            for fname in fileList:
                path = os.path.join(dirName, fname)
                arcname = os.path.normpath(path)
                tar.add(path, arcname=arcname)
        tar.close()

        temp.seek(0)
        router_request("POST", url, headers=headers, data=temp)


@device.group()
@click.argument('chute_name')
@click.pass_context
def chute(ctx, chute_name):
    """
    Operations on a chute.
    """
    ctx.obj['chute'] = chute_name
    ctx.obj['chute_url'] = "{}/chutes/{}".format(ctx.obj['base_url'], chute_name)


@chute.command()
@click.pass_context
def start(ctx):
    """
    Start the chute.
    """
    url = ctx.obj['chute_url'] + "/start"
    router_request("POST", url)


@chute.command()
@click.pass_context
def stop(ctx):
    """
    Stop the chute.
    """
    url = ctx.obj['chute_url'] + "/stop"
    router_request("POST", url)
{'fraction_non_alphanumeric': 0.1547870097005483, 'fraction_numerical': 0.008435259384226065, 'mean_word_length': 3.1825396825396823, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, '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': '3374943', 'n_tokens_mistral': 1621, 'n_tokens_neox': 1577, 'n_words': 364}