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
11 print 'All fns have a file open for writing as first parameter'
12 print 'pack(f, fullname, name): pack fullname as name'
13 print 'packsome(f, directory, namelist): selected files from directory'
14 print 'packall(f, directory): pack all files from directory'
15 print 'packnotolder(f, directory, name): pack all files from directory'
16 print ' that are not older than a file there'
17 print 'packtree(f, directory): pack entire directory tree'
20 def pack(outfp
, file, name
):
22 outfp
.write('echo ' + name
+ '\n')
23 outfp
.write('sed "s/^X//" >"' + name
+ '" <<"!"\n')
29 outfp
.write('X' + line
)
33 # Pack some files from a directory
34 def packsome(outfp
, dirname
, names
):
37 file = os
.path
.join(dirname
, name
)
38 pack(outfp
, file, name
)
40 # Pack all files from a directory
41 def packall(outfp
, dirname
):
42 names
= os
.listdir(dirname
)
52 packsome(outfp
, dirname
, names
)
54 # Pack all files from a directory that are not older than a give one
55 def packnotolder(outfp
, dirname
, oldest
):
56 names
= os
.listdir(dirname
)
65 oldest
= os
.path
.join(dirname
, oldest
)
71 st
= os
.stat(os
.path
.join(dirname
, name
))
72 if st
[ST_MTIME
] >= mtime
:
78 packsome(outfp
, dirname
, todo
)
80 # Pack a whole tree (no exceptions)
81 def packtree(outfp
, dirname
):
82 print 'packtree', dirname
83 outfp
.write('mkdir ' + unixfix(dirname
) + '\n')
84 names
= os
.listdir(dirname
)
95 fullname
= os
.path
.join(dirname
, name
)
96 if os
.path
.isdir(fullname
):
97 subdirs
.append(fullname
)
99 print 'pack', fullname
100 pack(outfp
, fullname
, unixfix(fullname
))
101 for subdirname
in subdirs
:
102 packtree(outfp
, subdirname
)
105 comps
= name
.split(os
.sep
)
109 if res
: res
= res
+ '/'