1 # Module 'packmail' -- create a self-unpacking shell archive.
3 # This module works on UNIX and on the Mac; the archives can unpack
4 # themselves only on UNIX.
7 from stat
import ST_MTIME
12 print 'All fns have a file open for writing as first parameter'
13 print 'pack(f, fullname, name): pack fullname as name'
14 print 'packsome(f, directory, namelist): selected files from directory'
15 print 'packall(f, directory): pack all files from directory'
16 print 'packnotolder(f, directory, name): pack all files from directory'
17 print ' that are not older than a file there'
18 print 'packtree(f, directory): pack entire directory tree'
21 def pack(outfp
, file, name
):
23 outfp
.write('echo ' + name
+ '\n')
24 outfp
.write('sed "s/^X//" >' + name
+ ' <<"!"\n')
30 outfp
.write('X' + line
)
34 # Pack some files from a directory
35 def packsome(outfp
, dirname
, names
):
38 file = os
.path
.join(dirname
, name
)
39 pack(outfp
, file, name
)
41 # Pack all files from a directory
42 def packall(outfp
, dirname
):
43 names
= os
.listdir(dirname
)
53 packsome(outfp
, dirname
, names
)
55 # Pack all files from a directory that are not older than a give one
56 def packnotolder(outfp
, dirname
, oldest
):
57 names
= os
.listdir(dirname
)
66 oldest
= os
.path
.join(dirname
, oldest
)
72 st
= os
.stat(os
.path
.join(dirname
, name
))
73 if st
[ST_MTIME
] >= mtime
:
79 packsome(outfp
, dirname
, todo
)
81 # Pack a whole tree (no exceptions)
82 def packtree(outfp
, dirname
):
83 print 'packtree', dirname
84 outfp
.write('mkdir ' + unixfix(dirname
) + '\n')
85 names
= os
.listdir(dirname
)
96 fullname
= os
.path
.join(dirname
, name
)
97 if os
.path
.isdir(fullname
):
98 subdirs
.append(fullname
)
100 print 'pack', fullname
101 pack(outfp
, fullname
, unixfix(fullname
))
102 for subdirname
in subdirs
:
103 packtree(outfp
, subdirname
)
106 comps
= string
.splitfields(name
, os
.sep
)
110 if res
: res
= res
+ '/'