factory/create_page
author Eugen Sawin <sawine@me73.com>
Tue, 06 Jul 2010 22:55:43 +0200
changeset 24 b5b083b0e730
parent 0 d9b71931f372
child 31 837078f56ae2
permissions -rwxr-xr-x
Removed backed files.
     1 #!/usr/bin/python
     2 
     3 import datetime
     4 import sys
     5 from optparse import OptionParser
     6 
     7 content_dir = "v2010"
     8 content_files = ("index.html", "resume.html", "howiwork.html", "personalwork.html", "books.html", "links.html", "contact.html", "chrome.html")
     9 
    10 def create_page(frame_filename, content_filename, output_filename):
    11    frame_file = open(frame_filename, "r")
    12    frame = frame_file.read()
    13    content_file = open(content_filename, "r")
    14    content = content_file.read()
    15    output_file = open(output_filename, "w")
    16    output = frame.replace("/insert{content}", content)
    17    output_file.write(output)
    18    output_file.close()
    19    content_file.close()
    20    frame_file.close()
    21 
    22 def main():
    23    parser = OptionParser()
    24    parser.add_option("-a", "--all", dest="create_all", action="store_true", help="create all pages", default=False)
    25    (options, args) = parser.parse_args()  
    26 
    27    #log_file = open("compile.log", "a")
    28    frame_filename = args[0]
    29 
    30    if options.create_all:
    31       for f in content_files:
    32          content_filename = content_dir + "/" + f
    33          output_file = "../" + f
    34          create_page(frame_filename, content_filename, output_file)
    35    else:
    36       create_page(frame_filename, args[1], args[2])
    37       
    38    #log = "".join(("Update of file ",             
    39     #        args[2],
    40      #       " at ",
    41       #      str(datetime.datetime.now()),
    42        #     ".<br />"))
    43    #log_file.write(log)
    44    #log_file.close()  
    45 
    46 if __name__ == "__main__":
    47    main()
    48