def main(): targetDir = "/tmp/sasipedia.vaSection" if os.path.exists(targetDir): shutil.rmtree(targetDir) os.mkdir(targetDir) print >> sys.stderr, "targetDir is: ", targetDir thisDir = os.path.dirname(os.path.realpath(__file__)) dataDir = os.path.join(thisDir, "..", "..", "testData") sections = [ {'id': 'va', 'label': 'Vulnerability Assessment'}, ] # Decorate sections w/ defaults. for section in sections: section['dir'] = os.path.join(dataDir, section['id']) section['metadataFile'] = os.path.join(dataDir, section['id'], 'metadata', '%s.csv' % section['id']) section['metadataAssetsDir'] = os.path.join(dataDir, section['id'], 'metadata', 'assets') section['menuBasePath'] = section['id'] # Create sections lookup. sectionsDict = {} for section in sections: sectionsDict[section['id']] = section # Customize va to use data file as metadata file, # and to use custom renderer. for sectionId in ['va']: section = sectionsDict[sectionId] section['metadataFile'] = os.path.join(dataDir, section['id'], 'data', '%s.csv' % section['id']) section['renderer'] = section_renderers.SectionRenderer( indexTemplate=templates.env.get_template('va_section_index.html') ) renderer = SASIPediaRenderer() renderer.renderSASIPedia( targetDir=targetDir, dataDir=dataDir, sections=sections )
def generate_sasipedia(targetDir=None, dataDir=None): # Create basic section definitions, in the # order in which the sections should be listed. sections = [ {"id": "substrates", "label": "Substrates"}, { "id": "gears", "label": "Gears", "renderer": section_renderers.DefaultSectionRenderer( indexTemplate=templates.env.get_template("gears_section_index.html") ), }, {"id": "energies", "label": "Habitat Energy"}, {"id": "va", "label": "Vulnerability Assessment"}, ] # Decorate sections w/ defaults. for section in sections: section["dir"] = os.path.join(dataDir, section["id"]) section["menuBasePath"] = section["id"] # Create sections lookup. sectionsDict = {} for section in sections: sectionsDict[section["id"]] = section # Customize sections in which the metadata is stored # with the data. for sectionId in ["substrates", "gears", "va", "energies"]: section = sectionsDict.get(sectionId) section["metadataFile"] = os.path.join(dataDir, "%s.csv" % section["id"]) # Add in features section. featureCategoriesPath = os.path.join(dataDir, "feature_categories.csv") featuresPath = os.path.join(dataDir, "features.csv") # Get feature rows. featureRows = {} if os.path.isfile(featuresPath): with open(featuresPath, "rb") as f: featureRows = [row for row in csv.DictReader(f)] featuresData = {"categories": []} if os.path.isfile(featureCategoriesPath): with open(featureCategoriesPath, "rb") as f: for categoryRow in csv.DictReader(f): categoryFeatures = [] for featureRow in featureRows: if featureRow.get("category") == categoryRow["id"]: categoryFeatures.append(featureRow) categoryFeatures.sort(key=lambda r: row.get("label", row.get("id"))) featuresData["categories"].append( { "id": categoryRow["id"], "label": categoryRow.get("label"), "description": categoryRow.get("description"), "features": categoryFeatures, } ) featuresSection = { "id": "features", "label": "Features", "menuBasePath": "features", "data": featuresData, "sort": True, "renderer": section_renderers.FeaturesSectionRenderer(), } sections.append(featuresSection) # Generate model parameters section. paramsPath = os.path.join(dataDir, "model_parameters.csv") if os.path.isfile(paramsPath): with open(paramsPath, "rb") as f: params = csv.DictReader(f).next() paramsSection = { "id": "model_parameters", "label": "Model Parameters", "menuBasePath": "model_parameters", "data": {"params": params}, "renderer": section_renderers.ParametersSectionRenderer(), } sections.append(paramsSection) # Customize va. for sectionId in ["va"]: section = sectionsDict.get(sectionId) if section: indexTemplate = templates.env.get_template("va_section_index.html") section["renderer"] = section_renderers.SectionRenderer(indexTemplate=indexTemplate) renderer = SASIPediaRenderer() renderer.renderSASIPedia(targetDir=targetDir, dataDir=dataDir, sections=sections)
def main(): targetDir = "/tmp/sasipedia" if os.path.exists(targetDir): shutil.rmtree(targetDir) os.mkdir(targetDir) thisDir = os.path.dirname(os.path.realpath(__file__)) dataDir = os.path.join(thisDir, "examples", "dataDirExample") # Set location of overview file. overviewFile = os.path.join(dataDir, 'description.txt') # Create basic section definitions, in the # order in which the sections should be listed. sections = [ {'id': 'substrates', 'label': 'Substrates'}, {'id': 'gears', 'label': 'Gears'}, {'id': 'energies', 'label': 'Habitat Energy'}, {'id': 'efforts', 'label': 'Fishing Efforts'}, {'id': 'model_parameters', 'label': 'Model Parameters'}, {'id': 'bio_features', 'label': 'Biological Features'}, {'id': 'geo_features', 'label': 'Geological Features'}, {'id': 'map_layers', 'label': 'Map Layers'}, {'id': 'glossary', 'label': 'Glossary'}, {'id': 'va', 'label': 'Vulnerability Assessment'}, ] # Decorate sections w/ defaults. for section in sections: section['dir'] = os.path.join(dataDir, section['id']) section['metadataFile'] = os.path.join(dataDir, section['id'], 'metadata', '%s.csv' % section['id']) section['metadataAssetsDir'] = os.path.join(dataDir, section['id'], 'metadata', 'assets') section['menuBasePath'] = section['id'] # Create sections lookup. sectionsDict = {} for section in sections: sectionsDict[section['id']] = section # Customize sections in which the metadata is stored # with the data. for sectionId in ['substrates', 'gears', 'va', 'energies']: section = sectionsDict.get(sectionId) if (section): section['metadataFile'] = os.path.join(dataDir, section['id'], 'data', '%s.csv' % section['id']) # Customize features. for featureCategory in ['bio', 'geo']: section = sectionsDict[featureCategory + '_features'] section['metadataFile'] = os.path.join(dataDir, 'features', 'data', 'features.csv') def categoryFilter(row, category=featureCategory): return row['category'] == category section['reader'] = section_readers.CSVSectionReader( filters=[categoryFilter]) # Customize sections which use description.txt files # for metadata. for sectionId in ['efforts', 'model_parameters']: section = sectionsDict.get(sectionId) if (section): indexTemplate = templates.env.get_template('content_section_index.html') section['metadataFile'] = os.path.join(dataDir, section['id'], 'metadata', 'description.txt') section['reader'] = section_readers.FileSectionReader() section['renderer'] = section_renderers.SectionRenderer( indexTemplate=indexTemplate ) # Customize va. for sectionId in ['va']: section = sectionsDict.get(sectionId) if (section): indexTemplate = templates.env.get_template('va_section_index.html') section['renderer'] = section_renderers.SectionRenderer( indexTemplate=indexTemplate ) renderer = SASIPediaRenderer() renderer.renderSASIPedia( targetDir=targetDir, dataDir=dataDir, overviewFile=overviewFile, sections=sections, )