Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/technical/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
templates_path = ["_templates"]
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]

edxplatform_repo_url = "https://github.com/edx/edx-platform"
edxplatform_repo_url = "https://github.com/openedx/edx-platform"
edxplatform_source_path = os.path.abspath(
os.path.join(os.path.dirname(__file__), "..", "..")
)
Expand Down
68 changes: 68 additions & 0 deletions docs/technical/xml_to_json.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import xml.etree.ElementTree as ET
import json


def parse_desc(n):
return n.text


def parse_source(n):
return n[0].items()[0][1]


def parse_def(n):
return n[0].text


def iter_toggle(section):
key = {"name": section[0].text}
for item in section[1:]:
if item.items()[0][1] == "source":
key["source"] = parse_source(item)
elif item.items()[0][1] == "default":
key["default"] = parse_def(item)
elif item.items()[0][1] == "warning":
key["warning"] = item[0].text
elif item.items()[0][1] == "description":
key["desc"] = parse_desc(item)
else:
key[item.items()[0][1]] = item.text.split(": ")[1]
return key


result = {}

s = ET.parse("_build/xml/settings.xml")
s = s.getroot()
s = s[0]

scms = s.findall("section")[1]
slms = s.findall("section")[0]

lms_settings = []
cms_settings = []

for i in scms[1:]:
cms_settings.append(iter_toggle(i))

result["cms_settigs"] = cms_settings

for i in slms[1:]:
lms_settings.append(iter_toggle(i))

result["lms_settings"] = lms_settings

f = ET.parse("_build/xml/featuretoggles.xml")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you aware that this file is actually generated from an API endpoint? (as far as I can remember)

Copy link
Member Author

@ghassanmas ghassanmas Sep 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes you are right that code-annotation does provide an API to extract the data in a structural format.
I actually find out about it after I spent few hours writing this script but I just tested and can confirm.

code_annotations static_find_annotations --config_file vevn/lib/python3.8/site-packages/code_annotations/contrib/config/setting_annotations.yaml 
code_annotations static_find_annotations --config_file vevnlib/python3.8/site-packages/code_annotations/contrib/config/feature_toggle_annotations.yaml

Running above the commands in edx-plaform root I was able to generate both feature and settings in a yaml file.
ref: https://edx.readthedocs.io/projects/edx-toggles/en/latest/how_to/get_feature_toggles_annotation_data.html#get-toggle-annotations

I guess it would be nice if we can generate those files on a per release basis and then do git diff which shall result changes of setting/config a nice format. Hopefully we can enforce people to use these annotaion

f = f.getroot()
f = f[1]

f_a = []

for i in f[2:]:
f_a.append(iter_toggle(i))

result["features_toggles"] = f_a
raw_json = json.dumps(result, indent=2, ensure_ascii=False)
result_file = open("result.json", "wt")
result_file.write(raw_json)
result_file.close()