def generate_sitemap(data, destination_dir, context):        
    TEMPLATE_BASE_DIR = os.path.join('templates', 'sitemap')
    WB_HUC_TEMPLATE = 'waterbudget_huc.xml'
    SF_HUC_TEMPLATE = 'streamflow_huc.xml'
    SF_GAGE_TEMPLATE = 'streamflow_gage.xml'
    PROJECT_TEMPLATE = 'project.xml'
    DATA_TEMPLATE = 'data.xml'
    INDEX_TEMPLATE = 'index.xml'
    HOME_TEMPLATE = 'home.xml'
    sitemap_destination_dir = destination_dir
    gc.make_sure_path_exists(sitemap_destination_dir)
    env = Environment(autoescape=True)
    env.loader = FileSystemLoader(TEMPLATE_BASE_DIR)
    
    print 'Creating sitemap files in %s'  % sitemap_destination_dir
    sitemap_files = []
    sitemap_files.extend(create_sitemaps([{}], HOME_TEMPLATE, sitemap_destination_dir, 'sitemap_home', context, env))
    sitemap_files.extend(create_sitemaps(data['waterbudget_hucs'], WB_HUC_TEMPLATE, sitemap_destination_dir, 'sitemap_wb_huc', context, env))
    sitemap_files.extend(create_sitemaps(data['streamflow_gages'], SF_GAGE_TEMPLATE, sitemap_destination_dir, 'sitemap_sf_gage', context, env))
    sitemap_files.extend(create_sitemaps(data['streamflow_hucs'], SF_HUC_TEMPLATE, sitemap_destination_dir, 'sitemap_sf_huc', context, env))
    sitemap_files.extend(create_sitemaps(data['projects'], PROJECT_TEMPLATE, sitemap_destination_dir, 'sitemap_project', context, env))
    sitemap_files.extend(create_sitemaps(data['datasets'], DATA_TEMPLATE, sitemap_destination_dir, 'sitemap_data', context, env))

    template = env.get_template(INDEX_TEMPLATE)
        
    index_context = context.copy()
    index_context['sitemap_files'] = sitemap_files
    sitemap_file = open(os.path.join(sitemap_destination_dir, 'sitemap.xml'), 'w')    
    sitemap_file.write(template.render(index_context))
    sitemap_file.close()
def generate_skeleton(data, destination_dir, data_config, context):
    TEMPLATE_BASE_DIR = os.path.join('templates', 'skeleton')
    WB_HUC_TEMPLATE = 'waterbudget_huc.html'
    SF_HUC_TEMPLATE = 'streamflow_huc.html'
    SF_GAGE_TEMPLATE = 'streamflow_gage.html'
    PROJECT_TEMPLATE = 'project.html'
    DATA_TEMPLATE = 'data.html'

    skeleton_destination_dir = destination_dir
    gc.make_sure_path_exists(skeleton_destination_dir)

    env = Environment(autoescape=True)
    env.loader = FileSystemLoader(TEMPLATE_BASE_DIR)

    print 'Creating files in %s' % skeleton_destination_dir

    generate_themed_skeletons(data['datasets'], DATA_TEMPLATE, context, {}, '#!data-discovery/dataDetail/', env,
                              skeleton_destination_dir)
    generate_themed_skeletons(data['projects'], PROJECT_TEMPLATE, context, {}, '#!data-discovery/projectDetail/', env,
                              skeleton_destination_dir)
    generate_themed_skeletons(data['streamflow_gages'], SF_GAGE_TEMPLATE, context,
                              data_config.get('streamflow').get('gage'), '#!streamflow-stats/gage/', env,
                              skeleton_destination_dir)
    generate_themed_skeletons(data['streamflow_hucs'], SF_HUC_TEMPLATE, context,
                              data_config.get('streamflow').get('huc12'), '#!streamflow-stats/huc/', env,
                              skeleton_destination_dir)
    generate_themed_skeletons(data['waterbudget_hucs']['huc12'], WB_HUC_TEMPLATE, context,
                              data_config.get('watershed').get('huc12'), '#!waterbudget/huc/', env,
                              skeleton_destination_dir)
    generate_themed_skeletons(data['waterbudget_hucs']['huc08'], WB_HUC_TEMPLATE, context,
                              data_config.get('watershed').get('huc08'), '#!waterbudget/huc/', env,
                              skeleton_destination_dir)
def generate_skeleton(data, destination_dir, context):
    TEMPLATE_BASE_DIR =       os.path.join('templates', 'skeleton')
    DATA_TEMPLATE = 'data.html'
    skeleton_destination_dir = destination_dir
    gc.make_sure_path_exists(skeleton_destination_dir)
    env = Environment(autoescape=True)
    env.loader = FileSystemLoader(TEMPLATE_BASE_DIR)
    
    print 'Creating files in %s'  % skeleton_destination_dir

    generate_themed_skeletons(data['datasets'], DATA_TEMPLATE, context, '#!catalog/gdp/dataset/', env, skeleton_destination_dir)
def main(argv):

    args = gc.parse_args(sys.argv)
    geoserver = args.geoserver
    sciencebase = args.sciencebase_url
    destination_dir = args.destination_dir
    gc.make_sure_path_exists(destination_dir)
    
    context = {
               'root_url' : args.root_url,
               'last_modified' : datetime.datetime.now().strftime('%Y-%m-%d')
               }
    data = gc.get_nwc_data(geoserver, sciencebase)

    generate_sitemap.generate_sitemap(data, os.path.join(destination_dir, 'sitemap'), context)
    generate_skeleton.generate_skeleton(data, os.path.join(destination_dir, 'skeleton'), context)
def generate_sitemap(data, destination_dir, context):        
    TEMPLATE_BASE_DIR = os.path.join('templates', 'sitemap')
    CATALOG_TEMPLATE = 'catalog.xml'
    INDEX_TEMPLATE = 'index.xml'
    HOME_TEMPLATE = 'home.xml'
    sitemap_destination_dir = destination_dir
    gc.make_sure_path_exists(sitemap_destination_dir)
    env = Environment(autoescape=True)
    env.loader = FileSystemLoader(TEMPLATE_BASE_DIR)
    
    print 'Creating sitemap files in %s'  % sitemap_destination_dir
    sitemap_files = []
    sitemap_files.extend(create_sitemaps([{}], HOME_TEMPLATE, sitemap_destination_dir, 'sitemap_home', context, env))
    sitemap_files.extend(create_sitemaps(data['datasets'], CATALOG_TEMPLATE, sitemap_destination_dir, 'sitemap_catalog', context, env))

    template = env.get_template(INDEX_TEMPLATE)
        
    index_context = context.copy()
    index_context['sitemap_files'] = sitemap_files
    sitemap_file = open(os.path.join(sitemap_destination_dir, 'sitemap.xml'), 'w')
    sitemap_file.write(template.render(index_context))
    sitemap_file.close()