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

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]
......@@ -49,12 +49,19 @@ class History(object):
def __getitem__(self, cmd_ids):
with, mode='r', encoding='utf-8') as f:
lines = f.readlines()
self.counter, cmd_list = int(lines[0]), lines[1:]
return cmd_list[cmd_ids]
except IndexError:
return None
self.counter = int(lines[0])
lines = lines[1:]
except ValueError:
# History file format is old, fix it
self.counter = 0
with, mode='w', encoding='utf-8') as f:
f.write('0\n%s' % ''.join(lines))
return lines[cmd_ids]
except IndexError:
return None
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