Skip to content

Commit

Permalink
updated SPARTA shar extraction script
Browse files Browse the repository at this point in the history
  • Loading branch information
amagela committed Mar 18, 2024
1 parent ea372d3 commit e9de6b2
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion doc/sphinx/08_sparta/extract-amashar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e9de6b2

Please sign in to comment.