Exemplo n.º 1
0
	def problem_part(part_name, metadata_sorter):
		part_metadata = []
		part_dir = prob.prob_dir + "/" + part_name + "/"
		makedirs_exist_ok(part_dir)

		raw_htmls = []
		for part in getattr(prob, part_name):
			fp = path.join(prob.prob_meta['prob_base'], part_name)

			if (part.endswith('.inline.html')) or (part.endswith('.inline.md')):
				continue

			(content, metadata, url) = get_content_and_metadata(part, fp)
			logger.debug( (part, metadata, content[0:5]))
			if not url:
				name = path.basename(part)
				filename = name + ".html"
				res = apply_template("file.html", problemContent=content,
					name=name, part=part_name, rel_path="{0}/{1}".format(part_name, name), prob=prob,
					**prob.prob_meta)
				write(res, part_name + "/" + filename)
				file_util.copy_file(part, path.join(part_dir, name))
			else:
				filename = path.basename(url)
				name = path.basename(filename)
				file_util.copy_file(part, path.join(part_dir, name))

			part_metadata.append({"name": name, "filename": filename, "meta": metadata})

		prob.parts[part_name] = part_metadata
Exemplo n.º 2
0
def write_problem(prob, apply_template, output_dir, base):
	spec = apply_template(prob.pagetype['base_template'], problemContent=prob.content, type="specification", rel_path='specification.md', prob=prob, **prob.prob_meta)
	makedirs_exist_ok(prob.prob_dir)

	def write(data, name):
		with open(path.join(prob.prob_dir, name), "w", encoding='utf-8') as f:
			f.write(data)

	write(spec, "index.html")

	def problem_part(part_name, metadata_sorter):
		prob.parts[part_name].sort(key = metadata_sorter)
		raw_htmls = []
		for part in getattr(prob, part_name):
			fp = path.join(prob.prob_meta['prob_base'], part_name)

			if (part.endswith('.inline.html')):
				with open(part, encoding='utf-8') as f:
					raw_html = f.read()
				raw_htmls.append(raw_html.strip())
				continue
			elif (part.endswith('.inline.md')):
				(html, _) = convert_markdown(part)
				raw_htmls.append(html.strip())
				continue

		template = apply_template(part_name + ".html", metadata=prob.parts[part_name], rel_path=part_name, prob=prob,
									raw_htmls=raw_htmls, base_template=prob.pagetype['base_template'], **prob.prob_meta)

		write(template, part_name + "/index.html")

	for p in prob.pagetype['parts']:
		problem_part(p[0], p[1])

	refs = apply_template("references.html", references=prob.bib_html, rel_path="references", prob=prob,
		has_bibtex=prob.has_bibtex, notes=prob.ref_notes_html, base_template=prob.pagetype['base_template'], **prob.prob_meta)
	makedirs_exist_ok(path.join(prob.prob_dir, "references"))
	write(refs, "references/index.html")

	# Cite a problem
	# pprint(prob_meta)
	cite = apply_template("problem_cite.html", base_template=prob.pagetype['base_template'], prob=prob, **prob.prob_meta)
	makedirs_exist_ok(path.join(prob.prob_dir, "cite"))
	write(cite, "cite/index.html")

	cite_bib = apply_template("problem_cite.bib", base_template=prob.pagetype['base_template'], prob=prob, **prob.prob_meta)
	write(cite_bib, "cite.bib")

	meta_to_write = create_json_metadata(prob)
	write( json.dumps(meta_to_write, sort_keys=True, indent=2), "../{0}.json".format(prob.name) )
Exemplo n.º 3
0
					else:
						dirpart = 'data'
					src_dst=( path.join(p.prob_meta['prob_base'], pages,  model['name']),
							  path.join(l.name, p.name,dirpart, model['name']) )
					lang_files[l.name].append(src_dst)
					break

write_pages(probs)
write_pages(langs)

# Make problems/cite.bib  with bibtex for citing each problem
cites=[apply_template("cite.bib")]

for prob in sorted(probs):
	old_path = path.join(output_dir, "prob/{0}".format(prob.name))
	makedirs_exist_ok(old_path)
	for fp in ["index.html","spec.html"]:
		with open(path.join(old_path, fp), "w", encoding='utf-8') as f:
			f.write(apply_template("redirect.html", url="/Problems/%s" % prob.name))

	cites.append(apply_template("problem_cite.bib", base_template=prob.pagetype['base_template'], prob=prob, **prob.prob_meta))

logger.debug("authors %s", authors_map.keys())

prob_cite_path = path.join(output_dir, "Problems.bib")
with open(prob_cite_path, "w", encoding='utf-8') as f:
	f.write("\n\n".join(cites))

# Other standalone pages

index_path = path.join(output_dir, "index.html")
Exemplo n.º 4
0
def process_problem(prob, apply_template, output_dir, base):
	"Creates the problem's html"

	(content, metadata) = convert_markdown(prob.specification)
	prob.content = content

	if not "category" in metadata:
		metadata['category'] = ['Unclassified']
	else:
		metadata['category'] = [ m for m in metadata['category'] if m ]
		if len(metadata['category']) == 0:
			metadata['category'] = ['Unclassified']

	metadata['id'] = [prob.name]
	metadata['shortid'] = [prob.name[4:]]
	prob.metadata = metadata

	title = prob.pagetype['title'](metadata)
	prob.prob_meta = {"title": title, "prob_base": prob.pagetype['class_dir'] + "/" + prob.name, "prob_name": prob.name}

	#todo: remove?
	prob.prob_dir = path.join(output_dir, prob.pagetype['class_dir'] +"/{0}".format(prob.name))
	def write(data, name):
		with open(path.join(prob.prob_dir, name), "w", encoding='utf-8') as f:
			f.write(data)


	def problem_part(part_name, metadata_sorter):
		part_metadata = []
		part_dir = prob.prob_dir + "/" + part_name + "/"
		makedirs_exist_ok(part_dir)

		raw_htmls = []
		for part in getattr(prob, part_name):
			fp = path.join(prob.prob_meta['prob_base'], part_name)

			if (part.endswith('.inline.html')) or (part.endswith('.inline.md')):
				continue

			(content, metadata, url) = get_content_and_metadata(part, fp)
			logger.debug( (part, metadata, content[0:5]))
			if not url:
				name = path.basename(part)
				filename = name + ".html"
				res = apply_template("file.html", problemContent=content,
					name=name, part=part_name, rel_path="{0}/{1}".format(part_name, name), prob=prob,
					**prob.prob_meta)
				write(res, part_name + "/" + filename)
				file_util.copy_file(part, path.join(part_dir, name))
			else:
				filename = path.basename(url)
				name = path.basename(filename)
				file_util.copy_file(part, path.join(part_dir, name))

			part_metadata.append({"name": name, "filename": filename, "meta": metadata})

		prob.parts[part_name] = part_metadata

	for p in prob.pagetype['parts']:
		problem_part(p[0], p[1])

	# Copying assets bindly
	prob_dir_in = path.join(base, prob.pagetype['class_dir'] + "/{0}".format(prob.name))
	assets_in = path.join(prob_dir_in, "assets")
	assets_out = path.join(prob.prob_dir, "assets")

	if path.exists(assets_in):
		logger.debug("Copying assets from %s to %s", assets_in, assets_out )
		dir_util.copy_tree(assets_in, assets_out)


	prob.has_bibtex=None
	prob.bib_html=""
	prob.ref_notes_html=""
	if prob.bib:
		makedirs_exist_ok(path.join(prob.prob_dir, "references"))
		file_util.copy_file(prob.bib.bibfile, path.join(prob.prob_dir, "references",  prob.name +"-refs.bib"))
		prob.has_bibtex = True
		prob.bib_html = prob.bib.to_html(apply_template)

	if prob.ref_notes:
		(prob.ref_notes_html, _) = convert_markdown(prob.ref_notes)
Exemplo n.º 5
0
                    src_dst = (path.join(p.prob_meta['prob_base'], pages,
                                         model['name']),
                               path.join(l.name, p.name, dirpart,
                                         model['name']))
                    lang_files[l.name].append(src_dst)
                    break

write_pages(probs)
write_pages(langs)

# Make problems/cite.bib  with bibtex for citing each problem
cites = [apply_template("cite.bib")]

for prob in sorted(probs):
    old_path = path.join(output_dir, "prob/{0}".format(prob.name))
    makedirs_exist_ok(old_path)
    for fp in ["index.html", "spec.html"]:
        with open(path.join(old_path, fp), "w", encoding='utf-8') as f:
            f.write(
                apply_template("redirect.html",
                               url="/Problems/%s" % prob.name))

    cites.append(
        apply_template("problem_cite.bib",
                       base_template=prob.pagetype['base_template'],
                       prob=prob,
                       **prob.prob_meta))

logger.debug("authors %s", authors_map.keys())

prob_cite_path = path.join(output_dir, "Problems.bib")