Guido van Rossum | 217a5fa | 1990-12-26 15:40:07 +0000 | [diff] [blame^] | 1 | # Module 'packmail' -- create a shell script out of some files. |
| 2 | |
| 3 | import mac |
| 4 | import macpath |
| 5 | from stat import ST_MTIME |
| 6 | |
| 7 | # Pack one file |
| 8 | def 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 |
| 20 | def 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 |
| 27 | def 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 |
| 33 | def 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) |