Commit 96b09136 authored by Stavros Sachtouris's avatar Stavros Sachtouris

Support old history files

Fixes grnet/kamaki#80

Kamaki history files must have an offset counter on the first line,
since version 0.11.

With this fix, kamaki supports older history files and adds the
default offset counter at the first line.
parent a26565ac
......@@ -18,6 +18,7 @@ Bug fixes
* Handle SSL unicode bug with grace [grnet/kamaki#67]
* Check server status before changing it [grnet/kamaki#57]
* Fix format of "create_volume" return values
* Support old history files [grnet/kamaki#80]
Support
-------
......
......@@ -49,12 +49,19 @@ class History(object):
def __getitem__(self, cmd_ids):
with codecs.open(self.filepath, mode='r', encoding='utf-8') as f:
try:
lines = f.readlines()
self.counter, cmd_list = int(lines[0]), lines[1:]
return cmd_list[cmd_ids]
except IndexError:
return None
try:
self.counter = int(lines[0])
lines = lines[1:]
except ValueError:
# History file format is old, fix it
self.counter = 0
with codecs.open(self.filepath, mode='w', encoding='utf-8') as f:
f.write('0\n%s' % ''.join(lines))
try:
return lines[cmd_ids]
except IndexError:
return None
@property
def limit(self):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment