def devlog_to_list_item(devlog, devlog_list_item_template_location, even, simplified): if even: evenorodd = 'even' else: evenorodd = 'odd' if simplified: display = 'none' salient = 'salient_title' nr_of_chars = 350 else: display = 'block' salient = '' nr_of_chars = 150 return fill_template( open(devlog_list_item_template_location).read(), { 'identifier': devlog.identifier, 'title': devlog.title, 'date': devlog.get_pretty_date(), 'lead': devlog.lead[:nr_of_chars], 'tag': devlog.tags[0], 'evenorodd': evenorodd, 'display': display, 'salient_title': salient })
def devlogs_to_rss(devlogs, template_location, item_template_location): rss_items = [] for devlog in devlogs: rss_items.append( fill_template( open(item_template_location).read(), { 'title': devlog.title, 'lead': devlog.lead, 'identifier': devlog.identifier, 'date': format_datetime(devlog.date) })) return fill_template( open(template_location, 'r').read(), { 'items': ''.join(rss_items), 'date': format_datetime(devlog.date) })
def create_page(template_location, title_area_file_location, title, content, page_type, open_graph_tags=None, content_variables=None, portrait_area=None): title_area = open(title_area_file_location).read() if content_variables != None: content = fill_template(content, content_variables) all_variables = { 'title_area': title_area, 'title': title, 'content': content, 'page_type': page_type, 'portrait_area': '', 'open_graph_tags_area': '' } if portrait_area != None: all_variables['portrait_area'] = open(portrait_area).read() if open_graph_tags != None: all_variables[ 'open_graph_tags_area'] = '\t<meta name="twitter:card" content="summary_large_image">\n' for item in open_graph_tags.keys(): all_variables[ 'open_graph_tags_area'] += '\t<meta property="og:' + item + '" content="' + open_graph_tags[ item] + '" />\n' return fill_template(open(template_location).read(), all_variables)
def generate_xsd_namespace(namespace: str, uri: str, schema_loc: str, title: Optional[str] = None) -> str: """ Return a Python module that represents the namespace :param namespace: Namespace to generate (e.g. "xsd") :param uri: Namespace uri (e.g. "http://www.w3.org/2001/XMLSchema#") :param schema_loc: file or URL of XML Schema :param title: Additional title for output file :return: python text for resource """ xs = xmlschema.XMLSchema11( 'https://www.w3.org/2009/XMLSchema/XMLSchema.xsd') schema = xs.to_dict(schema_loc) return fill_template(namespace, _hdr(schema, uri, schema_loc, title), _body(schema, uri))
def generate_namespace(namespace: str, uri: Union[str, URIRef, Namespace], rdf_loc: Union[str, URIRef, Namespace], rdf_format: str = "turtle") -> str: """ Return a Python module that represents the namespace :param namespace: Namespace to generate (e.g. "skos") :param uri: Namespace uri (e.g. "http://www.w3.org/2004/02/skos/core#") :param rdf_loc: file or URL of rdf :param rdf_format: format of RDF :return: text for resource """ g = Graph() # 'manual' format is a hack -- turtle format with accept header if rdf_format == 'manual': g.parse(data=manual(rdf_loc), format="turtle") else: g.load(rdf_loc, format=rdf_format) uri = URIRef(str(uri)) g.bind(namespace.lower(), uri) return fill_template(namespace, _hdr(g, uri, rdf_loc), _body(g, uri))
if batch != "": #template = fill_template(first_row_dict, file_list) file_list = [] batch = row['batch'] first_row_dict = row #batch_dict[batch] = {} #batch_dict[batch]['files'] = [] #batch_dict[batch][''] # str(now) is included for debugging directory = str(now) + row['filename'].replace('.tif', '') if not os.path.exists(directory): os.makedirs(directory + '/content/streams/') ie_file = directory + '/content/ie.xml' dc_file = directory + '/dc.xml' dc_template_string = dc_template(row) with open(dc_file, 'w') as output_file: output_file.write(dc_template_string) #input_file = '../tifs/' +row['filename'] #sha = file_hash(input_file) #file_list.append([input_file, sha]) template = fill_template(row, file_list) move('../tifs/' + row['filename'], directory + '/content/streams') copy(input_file, directory + '/content/streams') with open(ie_file, 'w') as output_file: output_file.write(template)
def generate_static_website(): #Settings PAGES_TO_GENERATE_FOLDER = 'pages_to_generate/' PAGES_TO_COPY_FOLDER = 'pages_to_copy/' DEVLOGS_FOLDER = 'devlogs/' TEMPLATE_FOLDER = 'templates/' MAIN_TEMPLATE_LOCATION = TEMPLATE_FOLDER + 'main_template.html' MAIN_TITLE_AREA_FILE_LOCATION = TEMPLATE_FOLDER + 'main_title_area.html' DEVLOG_TITLE_AREA_FILE_LOCATION = TEMPLATE_FOLDER + 'devlog_title_area.html' DEVLOG_LIST_TITLE_AREA_FILE_LOCATION = TEMPLATE_FOLDER + 'devlog_list_title_area.html' DEVLOG_LIST_ITEM_TEMPLATE_LOCATION = TEMPLATE_FOLDER + 'devlog_list_item_template.html' PORTRAIT_TEMPLATE_LOCATION = TEMPLATE_FOLDER + 'portrait_template.html' RSS_TEMPLATE_LOCATION = TEMPLATE_FOLDER + 'rss_template.xml' RSS_ITEM_TEMPLATE_LOCATION = TEMPLATE_FOLDER + 'rss_item_template.xml' PHP_LOCATION = 'C:/Program Files/php-7.0.9-Win32-VC14-x64/' #PHP_LOCATION = 'C:/Users/wstoop/Downloads/php/php.exe' if isdir('C:/Users/Wessel/Downloads/CivetWeb_Win32+64_V1.9.1/'): CIVETWEB_LOCATION = 'C:/Users/Wessel/Downloads/CivetWeb_Win32+64_V1.9.1/' else: CIVETWEB_LOCATION = 'C:\\Users\\wstoop\\Downloads\\' GOAL_LOCATION = 'docs/' DOMAIN_NAME = 'thesaplinggame.com' STATIC_FOLDER = 'static/' PRESS_FOLDER = 'press/' PRECOMPILED_PRESS_FOLDER = 'press_precompiled/' FRONT_PAGE = 'index.html' DEVLOG_TAGS = ['Announcement', 'Technical', 'Graphics', 'Music'] #Stop the webserver system("taskkill /im Civetweb64.exe") #Empty last if isdir(GOAL_LOCATION): rmtree(GOAL_LOCATION) #Create the goal folder mkdir(GOAL_LOCATION) mkdir(GOAL_LOCATION + 'devlogs/') open(GOAL_LOCATION + 'CNAME', 'w').write(DOMAIN_NAME) #Get images svg_images = get_svg_images([ 'rss_icon', 'devlog_icon', 'twitter_icon', 'steam_icon', 'itch_icon', 'kartridge_icon', 'gamejolt_icon', 'arrow_left', 'arrow_up', 'arrow_right', 'homepage_orange', 'devlog_orange', 'newsletter_orange', 'twitter_orange', 'steam_orange', 'itch_orange' ], STATIC_FOLDER) #Generate devlogs devlogs = [] published_devlogs = [] for filename in listdir(DEVLOGS_FOLDER): if isdir(DEVLOGS_FOLDER + filename): copytree(DEVLOGS_FOLDER + filename, GOAL_LOCATION + DEVLOGS_FOLDER + filename) else: devlog = parse_devlog( filename.split('.')[0], open(DEVLOGS_FOLDER + filename).read(), DEVLOG_TAGS) devlogs.append(devlog) if devlog.published: published_devlogs.append(devlog) devlogs.sort(key=lambda devlog: devlog.date, reverse=True) published_devlogs.sort(key=lambda devlog: devlog.date, reverse=True) for n, devlog in enumerate(devlogs): devlog_url = 'https://' + DOMAIN_NAME + '/devlogs/' + devlog.identifier open_graph_tags = OrderedDict([('title', devlog.title), ('url', devlog_url + '.html'), ('type', 'article'), ('description', devlog.lead), ('image', devlog_url + '/og_image.png') ]) navigation_buttons = create_navigation_buttons( [devlog for devlog in devlogs if devlog.published], n, svg_images) full_content = create_page(MAIN_TEMPLATE_LOCATION, DEVLOG_TITLE_AREA_FILE_LOCATION, devlog.title.upper(), devlog.html + navigation_buttons, 'devlog', portrait_area=PORTRAIT_TEMPLATE_LOCATION, open_graph_tags=open_graph_tags) open(GOAL_LOCATION + 'devlogs/' + devlog.identifier + '.html', 'w').write(full_content) #Generate the devlog listview listview_content = '<h3 class="page_header">DEVLOGS</h3>' for n, devlog in enumerate(published_devlogs): listview_content += devlog_to_list_item( devlog, DEVLOG_LIST_ITEM_TEMPLATE_LOCATION, n % 2 == 0, False) listview_content = create_page(MAIN_TEMPLATE_LOCATION, DEVLOG_LIST_TITLE_AREA_FILE_LOCATION, 'The Sapling', listview_content, 'devlog_list') open(GOAL_LOCATION + 'devlogs/index.html', 'w').write(listview_content) #Generate the devlog rss rss = devlogs_to_rss(devlogs, RSS_TEMPLATE_LOCATION, RSS_ITEM_TEMPLATE_LOCATION) open(GOAL_LOCATION + 'devlogs.rss', 'w').write(rss) #Generate basic pages content_variables = svg_images content_variables['latest_devlog'] = devlog_to_list_item( published_devlogs[0], DEVLOG_LIST_ITEM_TEMPLATE_LOCATION, False, True) for filename in listdir(PAGES_TO_GENERATE_FOLDER): filename_without_extension = filename.split('.')[0] if filename_without_extension == 'index': path = GOAL_LOCATION else: path = GOAL_LOCATION + filename_without_extension mkdir(path) full_content = create_page(MAIN_TEMPLATE_LOCATION, MAIN_TITLE_AREA_FILE_LOCATION, 'The Sapling', open(PAGES_TO_GENERATE_FOLDER + filename).read(), 'main', content_variables=content_variables) open(path + '/index.html', 'w').write(full_content) for filename in listdir(PAGES_TO_COPY_FOLDER): filename_without_extension = filename.split('.')[0] mkdir(GOAL_LOCATION + filename_without_extension) content = open(PAGES_TO_COPY_FOLDER + filename).read() content = fill_template(content, content_variables) open(GOAL_LOCATION + filename_without_extension + '/index.html', 'w').write(content) #Move over the static files copytree(STATIC_FOLDER, GOAL_LOCATION + STATIC_FOLDER) #Make static version of press pages #copytree(PRESS_FOLDER+'images',GOAL_LOCATION+PRESS_FOLDER+'images') #copytree(PRESS_FOLDER+'The Sapling/images',GOAL_LOCATION+PRESS_FOLDER+'The Sapling/images') #generate_press_section(PHP_LOCATION,PRESS_FOLDER,GOAL_LOCATION+PRESS_FOLDER) #Or copy in a precompiled press section copytree(PRECOMPILED_PRESS_FOLDER, GOAL_LOCATION + PRESS_FOLDER) #Landing page if FRONT_PAGE != 'index.html': remove(GOAL_LOCATION + 'index.html') rename(GOAL_LOCATION + FRONT_PAGE, GOAL_LOCATION + 'index.html') #Start the webserver chdir(CIVETWEB_LOCATION) Popen('CivetWeb64.exe')