Skip to content

Commit

Permalink
Add two new handy methods
Browse files Browse the repository at this point in the history
git-svn-id: svn://cherokee-project.com/CTK/trunk@4726 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information
alobbs committed Apr 5, 2010
1 parent 9820bac commit 9d1c7d2
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions CTK/Config.py
Expand Up @@ -377,3 +377,26 @@ def get_lowest_entry (self, pre):
return entries[0]

return 1

def normalize (self, pre, step=10):
keys = self.keys(pre)
keys.sort (lambda x,y: cmp(int(x),int(y)))

del (self['tmp!normalize'])

n = step
for k in keys:
self.clone ('%s!%s'%(pre, k), 'tmp!normalize!%s!%s'%(pre,n))
n += step

del (self[pre])
self.rename ('tmp!normalize!%s'%(pre), pre)

def apply_chunk (self, chunk):
lines = [l.strip() for l in chunk.split('\n')]
lines = filter (lambda x: len(x) and x[0] != '#', lines)

for line in lines:
left, right = line.split (" = ", 2)
self[left] = right

0 comments on commit 9d1c7d2

Please sign in to comment.