<commit_before>import web
from models import *
from rdflib import URIRef
from rdflib.Graph import Graph
from utils.site import *
import markdown2
from optparse import OptionParser
from sys import stdout
import os
from os.path import dirname, join, split, splitext, expanduser

config_file = os.path.join(os.path.dirname(__file__), 'config.py')
config = eval(open(config_file).read())

def main():
    # commandline options
    opt_parser = OptionParser()
    opt_parser.set_usage("usage:\n mkstatic.py [options] [output directory]")
    opt_parser.add_option('-l', action="store_true", dest='links', 
                          help='generate links')
    opt_parser.add_option('-p', action="store_true", dest='pubs', 
                          help='generate publications')
    opt_parser.add_option('-c', action="store_true", dest='categories', 
                          help='generate categories')
    opt_parser.add_option('-f', action="store_true", dest='foaf', 
                          help='generate about page from faof')
    opt_parser.add_option('-a', action="store_true", dest='all', 
                          help='generate all')
    opts, args = opt_parser.parse_args()

    if len(args) == 0:
        print opt_parser.usage
        exit()

    basedir = args[0]

    make_directories(basedir)

    if opts.foaf or opts.all:
        foaf(basedir, config['about.uri'])

    if opts.categories or opts.all:
        categories(basedir)
        
    if opts.pubs or opts.all:
        pubs(basedir)
        
    if opts.links or opts.all:
        links(basedir)


# creates a static version of the site

render = web.template.render('templates/', cache=False)
web.template.Template.globals['render'] = render 
web.template.Template.globals['sorted'] = sorted 
web.template.Template.globals['len'] = len
web.template.Template.globals['rel_uri'] = get_relative_uri 
web.template.Template.globals['markdown'] = markdown2.markdown

graph = rdfSubject.db

for root, dirs, files in os.walk(config['site.rdf_dir']):
   for name in files:       
       filename = os.path.join(root, name)
       if filename.endswith('.n3'):
           print filename
           graph.parse(filename, format='n3')

print "triples in graph: " + str(len(graph))

def make_directories(base_dir):
    for dir in ['publications', 'categories', 'links', 'publications/articles', 'publications/books', 'publications/chapters']:
        newdir = os.path.join(base_dir, dir)
        if os.path.isdir(newdir):
            pass
        else:
            os.mkdir(newdir)

person_uri = 'http://bruce.darcus.name/about#me'
me = Person(URIRef(person_uri))

def foaf(basedir, person_uri):
    print "generating about page"
    content = render.about(me).__str__()
    subgraph = get_subgraph(me.resUri)
    write_file(basedir + '/about.rdf', subgraph.serialize())
    write_file(basedir + '/about.xhtml', content)
<commit_msg>switched (another) hard-coded about.uri value to use config instead<commit_after>import web
from models import *
from rdflib import URIRef
from rdflib.Graph import Graph
from utils.site import *
import markdown2
from optparse import OptionParser
from sys import stdout
import os
from os.path import dirname, join, split, splitext, expanduser

config_file = os.path.join(os.path.dirname(__file__), 'config.py')
config = eval(open(config_file).read())

def main():
    # commandline options
    opt_parser = OptionParser()
    opt_parser.set_usage("usage:\n mkstatic.py [options] [output directory]")
    opt_parser.add_option('-l', action="store_true", dest='links', 
                          help='generate links')
    opt_parser.add_option('-p', action="store_true", dest='pubs', 
                          help='generate publications')
    opt_parser.add_option('-c', action="store_true", dest='categories', 
                          help='generate categories')
    opt_parser.add_option('-f', action="store_true", dest='foaf', 
                          help='generate about page from faof')
    opt_parser.add_option('-a', action="store_true", dest='all', 
                          help='generate all')
    opts, args = opt_parser.parse_args()

    if len(args) == 0:
        print opt_parser.usage
        exit()

    basedir = args[0]

    make_directories(basedir)

    if opts.foaf or opts.all:
        foaf(basedir, config['about.uri'])

    if opts.categories or opts.all:
        categories(basedir)
        
    if opts.pubs or opts.all:
        pubs(basedir)
        
    if opts.links or opts.all:
        links(basedir)


# creates a static version of the site

render = web.template.render('templates/', cache=False)
web.template.Template.globals['render'] = render 
web.template.Template.globals['sorted'] = sorted 
web.template.Template.globals['len'] = len
web.template.Template.globals['rel_uri'] = get_relative_uri 
web.template.Template.globals['markdown'] = markdown2.markdown

graph = rdfSubject.db

for root, dirs, files in os.walk(config['site.rdf_dir']):
   for name in files:       
       filename = os.path.join(root, name)
       if filename.endswith('.n3'):
           print filename
           graph.parse(filename, format='n3')

print "triples in graph: " + str(len(graph))

def make_directories(base_dir):
    for dir in ['publications', 'categories', 'links', 'publications/articles', 'publications/books', 'publications/chapters']:
        newdir = os.path.join(base_dir, dir)
        if os.path.isdir(newdir):
            pass
        else:
            os.mkdir(newdir)

person_uri = config['about.uri']
me = Person(URIRef(person_uri))

def foaf(basedir, person_uri):
    print "generating about page"
    content = render.about(me).__str__()
    subgraph = get_subgraph(me.resUri)
    write_file(basedir + '/about.rdf', subgraph.serialize())
    write_file(basedir + '/about.xhtml', content)

{'fraction_non_alphanumeric': 0.12761578044596913, 'fraction_numerical': 0.002058319039451115, 'mean_word_length': 3.0919298245614035, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1715834', 'n_tokens_mistral': 1830, 'n_tokens_neox': 1793, 'n_words': 406}