Skip to content

Commit

Permalink
Moved progress indicator to library
Browse files Browse the repository at this point in the history
  • Loading branch information
kthoden committed Mar 4, 2020
1 parent 81d68d3 commit a76d0f5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
26 changes: 6 additions & 20 deletions src/eoatex2imxml.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# -*- coding: utf-8; mode: python -*-
# Time-stamp: <2019-12-18 11:16:11 (kthoden)>
# Time-stamp: <2020-03-04 11:54:38 (kthoden)>

"""
Converts Latex files into a customized DocBook XML file.
Expand Down Expand Up @@ -351,20 +351,6 @@ def pdf_burst(input_file, tmpDir):
pageno += 1
# def pdf_burst ends here

def progress(count, total, status=''):
"""Progress bar for command line. Taken from
https://gist.github.com/vladignatyev/06860ec2040cb497f0f3"""

bar_len = 60
filled_len = int(round(bar_len * count / float(total)))

percents = round(100.0 * count / float(total), 1)
bar = '#' * filled_len + '-' * (bar_len - filled_len)

sys.stdout.write('[%s] %s%s ... %s\r' % (bar, percents, '%', status))
sys.stdout.flush()
# def progress ends here

def cleanup():
"""Remove support files"""
try:
Expand Down Expand Up @@ -762,7 +748,7 @@ def process_inline_equations( xmlChapters ):
else:
strSourceCode = xmlEOAineq.text

progress(intEOAineqnumber, len(xmlEOAineqs),"Processing EOAineq %s of %s." % (intEOAineqnumber, len(xmlEOAineqs)))
libeoaconvert.progress(intEOAineqnumber, len(xmlEOAineqs),"Processing EOAineq %s of %s." % (intEOAineqnumber, len(xmlEOAineqs)))

strSourceCode = os.linesep.join([s for s in strSourceCode.splitlines() if s])

Expand Down Expand Up @@ -823,7 +809,7 @@ def process_inline_equations( xmlChapters ):
counter_dictEOAineqs = 1
for intRunningOrder in dictEOAineqs.keys():
# provide more status information here in output!
progress(counter_dictEOAineqs, len(dictEOAineqs.keys()),"Splitting all inline equations, image %s of %s" % (counter_dictEOAineqs, len(dictEOAineqs.keys())))
libeoaconvert.progress(counter_dictEOAineqs, len(dictEOAineqs.keys()),"Splitting all inline equations, image %s of %s" % (counter_dictEOAineqs, len(dictEOAineqs.keys())))
Kommando = "{cmd} {arg1} {arg2}".format(
cmd = PDFCROP_EXEC,
arg1 = (formula_tmp_dir / ("EOAformulas_" + str(intRunningOrder) + ".pdf")).absolute(),
Expand Down Expand Up @@ -863,7 +849,7 @@ def process_eoachem( xmlChapters ):

str_chem_text = xml_EOAchem.text

progress(int_EOAchem_number, len(xmlEOAchems),"Processing EOAchem %s of %s." % (int_EOAchem_number, len(xmlEOAchems)))
libeoaconvert.progress(int_EOAchem_number, len(xmlEOAchems),"Processing EOAchem %s of %s." % (int_EOAchem_number, len(xmlEOAchems)))

str_chem_text = os.linesep.join([s for s in str_chem_text.splitlines() if s])
str_tex_chem = str_tex_chem + "\ce{" + str_chem_text + "}\n\\newpage\n"
Expand Down Expand Up @@ -909,7 +895,7 @@ def process_eoachem( xmlChapters ):
counter_dictEOAchems = 1
for intRunningOrder in dictEOAchems.keys():
# provide more status information here in output!
progress(counter_dictEOAchems, len(dictEOAchems.keys()),"Splitting all inline equations, image %s of %s" % (counter_dictEOAchems, len(dictEOAchems.keys())))
libeoaconvert.progress(counter_dictEOAchems, len(dictEOAchems.keys()),"Splitting all inline equations, image %s of %s" % (counter_dictEOAchems, len(dictEOAchems.keys())))
Kommando = "{cmd} {arg1} {arg2}".format(
cmd=PDFCROP_EXEC,
arg1=(formula_tmp_dir / ("EOAformulas_" + str(intRunningOrder) + ".pdf")).absolute(),
Expand Down Expand Up @@ -1511,7 +1497,7 @@ def add_bibliography_to_xml(

for xmlCitation in xmlCitations:
string_citekey = xmlCitation.find("./citekey").text
progress(counter_citations, len(xmlCitations),"Processing reference %s of %s: %s" % (counter_citations, len(xmlCitations), string_citekey))
libeoaconvert.progress(counter_citations, len(xmlCitations),"Processing reference %s of %s: %s" % (counter_citations, len(xmlCitations), string_citekey))
# If Bibliography-Type is anthology find Refsection for this Chapter
###############
# old version #
Expand Down
15 changes: 15 additions & 0 deletions src/utils/libeoaconvert.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,18 @@ def has_text_or_children(cr):
htoc = False
return htoc
# def has_text_or_children ends here


def progress(count, total, status=''):
"""Progress bar for command line. Taken from
https://gist.github.com/vladignatyev/06860ec2040cb497f0f3"""

bar_len = 60
filled_len = int(round(bar_len * count / float(total)))

percents = round(100.0 * count / float(total), 1)
bar = '#' * filled_len + '-' * (bar_len - filled_len)

sys.stdout.write('[%s] %s%s ... %s\r' % (bar, percents, '%', status))
sys.stdout.flush()
# def progress ends here

0 comments on commit a76d0f5

Please sign in to comment.