1 # Extract files from a SHAR archive.
10 def unshar(fp
, verbose
=0, overwrite
=0):
15 if verbose
> 3: print 'Got:', `line`
17 # Most common case first
18 if ofp
: ofp
.write(line
[1:])
21 if verbose
: print 'EOF'
23 print 'Unterminated file -- closing'
28 if verbose
: print line
,
30 if line
[:14] == 'sed "s/^X//" >':
31 if verbose
: print "!!!", `line`
32 i
= string
.find(line
, "'")
33 j
= string
.find(line
, "'", i
+1)
37 words
= string
.splitfields(file, '/')
39 while funny
in words
: words
.remove(funny
)
40 for i
in range(len(words
)):
41 if words
[i
] == '..': words
[i
] = ''
43 file = string
.joinfields(words
, ':')
51 if over
and not overwrite
:
52 print 'Skipping', file, '(already exists) ...'
56 print 'Overwriting', file, '...'
58 print 'Writing', file, '...'
60 if line
== 'END_OF_FILE\n':
62 print 'Unexpected END_OF_FILE marker'
71 if verbose
: print "...", `line`