~abentley/bzrtools/bzrtools.dev

« back to all changes in this revision

Viewing changes to shelf.py

  • Committer: Michael Ellerman
  • Date: 2006-02-21 03:41:11 UTC
  • mto: (0.1.73 shelf-tmp)
  • mto: This revision was merged to the branch mainline in revision 334.
  • Revision ID: michael@ellerman.id.au-20060221034111-04574f50042ef6bf
Add switch command to switch between multiple shelves.
Add show command to show the content of a patch on the current shelf.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
        if name is None:
24
24
            current = os.path.join(self.base, self._paths['current-shelf'])
25
25
            name = open(current).read().strip()
26
 
            assert '\n' not in name
27
26
 
 
27
        assert '\n' not in name
28
28
        self.name = name
 
29
 
29
30
        self.dir = os.path.join(self.base, self._paths['shelves'], name)
30
31
        if not os.path.isdir(self.dir):
31
32
            os.mkdir(self.dir)
43
44
            f.write('default')
44
45
            f.close()
45
46
 
 
47
    def make_default(self):
 
48
        f = open(os.path.join(self.base, self._paths['current-shelf']), 'w')
 
49
        f.write(self.name)
 
50
        f.close()
 
51
        self.log("Default shelf is now '%s'\n" % self.name)
 
52
 
46
53
    def log(self, msg):
47
54
        sys.stderr.write(msg)
48
55
 
49
56
    def delete(self, patch):
50
 
        try:
51
 
            patch = int(patch)
52
 
        except TypeError:
53
 
            raise CommandError("Invalid patch name '%s'" % patch)
54
 
 
55
 
        path = self.__path(patch)
56
 
 
57
 
        if not os.path.exists(path):
58
 
            raise CommandError("Patch '%s' doesn't exist!" % path)
59
 
 
 
57
        path = self.__path_from_user(patch)
60
58
        os.remove(path)
61
59
 
 
60
    def display(self, patch):
 
61
        path = self.__path_from_user(patch)
 
62
        sys.stdout.write(open(path).read())
 
63
 
62
64
    def list(self):
63
65
        self.log("Patches on shelf '%s':" % self.name)
64
66
        indexes = self.__list()
72
74
                msg = "No message saved with patch."
73
75
            self.log(' %.2d: %s\n' % (index, msg))
74
76
 
 
77
    def __path_from_user(self, patch_id):
 
78
        try:
 
79
            patch_id = int(patch_id)
 
80
        except TypeError:
 
81
            raise CommandError("Invalid patch name '%s'" % patch_id)
 
82
 
 
83
        path = self.__path(patch_id)
 
84
 
 
85
        if not os.path.exists(path):
 
86
            raise CommandError("Patch '%s' doesn't exist!" % path)
 
87
 
 
88
        return path
 
89
 
75
90
    def __path(self, index):
76
91
        return os.path.join(self.dir, '%.2d' % index)
77
92