blob: c7bebe89c19c809e30549dacfa621a7fcfb79e13 [file] [log] [blame]
Guido van Rossum217a5fa1990-12-26 15:40:07 +00001# Module 'packmail' -- create a shell script out of some files.
2
3import mac
4import macpath
5from stat import ST_MTIME
6
7# Pack one file
8def pack(outfp, file, name):
9 fp = open(file, 'r')
10 outfp.write('sed "s/^X//" >' + name + ' <<"!"\n')
11 while 1:
12 line = fp.readline()
13 if not line: break
14 if line[-1:] <> '\n':
15 line = line + '\n'
16 outfp.write('X' + line)
17 outfp.write('!\n')
18
19# Pack some files from a directory
20def packsome(outfp, dirname, names):
21 for name in names:
22 print name
23 file = macpath.cat(dirname, name)
24 pack(outfp, file, name)
25
26# Pack all files from a directory
27def packall(outfp, dirname):
28 names = mac.listdir(dirname)
29 names.sort()
30 packsome(outfp, dirname, names)
31
32# Pack all files from a directory that are not older than a give one
33def packnotolder(outfp, dirname, oldest):
34 names = mac.listdir(dirname)
35 oldest = macpath.cat(dirname, oldest)
36 st = mac.stat(oldest)
37 mtime = st[ST_MTIME]
38 todo = []
39 for name in names:
40 print name, '...',
41 st = mac.stat(macpath.cat(dirname, name))
42 if st[ST_MTIME] >= mtime:
43 print 'Yes.'
44 todo.append(name)
45 else:
46 print 'No.'
47 todo.sort()
48 packsome(outfp, dirname, todo)