MCPcopy Create free account
hub / github.com/StackStorm/st2 / load_content

Function load_content

st2client/tests/fixtures/loader.py:36–56  ·  view source on GitHub ↗

Loads content from file_path if file_path's extension is one of allowed ones (See ALLOWED_EXTS). Throws UnsupportedMetaException on disallowed filetypes. :param file_path: Absolute path to the file to load content from. :type file_path: ``str`` :rtype: ``dict``

(file_path)

Source from the content-addressed store, hash-verified

34
35
36def load_content(file_path):
37 """
38 Loads content from file_path if file_path's extension
39 is one of allowed ones (See ALLOWED_EXTS).
40 Throws UnsupportedMetaException on disallowed filetypes.
41 :param file_path: Absolute path to the file to load content from.
42 :type file_path: ``str``
43 :rtype: ``dict``
44 """
45 file_name, file_ext = os.path.splitext(file_path)
46
47 if file_ext not in ALLOWED_EXTS:
48 raise Exception(
49 "Unsupported meta type %s, file %s. Allowed: %s"
50 % (file_ext, file_path, ALLOWED_EXTS)
51 )
52
53 parser_func = PARSER_FUNCS.get(file_ext, None)
54
55 with open(file_path, "r") as fd:
56 return parser_func(fd) if parser_func else fd.read()
57
58
59def load_fixtures(fixtures_dict=None):

Callers 1

load_fixturesFunction · 0.85

Calls 2

getMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected