chester / chester /

Full commit
""" CRUDs the chester file written in JSON.
File is located in ~/.chester by default, change location if you wish.

import os.path
import json

LIST_PATH = os.path.expanduser('~') + "/.chester"

class Actions:
        Copies JSON to dictionary, does CRUD actions, and outputs JSON to file.
    def __init__(self):
            Open JSON file and load contents to dictionary.
        """ = {}
        if not os.path.exists(LIST_PATH):
            with open(LIST_PATH, "w") as f:
                json.dump(, f)
        with open(LIST_PATH, 'r') as f:
   = json.load(f)
    def create(self, sublist):
            Creates a new sublist in the master list.
        """[sublist] = {}
        print "{0} (sublist) created".format(sublist)
    def add(self, sublist, entry, value=""):
            Adds an element to specified sublist.
        """[sublist][entry] = value
        print "{0} {1} added to {2}".format(entry, value, sublist)
    def delete(self, sublist, entry='', value=''):
            Deletes a complete sublist or single entry.
        if sublist and not entry and not value:
            print "{0} (sublist) deleted".format(sublist)
        elif sublist and entry and value == "delete":

    def overview(self):
            Prints all sublist entries with number of elements.
        print "-------\nCHESTER\n-------"
        for entry in
            print "\t{0}({1})".format(entry, len([entry]))

    def show(self, sublist='', entry=''):
            Prints elements of each sublist according to the params supplied.
            if no params passed, shows all sublists with elements.
            if sublist is given, shows all elements in the sublist.
            if sublist and entry params are given, shows associated value.
        print "-------\nCHESTER\n-------"
        if sublist and not entry:
            for item in
                if item == sublist:
                    print "({0})\n".format(item)
                    for element in[item]:
                        value =[item][element]
                        print "\t{0} ~ {1}".format(element, value)
        elif sublist and entry:
            for item in
                print "({0})".format(item)
                for element in[item]:
                    # TODO: add a "smart" delimiter. "by" "-" ":" "~"
                    value =[item][element]
                    print "\t{0} ~ {1}".format(element, value)

    def help(self):
            Prints a help menu.
        print "help on the way..."
        help = """
Command             Description
-------             -----------
chester             Displays an overview
chester all         Displays every list and elements

chester <list name>     Creates a sublist or displays it

        print help

    def save(self):
            Saves dictionary to JSON file.
        with open(LIST_PATH, 'w') as f:
            json.dump(, f, indent=2)