Skip to content
Browse files

ENH: improve history API, better documentation

  • Loading branch information...
1 parent bc2b171 commit 02c3d4f1f05bac926465749ac945e2f7a17d785a Ilan Schnell committed
Showing with 15 additions and 23 deletions.
  1. +2 −2 enstaller/enpkg.py
  2. +12 −20 enstaller/history.py
  3. +1 −1 tests/test_history.py
View
4 enstaller/enpkg.py
@@ -313,7 +313,7 @@ def revert_actions(self, rev_in):
except IndexError:
raise EnpkgError("Error: no such revision: %r" % rev)
- curr = set(h.get_installed())
+ curr = h.get_state()
if state == curr:
print "Nothing to revert"
return []
@@ -336,8 +336,8 @@ def get_history(self):
"""
return a history (h) object:
+ h = Enpkg().get_history()
h.parse() -> list of tuples(datetime strings, set of eggs/diffs)
-
h.construct_states() -> list of tuples(datetime strings, set of eggs)
"""
return History(self.prefixes[0])
View
32 enstaller/history.py
@@ -56,7 +56,7 @@ def __init__(self, prefix):
self.prefix = prefix
if prefix is None:
return
- self._path = join(prefix, 'enpkg.hist')
+ self._log_path = join(prefix, 'enpkg.hist')
def __enter__(self):
if self.prefix is None:
@@ -68,22 +68,15 @@ def __exit__(self, exc_type, exc_value, traceback):
return
self.update()
- def check_for_path(self):
- if not isfile(self._path):
- raise Exception('Error: log file %r not found' % self._path)
-
- def get_installed(self):
- return egginst.get_installed(self.prefix)
-
- def init(self, force=False):
+ def _init_log_file(self, force=False):
"""
- initialize the history file
+ initialize the log file
"""
- if not force and isfile(self._path):
+ if not force and isfile(self._log_path):
return
- fo = open(self._path, 'w')
+ fo = open(self._log_path, 'w')
fo.write(time.strftime("==> %s <==\n" % TIME_FMT))
- for eggname in self.get_installed():
+ for eggname in egginst.get_installed(self.prefix):
fo.write('%s\n' % eggname)
fo.close()
@@ -91,12 +84,12 @@ def update(self):
"""
update the history file (creating a new one if necessary)
"""
- self.init()
+ self._init_log_file()
last = self.get_state()
- curr = set(self.get_installed())
+ curr = set(egginst.get_installed(self.prefix))
if last == curr:
return
- fo = open(self._path, 'a')
+ fo = open(self._log_path, 'a')
fo.write(time.strftime("==> %s <==\n" % TIME_FMT))
for fn in last - curr:
fo.write('-%s\n' % fn)
@@ -109,10 +102,9 @@ def parse(self):
parse the history file and return a list of
tuples(datetime strings, set of eggs/diffs)
"""
- self.check_for_path()
res = []
sep_pat = re.compile(r'==>\s*(.+?)\s*<==')
- for line in open(self._path):
+ for line in open(self._log_path):
line = line.strip()
if not line or line.startswith('#'):
continue
@@ -146,7 +138,8 @@ def construct_states(self):
def get_state(self, arg=None):
"""
return the state, i.e. the set of eggs, for a given revision or time,
- defaults to latest
+ defaults to latest (which is the same as the current state when the
+ log file is up-to-date)
"""
times, pkgs = zip(*self.construct_states())
if arg is None:
@@ -160,7 +153,6 @@ def get_state(self, arg=None):
return pkgs[i]
def print_log(self):
- self.check_for_path()
for i, (dt, cont) in enumerate(self.parse()):
print '%s (rev %d)' % (dt, i)
for line in pretty_cont(cont):
View
2 tests/test_history.py
@@ -11,7 +11,7 @@ class TestHistory(unittest.TestCase):
def setUp(self):
self.history = History('<dummy prefix>')
- self.history._path = PATH
+ self.history._log_path = PATH
def test_find_revision(self):
times = [

0 comments on commit 02c3d4f

Please sign in to comment.
Something went wrong with that request. Please try again.