# Module 'packmail' -- create a self-unpacking shell archive.
# This module works on UNIX and on the Mac; the archives can unpack
# themselves only on UNIX.
from stat
import ST_MTIME
print 'All fns have a file open for writing as first parameter'
print 'pack(f, fullname, name): pack fullname as name'
print 'packsome(f, directory, namelist): selected files from directory'
print 'packall(f, directory): pack all files from directory'
print 'packnotolder(f, directory, name): pack all files from directory'
print ' that are not older than a file there'
print 'packtree(f, directory): pack entire directory tree'
def pack(outfp
, file, name
):
outfp
.write('echo ' + name
+ '\n')
outfp
.write('sed "s/^X//" >"' + name
+ '" <<"!"\n')
# Pack some files from a directory
def packsome(outfp
, dirname
, names
):
file = os
.path
.join(dirname
, name
)
# Pack all files from a directory
def packall(outfp
, dirname
):
names
= os
.listdir(dirname
)
packsome(outfp
, dirname
, names
)
# Pack all files from a directory that are not older than a give one
def packnotolder(outfp
, dirname
, oldest
):
names
= os
.listdir(dirname
)
oldest
= os
.path
.join(dirname
, oldest
)
st
= os
.stat(os
.path
.join(dirname
, name
))
if st
[ST_MTIME
] >= mtime
:
packsome(outfp
, dirname
, todo
)
# Pack a whole tree (no exceptions)
def packtree(outfp
, dirname
):
print 'packtree', dirname
outfp
.write('mkdir ' + unixfix(dirname
) + '\n')
names
= os
.listdir(dirname
)
fullname
= os
.path
.join(dirname
, name
)
if os
.path
.isdir(fullname
):
pack(outfp
, fullname
, unixfix(fullname
))
for subdirname
in subdirs
:
packtree(outfp
, subdirname
)
comps
= name
.split(os
.sep
)