Revision 98093aac kamaki/cli/history.py

b/kamaki/cli/history.py
48 48
        return True
49 49

  
50 50
    def get(self, match_terms=None, limit=0):
51
        print 'HER?', self.filepath
51
        limit = int(limit) or 0
52 52
        with open(self.filepath, 'r') as f:
53 53
            result = ['%s.  \t%s' % (
54 54
                i + 1, line) for i, line in enumerate(f.readlines())
55 55
                if self._match(line, match_terms)]
56
            offset = len(result) - limit if (
57
                limit and len(result) > limit) else 0
58
            return result[offset:]
56
            return result[- limit:]
59 57

  
60 58
    def add(self, line):
61
        f = open(self.filepath, 'a+')
62
        f.write(line + '\n')
63
        f.close()
59
        with open(self.filepath, 'a+') as f:
60
            f.write(line + '\n')
64 61

  
65 62
    def clean(self):
66
        f = open(self.filepath, 'w')
67
        f.close()
63
        with open(self.filepath, 'w'):
64
            pass
68 65

  
69 66
    def retrieve(self, cmd_id):
70 67
        """

Also available in: Unified diff