7
7
from diffstat import DiffStat
8
8
from patchsource import PatchSource, FilePatchSource
12
10
class Shelf(object):
13
11
MESSAGE_PREFIX = "# Shelved patch: "
15
def __init__(self, base, name='default'):
15
'shelves' : '.shelf/shelves',
16
'current-shelf' : '.shelf/current-shelf',
19
def __init__(self, base, name=None):
24
current = os.path.join(self.base, self._paths['current-shelf'])
25
name = open(current).read().strip()
26
assert '\n' not in name
18
shelf_base = os.path.join(self.base, BASE_DIR)
19
self.shelf_dir = os.path.join(shelf_base, name)
29
self.dir = os.path.join(self.base, self._paths['shelves'], name)
30
if not os.path.isdir(self.dir):
21
for dir in [shelf_base, self.shelf_dir]:
34
# Create required directories etc.
35
for dir in [self._paths['base'], self._paths['shelves']]:
36
dir = os.path.join(self.base, dir)
22
37
if not os.path.isdir(dir):
40
current = os.path.join(self.base, self._paths['current-shelf'])
41
if not os.path.exists(current):
42
f = open(current, 'w')
25
46
def log(self, msg):
26
47
sys.stderr.write(msg)
52
73
self.log(' %.2d: %s\n' % (index, msg))
54
75
def __path(self, index):
55
return os.path.join(self.shelf_dir, '%.2d' % index)
76
return os.path.join(self.dir, '%.2d' % index)
57
78
def next_patch(self):
58
79
indexes = self.__list()