3 This script copies the files in one directory to another, expanding any SSI
4 <!-- #include --> statements it encounters along the way.
8 ./ssi_expander.py [source_directory] destination_directory
10 If source_directory is not specified, then the current directory is used.
17 def process(source
, dest
):
18 for dirpath
, dirnames
, filenames
in os
.walk(source
):
19 dest_dir
= os
.path
.realpath(os
.path
.join(dest
, os
.path
.relpath(dirpath
, source
)))
20 if not os
.path
.exists(dest_dir
):
22 assert os
.path
.isdir(dest_dir
)
23 for filename
in filenames
:
24 src_path
= os
.path
.abspath(os
.path
.join(source
, dirpath
, filename
))
25 dest_path
= os
.path
.join(dest_dir
, filename
)
26 if not filename
.endswith('.html'):
27 os
.symlink(src_path
, dest_path
)
29 file(dest_path
, 'w').write(ssi
.InlineIncludes(src_path
))
31 # ignore hidden directories
32 for dirname
in dirnames
[:]:
33 if dirname
.startswith('.'):
34 dirnames
.remove(dirname
)
37 if __name__
== '__main__':
38 if len(sys
.argv
) == 2:
41 elif len(sys
.argv
) == 3:
42 source
, dest
= sys
.argv
[1:]
44 sys
.stderr
.write('Usage: %s [source_directory] destination_directory\n' % sys
.argv
[0])