#!/usr/bin/python from dt_ParseArgs import parse_args, NO_ARGS from dt_StructuredDoc import StructuredDoc from dt_FilePath import canonical, strip_filename, relative_to import posix, sys, copy ops, args=parse_args( [(['h', 'help'], NO_ARGS, 'display this help and exit'), (['version'], NO_ARGS, 'output version information and exit'), (['r', 'site-root', 'root'], posix.getcwd(), ('ROOT', 'The root of the web pages (ignored)')), (['suffix'], "", ('SUFFIX', 'write modified file with SUFFIX (default=no suffix')), (['s', 'to-stdout'], NO_ARGS, 'write to stdout (default=overwrite file)')], name='dt_remove', usage='Usage: dt_remove [OPTION] CONTENT ...', description='Remove template from CONTENT', version='0.0.1') content_filename_list=args site_root=ops['r'] for content_filename in content_filename_list: try: s=StructuredDoc(from_file=content_filename) except IOError: sys.stderr.write("error: cannot open file \"%s\"\n" % content_filename) sys.exit(1) new_pieces=[] for x in s.pieces: if type(x) is type([]): new_pieces.append(x) s.pieces=new_pieces if ops.has_key('s'): out_file=sys.stdout else: out_file=open(content_filename+ops['suffix'], "w") out_file.write(str(s)) if ops.has_key('s'): out_file.close()