Revision edaf3ba6 kamaki/cli/history.py

b/kamaki/cli/history.py
37 37

  
38 38

  
39 39
class History(object):
40
    def __init__(self, filepath, token=None):
40
    def __init__(self, filepath, token=None, max_lines=0):
41 41
        self.filepath = filepath
42 42
        self.token = token
43
        self.max_lines = max_lines
44

  
45
    def __getitem__(self, cmd_id):
46
        cmd_id = int(cmd_id)
47
        if not cmd_id:
48
            return None
49
        with open(self.filepath) as f:
50
            try:
51
                cmd_list = f.readlines()[:-1]  # exclude current command
52
                return cmd_list[cmd_id - (1 if cmd_id > 0 else 0)]
53
            except IndexError:
54
                return None
43 55

  
44 56
    @classmethod
45 57
    def _match(self, line, match_terms):
......
63 75
        with open(self.filepath, 'a+') as f:
64 76
            f.write(line + '\n')
65 77

  
66
    def clean(self):
78
    def empty(self):
67 79
        with open(self.filepath, 'w'):
68 80
            pass
69 81

  
70
    def retrieve(self, cmd_id):
71
        """
72
        :param cmd_id: (int) the id of the command to retrieve can be positive
73
            or negative, zero values are ignored
82
    def clean(self):
83
        """DEPRECATED in version 0.14"""
84
        return self.empty()
74 85

  
75
        :returns: (str) the stored command record without the id
76
        """
77
        cmd_id = int(cmd_id)
78
        if not cmd_id:
79
            return None
80
        with open(self.filepath) as f:
81
            try:
82
                cmd_list = f.readlines()[:-1]  # exclude current command
83
                return cmd_list[cmd_id - (1 if cmd_id > 0 else 0)]
84
            except IndexError:
85
                return None
86
    def retrieve(self, cmd_id):
87
        """DEPRECATED in version 0.14"""
88
        return self[cmd_id]

Also available in: Unified diff