Skip to content

Commit

Permalink
Starting work on adding grouping support
Browse files Browse the repository at this point in the history
Basically it works like a standard hierarchy:

    test/hello

Means get the key `hello` from the group `test`. You'll be able to nest
groups into other groups as well:

    test/hello/world

This commit has some progress on this, but is still far from complete
(as you can see by the non-functional set function)

I'm hoping to eventually use this to create remote repository syncing
via a RESTful API. More on that soon.
  • Loading branch information
Steve Gattuso committed Oct 23, 2011
1 parent 328ed3c commit 2a06da0
Showing 1 changed file with 46 additions and 4 deletions.
50 changes: 46 additions & 4 deletions boom.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self):
self.data = pickle.load(f)
f.close()
except (IOError, EOFError):
self.data = {}
self.data = {'keys':{}, 'groups':{}}
self.save()
print("\033[94m [MEH] \033[0m .boom not found. I'll create it for you...")

Expand All @@ -31,13 +31,55 @@ def save(self):
return True

def get(self, key):
key = key.split('/')

# It's a key in the top level
if len(key) == 1:
try:
return self.data['keys'][key]
except KeyError:
return None

# I N C E P T I O N
current = self.data
for group in key:
# The very last value is the key inside of the group
if group is key[-1]:
continue
# Go deeper
try:
current = current['groups'][group]
except KeyError:
return None

# Attempt to get the key
try:
return self.data[key]
return current['keys'][key[-1]]
except KeyError:
return None

def set(self, key, value):
self.data[key] = value
key = key.split('/')

# It's a key in the top level
if len(key) == 1:
self.data['keys'][key] = value

# I N C E P T I O N
current = self.data
for group in key:
# The very last value is the key inside of the group
if group is key[-1]:
continue
# Go deeper
try:
current = current['groups'][group]
except KeyError:
current = {'keys': {}, 'groups': {}}

# Set that key!
current['keys'] = value

self.save()

def list(self):
Expand Down

0 comments on commit 2a06da0

Please sign in to comment.