MCPcopy Index your code
hub / github.com/spaceandtimefdn/SxT-Python-SDK / load

Method load

src/spaceandtime/sxtresource.py:539–636  ·  view source on GitHub ↗

-------------------- Loads Resource file *WITH PRIVATE KEYS* to the current object, overwriting all current values. The load is expecting a plain-text file in a shell-loadable format, meaning you can run the input file in a terminal /shell, and it will load into environment

(self, filepath:Path, *args, **kwargs)

Source from the content-addressed store, hash-verified

537
538
539 def load(self, filepath:Path, *args, **kwargs):
540 """--------------------
541 Loads Resource file *WITH PRIVATE KEYS* to the current object, overwriting all current values.
542
543 The load is expecting a plain-text file in a shell-loadable format, meaning you can run the input file in a
544 terminal /shell, and it will load into environment variables. This is the same file that the save() function
545 produces. Any NAME=Value format is translated into object variables, including heredocs using the EOM marker.
546 For examples, look at the save() file produced. To prevent losing keys, it is recommended you always
547 save() before you load().
548
549 Args:
550 filepath (Path): File to load into object.
551 exact_match_only (bool): If False, will accept incomplete filenames or filenames with iterators.
552
553 Returns:
554 bool: True if load was successful, False if not.
555 """
556 if not filepath or not Path(filepath).exists(): raise ValueError(f'Must supply a valid filepath to load().')
557 self.clear_all()
558
559 # load file contents:
560 filecontents = Path(filepath).read_text()
561
562 # just in case, try to catch other past docstring markers
563 eom_marker = kwargs['docstring_marker_override'] if 'docstring_marker_override' in kwargs else 'EOM'
564 if eom_marker not in filecontents and 'EOMsg' in filecontents: eom_marker = 'EOMsg'
565
566 # pull out any docstrings first:
567 multiline = False
568 multilines = []
569 lines = filecontents.split("\n")
570 loadmap = {}
571
572 for line in lines:
573 line_nospace = line = str(line).strip()
574 if line.startswith('#') or line.strip() == '': continue
575
576 while ' ' in line_nospace: line_nospace = line_nospace.replace(' ','')
577
578 if f'$(cat<<{eom_marker}' in line_nospace and '"' not in line_nospace and "'" not in line_nospace:
579 # trigger multiline section (docstring) and capture multiline name
580 multiline = True
581 name = line.split('=')[0].strip()
582 multilines = []
583 continue
584
585 if multiline and not line_nospace.startswith(eom_marker):
586 # continue collecting multiline value data (not name)
587 multilines.append(line)
588 continue
589
590 if multiline and line_nospace.startswith(eom_marker):
591 # trigger end of multiline section, and save to larger loadmap
592 multiline = False
593 loadmap[name] = '\n'.join(multilines)
594 continue
595
596 # if missing an equal sign, not an assignment line, ignore

Callers 1

__init__Method · 0.95

Calls 5

clear_allMethod · 0.95
SXTKeyManagerClass · 0.90
SXTBiscuitClass · 0.90
SxTFileContentErrorClass · 0.90
existsMethod · 0.45

Tested by

no test coverage detected