<commit_before>#!/usr/bin/env python
import bcrypt
import bson.binary
import pymongo

client = pymongo.MongoClient()
accounts = client.mr_plotter.accounts

def disp_help(tokens):
    print "Type one of the following commands and press <Enter> or <Return> to execute it:"
    print " ".join(funcs.keys())

def create_funcs():
    help = disp_help
    
    def adduser(tokens):
        if len(tokens) < 3:
            print "Usage: adduser username password [tag1] [tag2] ..."
            return
        username = tokens[1]
        password = tokens[2]
        phash = bcrypt.hashpw(password, bcrypt.gensalt())
        pbin = bson.binary.Binary(phash, bson.binary.USER_DEFINED_SUBTYPE)
        # ALL accounts have the public tag
        tags = set(tokens[3:])
        tags.add("public")
        accounts.update({"user": username}, {"$set": {"password": <PASSWORD>, "tags": tuple(tags)}}, upsert = True)
        
    def setpassword(tokens):
        if len(tokens) != 3:
            print "Usage: setpassword username password"
            return
        username = tokens[1]
        password = <PASSWORD>]
        phash = bcrypt.hashpw(password, bcrypt.gensalt())
        pbin = bson.binary.Binary(phash, bson.binary.USER_DEFINED_SUBTYPE)
        accounts.update({"user": username}, {"$set": {"password": pbin}})
            
    def rmuser(tokens):
        if len(tokens) != 2:
            print "Usage: rmuser username"
            return
        accounts.delete_one({"user": tokens[1]})
            
    def addtags(tokens):
        if len(tokens) < 3:
            print "Usage: addtags username tag1 [tag2] [tag3] ..."
            return
        accounts.update({"user": tokens[1]}, {"$addToSet": {"tags": {"$each": tokens[2:]}}})
            
    def rmtags(tokens):
        if len(tokens) < 3:
            print "Usage: rmtags username tag1 [tag2] [tag3] ..."
            return
        # ALL accounts have the public tag
        tags = set(tokens[2:])
        if "public" in tags:
            tags.remove("public")
        accounts.update({"user": tokens[1]}, {"$pullAll": {"tags": tuple(tags)}})
            
    def lstags(tokens):
        if len(tokens) != 2:
            print "Usage: lstags username"
            return
        account = accounts.find_one({"user": tokens[1]})
        print " ".join(account["tags"])
            
    def lsusers(tokens):
        if len(tokens) != 1:
            print "Usage: lsusers"
            return
        for account in accounts.find():
            print account["user"]
            
    def ls(tokens):
        if len(tokens) != 1:
            print "Usage: ls"
            return
        for account in accounts.find():
            print "{0}: {1}".format(account["user"], " ".join(account["tags"]))
        
    def exit(tokens):
        if len(tokens) != 1:
            print "Usage: exit"
            return
        raise SystemExit
        
    def close(tokens):
        if len(tokens) != 1:
            print "Usage: close"
            return
        raise SystemExit
        
    return locals()
    
funcs = create_funcs()

def exec_statement(string):
    tokens = string.split()
    if len(tokens) == 0:
        return
    
    command = tokens[0]
    if command not in funcs:
        exec_func = disp_help
        print "'{0}' is not a valid command".format(command)
    else:
        exec_func = funcs[command]
    
    exec_func(tokens)
    
if __name__ == "__main__":
    while True:
        try:
            statement = raw_input("Mr. Plotter> ")
        except EOFError:<commit_msg>Make accounts.py take MongoDB hostname and port as command line arguments<commit_after>#!/usr/bin/env python
import bcrypt
import bson.binary
import pymongo
import sys

mongohost = "localhost"
mongoport = 27017

error = False
if len(sys.argv) == 2:
    mongohost = sys.argv[1]
if len(sys.argv) == 3:
    try:
        mongoport = int(sys.argv[2])
    except ValueError:
        error = True

if error or len(sys.argv) > 3:
    print "Usage: {0} [mongo_hostname] [mongoport]".format(sys.argv[0])
    sys.exit()

client = pymongo.MongoClient(mongohost, mongoport)
accounts = client.mr_plotter.accounts

def disp_help(tokens):
    print "Type one of the following commands and press <Enter> or <Return> to execute it:"
    print " ".join(funcs.keys())

def create_funcs():
    help = disp_help

    def adduser(tokens):
        if len(tokens) < 3:
            print "Usage: adduser username password [tag1] [tag2] ..."
            return
        username = tokens[1]
        password = tokens[2]
        phash = bcrypt.hashpw(password, bcrypt.gensalt())
        pbin = bson.binary.Binary(phash, bson.binary.USER_DEFINED_SUBTYPE)
        # ALL accounts have the public tag
        tags = set(tokens[3:])
        tags.add("public")
        accounts.update({"user": username}, {"$set": {"password": pbin, "tags": tuple(tags)}}, upsert = True)

    def setpassword(tokens):
        if len(tokens) != 3:
            print "Usage: setpassword username password"
            return
        username = tokens[1]
        password = tokens[2]
        phash = <PASSWORD>.hashpw(password, bcrypt.gensalt())
        pbin = bson.binary.Binary(phash, bson.binary.USER_DEFINED_SUBTYPE)
        accounts.update({"user": username}, {"$set": {"password": pbin}})

    def rmuser(tokens):
        if len(tokens) != 2:
            print "Usage: rmuser username"
            return
        accounts.delete_one({"user": tokens[1]})

    def addtags(tokens):
        if len(tokens) < 3:
            print "Usage: addtags username tag1 [tag2] [tag3] ..."
            return
        accounts.update({"user": tokens[1]}, {"$addToSet": {"tags": {"$each": tokens[2:]}}})

    def rmtags(tokens):
        if len(tokens) < 3:
            print "Usage: rmtags username tag1 [tag2] [tag3] ..."
            return
        # ALL accounts have the public tag
        tags = set(tokens[2:])
        if "public" in tags:
            tags.remove("public")
        accounts.update({"user": tokens[1]}, {"$pullAll": {"tags": tuple(tags)}})

    def lstags(tokens):
        if len(tokens) != 2:
            print "Usage: lstags username"
            return
        account = accounts.find_one({"user": tokens[1]})
        print " ".join(account["tags"])

    def lsusers(tokens):
        if len(tokens) != 1:
            print "Usage: lsusers"
            return
        for account in accounts.find():
            print account["user"]

    def ls(tokens):
        if len(tokens) != 1:
            print "Usage: ls"
            return
        for account in accounts.find():
            print "{0}: {1}".format(account["user"], " ".join(account["tags"]))

    def exit(tokens):
        if len(tokens) != 1:
            print "Usage: exit"
            return
        raise SystemExit

    def close(tokens):
        if len(tokens) != 1:
            print "Usage: close"
            return
        raise SystemExit

    return locals()

funcs = create_funcs()

def exec_statement(string):
    tokens = string.split()
    if len(tokens) == 0:
        return

    command = tokens[0]
    if command not in funcs:
        exec_func = disp_help
        print "'{0}' is not a valid command".format(command)
    else:
        exec_func = funcs[command]

    exec_func(tokens)

if __name__ == "__main__":
    while True:
        try:
            statement = raw_input("Mr. Plotter> ")
        except EOFError:
{'fraction_non_alphanumeric': 0.13178503915743991, 'fraction_numerical': 0.010667026735079665, 'mean_word_length': 2.097867001254705, 'pattern_counts': {'":': 34, '<': 16, '<?xml version=': 0, '>': 13, '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': '7441505', 'n_tokens_mistral': 2274, 'n_tokens_neox': 2223, 'n_words': 596}