def main(data_path: str, send: bool = False):
    scipy_proc = options.cfg2dict(proc_conf)
    proceedings = scipy_proc["proceedings"]

    template = "author-invitation.txt"

    # we don't know what the author dump will look like yet, so we may need
    # to tweak this later
    # current assumption is that we will have table with fields for the
    # author's name, email address, and the paper title
    data = pd.read_csv(data_path)

    email_data = []
    for label, row in data.iterrows():
        one_email = deepcopy(scipy_proc)
        one_email["cc_emails"] = one_email["proceedings"]["editor_email"]
        one_email["to_name"] = row["name"]
        one_email["to_emails"] = [row["email"]]
        one_email["title"] = row["title"]
        one_email[
            "subject"] = f"Invitation to submit a full paper for {proceedings['title']['acronym']} {proceedings['year']}"
        email_data.append(one_email)

    mailer = Mailer(template, send)
    mailer.send_all(email_data)
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 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
Exemple #4
0
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 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 tex2pdf_singlepass(out_path):
    """
    Returns
    -------
    out : str
        LaTeX output.
    retry : bool
        Whether another round of building is needed.
    """

    import subprocess
    command_line = 'pdflatex -halt-on-error paper.tex'

    # -- dummy tempfile is a hacky way to prevent pdflatex
    #    from asking for any missing files via stdin prompts,
    #    which mess up our build process.
    dummy = tempfile.TemporaryFile()

    run = subprocess.Popen(command_line, shell=True,
            stdin=dummy,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            cwd=out_path,
            )
    out, err = run.communicate()

    if b"Fatal" in out or run.returncode:
        print("PDFLaTeX error output:")
        print("=" * 80)
        print(out)
        print("=" * 80)
        if err:
            print(err)
            print("=" * 80)

        # Errors, exit early
        return out, False

    # Compile BiBTeX if available
    stats_file = os.path.join(out_path, 'paper_stats.json')
    d = options.cfg2dict(stats_file)
    bib_file = os.path.join(out_path, d["bibliography"] + '.bib')

    if os.path.exists(bib_file):
        bibtex_cmd = 'bibtex paper && ' + command_line
        run = subprocess.Popen(bibtex_cmd, shell=True,
                stdin=dummy,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                cwd=out_path,
                )
        out_bib, err = run.communicate()
        if err or b'Error' in out_bib:
            print("Error compiling BiBTeX")
            return out_bib, False

    if b"Label(s) may have changed." in out:
        return out, True

    return out, False
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)
Exemple #8
0
def main(send: bool = False):

    scipy_proc = options.cfg2dict(proc_conf)
    proceedings = scipy_proc["proceedings"]
    # the doi data is importable via the config module
    toc = options.cfg2dict(toc_conf)

    template = "doi-notification.txt"

    email_data = []
    for paper in toc["toc"]:
        one_email = deepcopy(scipy_proc)
        one_email.update(paper)
        one_email["cc_emails"] = one_email["proceedings"]["editor_email"]
        one_email["to_name"] = author_greeting(one_email["author"])
        one_email["to_emails"] = paper["author_email"]
        one_email[
            "subject"] = f"Your {proceedings['title']['acronym']} {proceedings['year']} Paper DOI"
        email_data.append(one_email)
    mailer = Mailer(template, send)
    mailer.send_all(email_data)
def other_stats(track_dir, _id, doi_prefix=None):
    """Pull in stats of slides, return stats and the next paper
    """

    stats = options.cfg2dict(os.path.join(track_dir, _id, 'info.json'))
    doi = make_doi(doi_prefix)

    print('"%s" other entry' % (_id))

    # Build table of contents
    stats.update({
                  'slide_id': _id,
                  'doi': doi if is_final else ''
                })

    return stats
def paper_stats(paper_id, start):
    """Pull in stats of paper, return stats and the next paper 
    """
    stats = options.cfg2dict(os.path.join(output_dir, paper_id, 'paper_stats.json'))

    pages = stats.get('pages', 1)
    stop = start + pages - 1

    print('"%s" from p. %s to %s' % (paper_id, start, stop))

    # Build table of contents
    stats.update({'page': {'start': start,
                           'stop': stop},
                  'paper_id': paper_id
                 })
    
    return stats 
Exemple #11
0
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.
   """

   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 paper_stats(paper_id, start, doi_prefix=None):
    """Pull in stats of paper, return stats and the next paper
    """
    stats = options.cfg2dict(os.path.join(output_dir, paper_id, 'paper_stats.json'))

    pages = stats.get('pages', 1)
    stop = start + pages - 1
    paper_doi = make_doi(doi_prefix)

    print('"%s" from p. %s to %s' % (paper_id, start, stop))

    # Build table of contents
    stats.update({'page': {'start': start,
                           'stop': stop},
                  'paper_id': paper_id,
                  'doi': paper_doi if is_final else ''
                 })

    return stats
Exemple #14
0
def paper_stats(paper_id, start):
    stats = options.cfg2dict(os.path.join(output_dir, paper_id, 'paper_stats.json'))

    # Write page number snippet to be included in the LaTeX output
    if 'pages' in stats:
        pages = stats['pages']
    else:
        pages = 1

    stop = start + pages - 1

    print('"%s" from p. %s to %s' % (paper_id, start, stop))

    with open(os.path.join(output_dir, paper_id, 'page_numbers.tex'), 'w') as f:
        f.write('\setcounter{page}{%s}' % start)
    stats.update({'page': {'start': start,
                           'stop': stop}})
    stats.update({'paper_id': paper_id})

    return stats, stop
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)
Exemple #16
0
def paper_stats(paper_id, start):
    """Pull in stats of paper, return stats and the next paper 
    """
    stats = options.cfg2dict(
        os.path.join(output_dir, paper_id, 'paper_stats.json'))

    pages = stats.get('pages', 1)
    stop = start + pages - 1

    print('"%s" from p. %s to %s' % (paper_id, start, stop))

    # Build table of contents
    stats.update({
        'page': {
            'start': start,
            'stop': stop
        },
        'paper_id': paper_id
    })

    return stats
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)
Exemple #18
0
def paper_stats(paper_id, start):
    stats = options.cfg2dict(
        os.path.join(output_dir, paper_id, 'paper_stats.json'))

    # Write page number snippet to be included in the LaTeX output
    if 'pages' in stats:
        pages = stats['pages']
    else:
        pages = 1

    stop = start + pages - 1

    print '"%s" from p. %s to %s' % (paper_id, start, stop)

    with open(os.path.join(output_dir, paper_id, 'page_numbers.tex'),
              'w') as f:
        f.write('\setcounter{page}{%s}' % start)

    # Build table of contents
    stats.update({'page': {'start': start, 'stop': stop}})
    stats.update({'paper_id': paper_id})

    return stats, stop
Exemple #19
0
def main(data_path: str, send: bool = False):
    scipy_proc = options.cfg2dict(proc_conf)
    proceedings = scipy_proc["proceedings"]

    template = "reviewer-invite.txt"

    # we make this table by hand in google sheets when the committee divvies
    # up reviewers among papers -- the format we have been using is something like
    # | paper title | PR url | reviewer one | reviewer two | ... | reviewer n |
    # where each reviewer field is like "firstname lastname <email@provider>"
    data = pd.read_csv(data_path)
    data = pd.melt(data,
                   id_vars=["title", "url"],
                   var_name="number",
                   value_name="reviewer")
    data = data.dropna()

    email_data = []
    for label, row in data.iterrows():
        one_email = deepcopy(scipy_proc)
        one_email["cc_emails"] = one_email["proceedings"]["editor_email"]
        name, email = split_email_field(row["reviewer"])
        if "@" in email:
            # sometimes we won't have reviewer emails, so that field might be
            # firstname lastname and nothing else
            one_email["to_emails"] = [email]
            one_email["to_name"] = name
            one_email["title"] = row["title"].replace("Paper: ", "")
            one_email["url"] = row["url"]
            one_email[
                "subject"] = f"{proceedings['title']['acronym']} {proceedings['year']} invitation to review proceedings"
            email_data.append(one_email)
        else:
            print(f"could not parse {row['reviewer']}")

    mailer = Mailer(template, send)
    mailer.send_all(email_data)
Exemple #20
0
#!/usr/bin/env python

import getpass
import os
import sys

import gmail
from conf import work_dir
from options import cfg2dict
from build_template import _from_template

dry_run = (len(sys.argv) < 2) or (sys.argv[1] != '--send-emails')

email_conf = os.path.join(work_dir, 'email.json')
config = cfg2dict(email_conf)

for reviewer_info in config['reviewers']:
    for p in reviewer_info['papers']:
        if not os.path.isdir(os.path.join(work_dir, '../papers/', p)):
            raise RuntimeError(
                "Paper %s not found..refusing to generate emails." % p)

if not dry_run:
    password = getpass.getpass(config['sender']['login'] + "'s password:  "******"Sending invite to " + reviewer
#!/usr/bin/env python

import getpass
import os
import sys

import gmail
from conf import work_dir
from options import cfg2dict
from build_template import _from_template

dry_run = (len(sys.argv) < 2) or (sys.argv[1] != '--send-emails')

email_conf = os.path.join(work_dir, 'email.json')
config = cfg2dict(email_conf)

for reviewer_info in config['reviewers']:
    for p in reviewer_info['papers']:
        if not os.path.isdir(os.path.join(work_dir, '../papers/', p)):
            raise RuntimeError("Paper %s not found..refusing to generate emails." % p)

if not dry_run:
    password = getpass.getpass(config['sender']['login']+"'s password:  "******"Sending invite to " + reviewer

    msg = _from_template('reviewer-invite.txt', reviewer_config)
Exemple #22
0
#!/usr/bin/env python

import os

import _mailer as mailer
from conf import work_dir, toc_conf, proc_conf
import options

args = mailer.parse_args()
scipy_proc = options.cfg2dict(proc_conf)
toc = options.cfg2dict(toc_conf)

sender = scipy_proc['proceedings']['xref']['depositor_email']
template = 'doi-notification.txt'
template_data = scipy_proc.copy()
template_data['proceedings']['editor_email'] = ', '.join(template_data['proceedings']['editor_email'])

for paper in toc['toc']:

    template_data.update(paper)
    recipients = ','.join(template_data['author_email'])
    template_data['author'] = mailer.author_greeting(template_data['author'])
    template_data['author_email'] = ', '.join(template_data['author_email'])
    template_data['committee'] = '\n  '.join(template_data['proceedings']['editor'])

    mailer.send_template(sender, recipients, template, template_data)
Exemple #23
0
def get_config():
    config = cfg2dict(proc_conf)
    config.update(cfg2dict(toc_conf))
    return config
Exemple #24
0
def load_config(conf_file):
    return cfg2dict(conf_file)
Exemple #25
0

def dict2cfg(d, filename):
    """Write dictionary out to config file.

    """
    json.dump(d, codecs.open(filename, 'w', 'utf-8'), ensure_ascii=False)


def mkdir_p(dir):
    if os.path.isdir(dir):
        return
    os.makedirs(dir)


options = cfg2dict(proc_conf)

########NEW FILE########
__FILENAME__ = compat3
import sys

__all__ = ['b', 'basestring_', 'bytes', 'next', 'is_unicode']

if sys.version < "3":
    b = bytes = str
    basestring_ = basestring
else:

    def b(s):
        if isinstance(s, str):
            return s.encode('latin1')
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)
def tex2pdf_singlepass(out_path):
    """
    Returns
    -------
    out : str
        LaTeX output.
    retry : bool
        Whether another round of building is needed.
    """

    import subprocess
    command_line = 'pdflatex -halt-on-error paper.tex'

    # -- dummy tempfile is a hacky way to prevent pdflatex
    #    from asking for any missing files via stdin prompts,
    #    which mess up our build process.
    dummy = tempfile.TemporaryFile()

    run = subprocess.Popen(
        command_line,
        shell=True,
        stdin=dummy,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        cwd=out_path,
    )
    out, err = run.communicate()

    if b"Fatal" in out or run.returncode:
        print("PDFLaTeX error output:")
        print("=" * 80)
        print(out)
        print("=" * 80)
        if err:
            print(err)
            print("=" * 80)

        # Errors, exit early
        return out, False

    # Compile BiBTeX if available
    stats_file = os.path.join(out_path, 'paper_stats.json')
    d = options.cfg2dict(stats_file)
    bib_file = os.path.join(out_path, d["bibliography"] + '.bib')

    if os.path.exists(bib_file):
        bibtex_cmd = 'bibtex paper && ' + command_line
        run = subprocess.Popen(
            bibtex_cmd,
            shell=True,
            stdin=dummy,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            cwd=out_path,
        )
        out_bib, err = run.communicate()
        if err or b'Error' in out_bib:
            print("Error compiling BiBTeX")
            print("bibtex error output:")
            print("=" * 80)
            print(out_bib)
            print("=" * 80)
            return out_bib, False

    if b"Label(s) may have changed." in out:
        return out, True

    return out, False
#!/usr/bin/env python

import os

import _mailer as mailer
from conf import work_dir, toc_conf, proc_conf
import options

args = mailer.parse_args()
scipy_proc = options.cfg2dict(proc_conf)
toc = options.cfg2dict(toc_conf)

sender = scipy_proc['proceedings']['xref']['depositor_email']
template = 'doi-notification.txt'
template_data = scipy_proc.copy()
template_data['proceedings']['editor_email'] = ', '.join(
    template_data['proceedings']['editor_email'])

for paper in toc['toc']:

    template_data.update(paper)
    recipients = ','.join(template_data['author_email'])
    template_data['author'] = mailer.author_greeting(template_data['author'])
    template_data['author_email'] = ', '.join(template_data['author_email'])
    template_data['committee'] = '\n  '.join(
        template_data['proceedings']['editor'])

    mailer.send_template(sender, recipients, template, template_data)
    
    for paper_id in dirs:
        with options.temp_cd(basedir):
            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)
Exemple #30
0
#!/usr/bin/env python

import glob
import os
import sys

sys.path.insert(0, 'publisher')

import options

output_dir = 'output'
dirs = [d for d in glob.glob('%s/*' % output_dir) if os.path.isdir(d)]

pages = []
cum_pages = [1]

for d in sorted(dirs):
    try:
        stats = options.cfg2dict(os.path.join(d, 'paper_stats.cfg'))
        pages.append(int(stats['pages']))
        cum_pages.append(cum_pages[-1] + pages[-1])

        print '"%s" from p. %s to %s' % (os.path.basename(d), cum_pages[-2],
                                         cum_pages[-1] - 1)

        f = open(os.path.join(d, 'page_numbers.tex'), 'w')
        f.write('\setcounter{page}{%s}' % cum_pages[-2])
        f.close()
    except IOError, e:
        continue
def tex2pdf(out_path):

    import subprocess
    command_line = 'pdflatex -halt-on-error paper.tex'

    # -- dummy tempfile is a hacky way to prevent pdflatex
    #    from asking for any missing files via stdin prompts,
    #    which mess up our build process.
    dummy = tempfile.TemporaryFile()
    run = subprocess.Popen(command_line, shell=True,
            stdin=dummy,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            cwd=out_path,
            )
    out, err = run.communicate()

    if "Fatal" in out or run.returncode:
        print("PDFLaTeX error output:")
        print("=" * 80)
        print(out)
        print("=" * 80)
        if err:
            print(err)
            print("=" * 80)

        # Errors, exit early
        return out


    # Compile BiBTeX if available
    stats_file = os.path.join(out_path, 'paper_stats.json')
    d = options.cfg2dict(stats_file)
    bib_file = os.path.join(out_path, d["bibliography"] + '.bib')

    if os.path.exists(bib_file):
        bibtex_cmd = 'bibtex paper && ' + command_line
        run = subprocess.Popen(bibtex_cmd, shell=True,
                stdin=dummy,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                cwd=out_path,
                )
        out, err = run.communicate()

        if err:
            print("Error compiling BiBTeX")
            return out


    # -- returncode always 0, have to check output for error
    if not run.returncode:
        # -- pdflatex has to run twice to actually work
        run = subprocess.Popen(command_line, shell=True,
                stdin=dummy,
                stdout=subprocess.PIPE,
                stderr=subprocess.PIPE,
                cwd=out_path,
                )
        out, err = run.communicate()

    return out
def load_config(conf_file):
    return cfg2dict(conf_file)
Exemple #33
0
        return {}

    return json.loads(codecs.open(filename, 'r', 'utf-8').read())

def dict2cfg(d, filename):
    """Write dictionary out to config file.

    """
    json.dump(d, codecs.open(filename, 'w', 'utf-8'), ensure_ascii=False)

def mkdir_p(dir):
    if os.path.isdir(dir):
        return
    os.makedirs(dir)

options = cfg2dict(proc_conf)

########NEW FILE########
__FILENAME__ = compat3
import sys

__all__ = ['b', 'basestring_', 'bytes', 'next', 'is_unicode']

if sys.version < "3":
    b = bytes = str
    basestring_ = basestring
else:

    def b(s):
        if isinstance(s, str):
            return s.encode('latin1')
Exemple #34
0
    for paper_id in dirs:
        with options.temp_cd(basedir):
            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)
Exemple #35
0
def get_config():
    config = cfg2dict(proc_conf)
    config.update(cfg2dict(toc_conf))
    return config
Exemple #36
0
def tex2pdf(out_path):

    import subprocess
    command_line = 'pdflatex -halt-on-error paper.tex'

    # -- dummy tempfile is a hacky way to prevent pdflatex
    #    from asking for any missing files via stdin prompts,
    #    which mess up our build process.
    dummy = tempfile.TemporaryFile()
    run = subprocess.Popen(
        command_line,
        shell=True,
        stdin=dummy,
        stdout=subprocess.PIPE,
        stderr=subprocess.PIPE,
        cwd=out_path,
    )
    out, err = run.communicate()

    if "Fatal" in out or run.returncode:
        print("PDFLaTeX error output:")
        print("=" * 80)
        print(out)
        print("=" * 80)
        if err:
            print(err)
            print("=" * 80)

        # Errors, exit early
        return out

    # Compile BiBTeX if available
    stats_file = os.path.join(out_path, 'paper_stats.json')
    d = options.cfg2dict(stats_file)
    bib_file = os.path.join(out_path, d["bibliography"] + '.bib')

    if os.path.exists(bib_file):
        bibtex_cmd = 'bibtex paper && ' + command_line
        run = subprocess.Popen(
            bibtex_cmd,
            shell=True,
            stdin=dummy,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            cwd=out_path,
        )
        out, err = run.communicate()

        if err:
            print("Error compiling BiBTeX")
            return out

    # -- returncode always 0, have to check output for error
    if not run.returncode:
        # -- pdflatex has to run twice to actually work
        run = subprocess.Popen(
            command_line,
            shell=True,
            stdin=dummy,
            stdout=subprocess.PIPE,
            stderr=subprocess.PIPE,
            cwd=out_path,
        )
        out, err = run.communicate()

    return out