MCPcopy
hub / github.com/volatilityfoundation/volatility3 / setup

Function setup

doc/source/conf.py:24–120  ·  view source on GitHub ↗
(app)

Source from the content-addressed store, hash-verified

22
23
24def setup(app):
25 volatility_directory = os.path.abspath(
26 os.path.join(os.path.dirname(__file__), "..", "..", "volatility3")
27 )
28
29 source_dir = os.path.abspath(os.path.dirname(__file__))
30 sphinx.ext.apidoc.main(
31 ["-e", "-M", "-f", "-T", "-o", source_dir, volatility_directory]
32 )
33
34 # Go through the volatility3.framework.plugins files and change them to volatility3.plugins
35 for dir, _, files in os.walk(os.path.dirname(__file__)):
36 for filename in files:
37 if (
38 filename.startswith("volatility3.framework.plugins")
39 and filename != "volatility3.framework.plugins.rst"
40 ):
41 # Change all volatility3.framework.plugins to volatility3.plugins in the file
42 # Rename the file
43 new_filename = filename.replace(
44 "volatility3.framework.plugins", "volatility3.plugins"
45 )
46
47 replace_string = b"Submodules\n----------\n\n.. toctree::\n\n"
48 submodules = replace_string
49
50 # If file already exists, read out the subpackages entries from it add them to the new list
51 if os.path.exists(os.path.join(dir, new_filename)):
52 with open(os.path.join(dir, new_filename), "rb") as newfile:
53 data = newfile.read()
54 index = data.find(replace_string)
55 if index > -1:
56 submodules = data[index:]
57
58 with open(os.path.join(dir, new_filename), "wb") as newfile:
59 with open(os.path.join(dir, filename), "rb") as oldfile:
60 line = oldfile.read()
61 correct_plugins = line.replace(
62 b"volatility3.framework.plugins", b"volatility3.plugins"
63 )
64 correct_submodules = correct_plugins.replace(
65 replace_string, submodules
66 )
67 newfile.write(correct_submodules)
68 os.remove(os.path.join(dir, filename))
69 elif filename == "volatility3.framework.rst":
70 with open(os.path.join(dir, filename), "rb") as contents:
71 lines = contents.readlines()
72 plugins_seen = False
73 with open(os.path.join(dir, filename), "wb") as contents:
74 for line in lines:
75 if b"volatility3.framework.plugins" in line:
76 plugins_seen = True
77 if plugins_seen and line == b"":
78 contents.write(b" volatility3.plugins")
79 contents.write(line)
80 elif filename == "volatility3.plugins.rst":
81 with open(os.path.join(dir, filename), "rb") as contents:

Callers

nothing calls this directly

Calls 5

removeMethod · 0.80
readlinesMethod · 0.80
readMethod · 0.45
findMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected