From e9de6b2366900f80d168a48a61061630d54c83aa Mon Sep 17 00:00:00 2001 From: Anthony Agelastos Date: Mon, 18 Mar 2024 12:21:15 -0600 Subject: [PATCH] updated SPARTA shar extraction script --- doc/sphinx/08_sparta/extract-amashar.py | 29 ++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/doc/sphinx/08_sparta/extract-amashar.py b/doc/sphinx/08_sparta/extract-amashar.py index da4ab7d1..f44a86fc 100755 --- a/doc/sphinx/08_sparta/extract-amashar.py +++ b/doc/sphinx/08_sparta/extract-amashar.py @@ -134,9 +134,36 @@ def _check_attr(self): self.logger.critical('Cannot read "{}"'.format(self.file_name)) sys.exit(EXIT_CODES["no file"]) + def _extract_statistics(self): + """Loop through file and gather statistics.""" + + # open up file and get lists of files and bundle their contents accordingly + files_split = {} + path_full = "" + with open(self.file_name) as fp: + line = fp.readline() + while line: + if len(line) > 6: + line_check = '##### ' + line_front = line[0:len(line_check)] + if line_front == line_check: + path_full = line[len(line_check):].rstrip() + files_split[path_full] = [] + files_split[path_full].append(line) + line = fp.readline() + + # fill up the bundles + for path_full in files_split: + path_dirname = os.path.dirname(path_full) + os.makedirs(path_dirname) + with open(path_full, 'w') as fp: + self.logger.info("Writing {}".format(path_full)) + fp.writelines(files_split[path_full]) + + def run(self): """Read in SHAR and begin to unpack the bundle.""" - self.logger.info("Information") + self._extract_statistics() # do work