From CAC Documentation wiki
Jump to navigation Jump to search

I got tired of cutting and pasting to create all of the blank pages for VW's, so I made a python script to do it for me. Basically, you just make a blank aspx (I have a base.aspx if you want it) file (C# directives and the place holder asp:Content tags) and drop it in the directory. Then set up your TOC.txt with the files you'll need.


python filemaker.py z:\vwmodule\base.aspx
 Skipping Computational Steering from TOC.txt.
 default.aspx created OK.
 goals.aspx created OK.
 prerequisites.aspx created OK.
 Whatis.aspx created OK.
 types.aspx created OK.
 basicexamples.aspx created OK.
 interactive_example.aspx created OK.
 approaches.aspx created OK.
 architecture.aspx created OK.
 howto_plan.aspx created OK.
 howto_steerfile.aspx created OK.
 howto_app.aspx created OK.

It's non-destructive, so if a file already exists, it skips it and doesn't overwrite it.

File links: internal: Media:filemaker.py external: at cacvis


import sys
import os
import shutil

def Usage():
    print "python2.5 aspxmaker.py path/to/base.aspx"
    print "   Looks in path/to for default.aspx and TOC.txt"
    print "   and will create all of the aspx files (w/o overwrite)"
    print "   specified in the TOC.txt file"

def createFileFromBase(basedir,newfilename, filetocopy):
    #Check to see if already exists
    fullpath = os.path.join(basedir,newfilename)
    if os.path.exists(fullpath):
        if os.path.isfile(fullpath):
            print "%s already exists, not overwriting" % fullpath
            print "%s appears to be a directory?!?" % fullpath
        return None
    #should be safe to copy
        if str(os.path.getsize(newfilename)) != str(os.path.getsize(filetocopy)):
            raise Error, "%s isn't the same size as the copied file!" % newfilename
        print "%s created OK." % newfilename
    except IOError:
        print "IOError reported for %s, check permissions, continuing" % newfilename
    return 1

def run(base):
    basedir = os.path.dirname(base)
    fid = open(os.path.join(basedir,'TOC.txt'))
        for line in fid:
            if line.strip().endswith('.aspx'):
                createFileFromBase(basedir, line.strip(),base)
                print "Skipping %s from TOC.txt." % line.strip()

if __name__=='__main__':
    if (len(sys.argv) != 2):
    base = sys.argv[1]