Skip to content

Commit

Permalink
Merge pull request #15 from IBM/14-implement-progress-bars-during-pro…
Browse files Browse the repository at this point in the history
…cessing

Fixes #14 Implemented progressbars
  • Loading branch information
tjanasiewicz authored Nov 26, 2024
2 parents b4e2918 + 2df4ec7 commit 708904a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
17 changes: 12 additions & 5 deletions javacore_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

from lxml import etree
from lxml.etree import XMLSyntaxError
from tqdm import tqdm

import tips
from code_snapshot_collection import CodeSnapshotCollection
Expand Down Expand Up @@ -235,7 +236,7 @@ def parse_common_data(self, filename):

def parse_javacores(self):
""" creates a Javacore object for each javacore...txt file in the given path """
for filename in self.files:
for filename in tqdm(self.files, "Parsing Javacore files", unit=" javacores"):
filename = os.path.join(self.path, filename)
javacore = Javacore()
javacore.create(filename, self)
Expand Down Expand Up @@ -480,17 +481,21 @@ def generate_htmls_from_xmls_xsls(report_xml_file, data_input_dir, output_dir):
os.mkdir(output_dir)
shutil.copy2(report_xml_file, data_input_dir)

list_files = os.listdir(data_input_dir)
progress_bar = tqdm(desc="Generating html files", unit=' files')

# Generating list of tuples. This is required attribute for p.map function executed few lines below.
generate_html_from_xml_xsl_files_params = []
for file in os.listdir(data_input_dir):
generate_html_from_xml_xsl_files_params.append((file, data_input_dir, output_dir))
for file in list_files:
generate_html_from_xml_xsl_files_params.append((file, data_input_dir, output_dir, progress_bar))

# https://docs.python.org/3.8/library/multiprocessing.html
threads_no = JavacoreSet.get_number_of_parallel_threads()
logging.info(f"Using {threads_no} threads to generate html files")
with Pool(threads_no) as p:
p.map(JavacoreSet.generate_html_from_xml_xsl_files, generate_html_from_xml_xsl_files_params)

progress_bar.close()
logging.info(f"Generated html files in {output_dir}")

# Run with the same number of threads as you have processes but leave one thread for something else.
Expand All @@ -501,7 +506,7 @@ def get_number_of_parallel_threads():
@staticmethod
def generate_html_from_xml_xsl_files(args):

collection_file, collection_input_dir, output_dir = args
collection_file, collection_input_dir, output_dir, progress_bar = args

if not collection_file.endswith(".xsl"): return

Expand All @@ -528,13 +533,15 @@ def generate_html_from_xml_xsl_files(args):
logging.debug("Generating file " + html_file)
output_doc.write(html_file, pretty_print=True)

progress_bar.update(1)

def create_xml_xsl_for_collection(self, tmp_dir, xml_xsls_prefix_path, collection, output_file_prefix):
logging.info("Creating xmls and xsls in " + tmp_dir)
os.mkdir(tmp_dir)
extensions = [".xsl", ".xml"]
for extension in extensions:
file_content = Path(xml_xsls_prefix_path + extension).read_text()
for element in collection:
for element in tqdm(collection, desc="Creating xml/xsl files", unit=" files"):
element_id = element.get_id()
filename = output_file_prefix + "_" + str(element_id) + extension
if filename.startswith("_"):
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ dicttoxml
py7zr
lxml
pyana
flask # WSGI server for development the code
tqdm

0 comments on commit 708904a

Please sign in to comment.