def test_cfg2dict(): d = {'title': 'temp_title'} with tempdir.TemporaryDirectory() as td: loc_path = os.path.join(td, 'paper_stats.json') options.dict2cfg(d, loc_path) test_d = options.cfg2dict(loc_path) assert test_d == d
def rst2tex(in_path, out_path): options.mkdir_p(out_path) for file in glob.glob(os.path.join(in_path, '*')): shutil.copy(file, out_path) base_dir = os.path.dirname(__file__) scipy_status = os.path.join(base_dir, '_static/status.sty') shutil.copy(scipy_status, out_path) scipy_style = os.path.join(base_dir, '_static/scipy.sty') shutil.copy(scipy_style, out_path) preamble = r'''\usepackage{scipy}''' # Add the LaTeX commands required by Pygments to do syntax highlighting pygments = None try: import pygments except ImportError: import warnings warnings.warn( RuntimeWarning('Could not import Pygments. ' 'Syntax highlighting will fail.')) if pygments: from pygments.formatters import LatexFormatter from writer.sphinx_highlight import SphinxStyle preamble += LatexFormatter(style=SphinxStyle).get_style_defs() settings = { 'documentclass': 'IEEEtran', 'use_verbatim_when_possible': True, 'use_latex_citations': True, 'latex_preamble': preamble, 'documentoptions': 'letterpaper,compsoc,twoside', 'halt_level': 3, # 2: warn; 3: error; 4: severe } try: rst, = glob.glob(os.path.join(in_path, '*.rst')) except ValueError: raise RuntimeError("Found more than one input .rst--not sure which " "one to use.") content = header + open(rst, 'r').read() tex = dc.publish_string(source=content, writer=writer, settings_overrides=settings) stats_file = os.path.join(out_path, 'paper_stats.json') d = options.cfg2dict(stats_file) d.update(writer.document.stats) options.dict2cfg(d, stats_file) tex_file = os.path.join(out_path, 'paper.tex') with open(tex_file, 'w') as f: f.write(tex)
def rst2tex(in_path, out_path): dir_util.copy_tree(in_path, out_path) base_dir = os.path.dirname(__file__) scipy_status = os.path.join(base_dir, '_static/status.sty') shutil.copy(scipy_status, out_path) scipy_style = os.path.join(base_dir, '_static/scipy.sty') shutil.copy(scipy_style, out_path) preamble = r'''\usepackage{scipy}''' # Add the LaTeX commands required by Pygments to do syntax highlighting pygments = None try: import pygments except ImportError: import warnings warnings.warn(RuntimeWarning('Could not import Pygments. ' 'Syntax highlighting will fail.')) if pygments: from pygments.formatters import LatexFormatter from writer.sphinx_highlight import SphinxStyle preamble += LatexFormatter(style=SphinxStyle).get_style_defs() settings = {'documentclass': 'IEEEtran', 'use_verbatim_when_possible': True, 'use_latex_citations': True, 'latex_preamble': preamble, 'documentoptions': 'letterpaper,compsoc,twoside', 'halt_level': 3, # 2: warn; 3: error; 4: severe } try: rst, = glob.glob(os.path.join(in_path, '*.rst')) except ValueError: raise RuntimeError("Found more than one input .rst--not sure which " "one to use.") content = header + open(rst, 'r').read() tex = dc.publish_string(source=content, writer=writer, settings_overrides=settings) stats_file = os.path.join(out_path, 'paper_stats.json') d = options.cfg2dict(stats_file) try: d.update(writer.document.stats) options.dict2cfg(d, stats_file) except AttributeError: print("Error: no paper configuration found") tex_file = os.path.join(out_path, 'paper.tex') with open(tex_file, 'w') as f: f.write(tex)
def rst2tex(in_path, out_path): options.mkdir_p(out_path) for file in glob.glob(os.path.join(in_path, "*")): shutil.copy(file, out_path) base_dir = os.path.dirname(__file__) scipy_status = os.path.join(base_dir, "_static/status.sty") shutil.copy(scipy_status, out_path) scipy_style = os.path.join(base_dir, "_static/scipy.sty") shutil.copy(scipy_style, out_path) preamble = r"""\usepackage{scipy}""" # Add the LaTeX commands required by Pygments to do syntax highlighting pygments = None try: import pygments except ImportError: import warnings warnings.warn(RuntimeWarning("Could not import Pygments. " "Syntax highlighting will fail.")) if pygments: from pygments.formatters import LatexFormatter from writer.sphinx_highlight import SphinxStyle preamble += LatexFormatter(style=SphinxStyle).get_style_defs() settings = { "documentclass": "IEEEtran", "use_verbatim_when_possible": True, "use_latex_citations": True, "latex_preamble": preamble, "documentoptions": "letterpaper,compsoc,twoside", "halt_level": 3, # 2: warn; 3: error; 4: severe } try: rst, = glob.glob(os.path.join(in_path, "*.rst")) except ValueError: raise RuntimeError("Found more than one input .rst--not sure which " "one to use.") content = header + open(rst, "r").read() tex = dc.publish_string(source=content, writer=writer, settings_overrides=settings) stats_file = os.path.join(out_path, "paper_stats.json") d = options.cfg2dict(stats_file) d.update(writer.document.stats) options.dict2cfg(d, stats_file) tex_file = os.path.join(out_path, "paper.tex") with open(tex_file, "w") as f: f.write(tex)
def page_count(pdflatex_stdout, paper_dir): """ Parse pdflatex output for paper count, and store in a .ini file. """ regexp = re.compile('Output written on paper.pdf \((\d+) pages') cfgname = os.path.join(paper_dir,'paper_stats.json') d = options.cfg2dict(cfgname) for line in pdflatex_stdout.splitlines(): m = regexp.match(line) if m: pages = m.groups()[0] d.update({'pages': int(pages)}) break options.dict2cfg(d, cfgname)
def page_count(pdflatex_stdout, paper_dir): """ Parse pdflatex output for paper count, and store in a .ini file. """ if pdflatex_stdout is None: print "*** WARNING: PDFLaTeX failed to generate output." return regexp = re.compile('Output written on paper.pdf \((\d+) pages') cfgname = os.path.join(paper_dir, 'paper_stats.json') d = options.cfg2dict(cfgname, quiet=True) for line in pdflatex_stdout.splitlines(): m = regexp.match(line) if m: pages = m.groups()[0] d.update({'pages': int(pages)}) break options.dict2cfg(d, cfgname)
stats, start = paper_stats(paper_id, start + 1) toc_entries.append(stats) build_paper(paper_id) src_pdf = os.path.join(output_dir, paper_id, 'paper.pdf') dest_pdf = os.path.join(pdf_dir, paper_id+'.pdf') shutil.copy(src_pdf, dest_pdf) command_line = 'cd '+pdf_dir+' ; pdfannotextractor '+paper_id+'.pdf' run = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE) out, err = run.communicate() toc = {'toc': toc_entries} options.dict2cfg(toc, toc_conf) ########NEW FILE######## __FILENAME__ = build_template #!/usr/bin/env python import os import sys import shlex, subprocess import tempita from conf import bib_dir, build_dir, template_dir, html_dir from options import get_config def _from_template(tmpl_basename, config): tmpl = os.path.join(template_dir, tmpl_basename + '.tmpl')
toc_entries.append(stats) build_paper(paper_id) src_pdf = os.path.join(output_dir, paper_id, 'paper.pdf') dest_pdf = os.path.join(pdf_dir, paper_id + '.pdf') shutil.copy(src_pdf, dest_pdf) command_line = 'cd ' + pdf_dir + ' ; pdfannotextractor ' + paper_id + '.pdf' run = subprocess.Popen(command_line, shell=True, stdout=subprocess.PIPE) out, err = run.communicate() toc = {'toc': toc_entries} options.dict2cfg(toc, toc_conf) ########NEW FILE######## __FILENAME__ = build_template #!/usr/bin/env python import os import sys import shlex, subprocess import tempita from conf import bib_dir, build_dir, template_dir, html_dir from options import get_config def _from_template(tmpl_basename, config):
def rst2tex(in_path, out_path): dir_util.copy_tree(in_path, out_path) base_dir = os.path.dirname(__file__) out_file = shutil.copy(status_file, out_path) os.rename(out_file, os.path.join(out_path, 'status.sty')) scipy_style = os.path.join(base_dir, '_static/scipy.sty') shutil.copy(scipy_style, out_path) preamble = u'''\\usepackage{scipy}''' # Add the LaTeX commands required by Pygments to do syntax highlighting pygments = None try: import pygments except ImportError: import warnings warnings.warn( RuntimeWarning('Could not import Pygments. ' 'Syntax highlighting will fail.')) if pygments: from pygments.formatters import LatexFormatter from writer.sphinx_highlight import SphinxStyle preamble += LatexFormatter(style=SphinxStyle).get_style_defs() settings = { 'documentclass': 'IEEEtran', 'use_verbatim_when_possible': True, 'use_latex_citations': True, 'latex_preamble': preamble, 'documentoptions': 'letterpaper,compsoc,twoside', 'halt_level': 3, # 2: warn; 3: error; 4: severe } try: rst, = glob.glob(os.path.join(in_path, '*.rst')) except ValueError: raise RuntimeError("Found more than one input .rst--not sure which " "one to use.") with io.open(rst, mode='r', encoding='utf-8') as f: content = header + f.read() tex = dc.publish_string(source=content, writer=writer, settings_overrides=settings) stats_file = os.path.join(out_path, 'paper_stats.json') d = options.cfg2dict(stats_file) try: d.update(writer.document.stats) options.dict2cfg(d, stats_file) except AttributeError: print("Error: no paper configuration found") tex_file = os.path.join(out_path, 'paper.tex') with io.open(tex_file, mode='wb') as f: try: tex = tex.encode('utf-8') except (AttributeError, UnicodeDecodeError): pass f.write(tex)
build_paper(paper_id, start=start) stats = paper_stats(paper_id, start) start = stats.get('page', {}).get('stop', start) + 1 toc_entries.append(stats) src_pdf = os.path.join(output_dir, paper_id, 'paper.pdf') dest_pdf = os.path.join(pdf_dir, paper_id + '.pdf') shutil.copy(src_pdf, dest_pdf) # load metadata toc = {'toc': toc_entries} scipy_entry = options.cfg2dict(proc_conf) # make dois for papers, then entire proceedings doi_prefix = scipy_entry["proceedings"]["xref"]["prefix"] issn = scipy_entry['series']['xref']['issn'] for paper in toc_entries: paper['doi'] = make_doi(doi_prefix) scipy_entry['proceedings']['doi'] = make_doi(doi_prefix) scipy_entry['series']['doi'] = make_series_doi(doi_prefix, issn) # persist metadata options.dict2cfg(toc, toc_conf) options.dict2cfg(scipy_entry, proc_conf) # make crossref submission file xref = XrefMeta(scipy_entry, toc_entries) xref.make_metadata() xref.write_metadata(xref_conf)
start = stats.get('page',{}).get('stop', start) + 1 toc_entries.append(stats) src_pdf = os.path.join(output_dir, paper_id, 'paper.pdf') dest_pdf = os.path.join(pdf_dir, paper_id+'.pdf') shutil.copy(src_pdf, dest_pdf) for track_dir, folder_ids in other_dirs.items(): track = os.path.split(track_dir)[-1] other_entries[track] = [] for folder in folder_ids: stats = other_stats(track_dir, folder, doi_prefix) other_entries[track].append(stats) # load completed TOC toc = {'toc': toc_entries} # make doi for this year's proceedings and for whole conference (static) scipy_entry['proceedings']['doi'] = make_doi(doi_prefix) if is_final else '' scipy_entry['series']['doi'] = make_series_doi(doi_prefix, issn) # persist metadata options.dict2cfg(toc, toc_conf) options.dict2cfg(other_entries, other_conf) options.dict2cfg(scipy_entry, proc_conf) # make crossref submission file xref = XrefMeta(scipy_entry, toc_entries, other_entries) xref.make_metadata() xref.write_metadata(xref_conf)
build_paper(paper_id, start=start) stats = paper_stats(paper_id, start) start = stats.get('page',{}).get('stop', start) + 1 toc_entries.append(stats) src_pdf = os.path.join(output_dir, paper_id, 'paper.pdf') dest_pdf = os.path.join(pdf_dir, paper_id+'.pdf') shutil.copy(src_pdf, dest_pdf) # load metadata toc = {'toc': toc_entries} scipy_entry = options.cfg2dict(proc_conf) # make dois for papers, then entire proceedings doi_prefix = scipy_entry["proceedings"]["xref"]["prefix"] issn = scipy_entry['series']['xref']['issn'] for paper in toc_entries: paper['doi'] = make_doi(doi_prefix) scipy_entry['proceedings']['doi'] = make_doi(doi_prefix) scipy_entry['series']['doi'] = make_series_doi(doi_prefix, issn) # persist metadata options.dict2cfg(toc, toc_conf) options.dict2cfg(scipy_entry, proc_conf) # make crossref submission file xref = XrefMeta(scipy_entry, toc_entries) xref.make_metadata() xref.write_metadata(xref_conf)