Skip to content

Commit

Permalink
rename yaml files
Browse files Browse the repository at this point in the history
  • Loading branch information
pwittich committed Nov 15, 2023
1 parent e134248 commit 705d428
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 395 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -134,4 +134,5 @@ dmypy.json

# testing xml output
src/test.xml
src/test2.xml
.DS_Store
File renamed without changes.
File renamed without changes.
296 changes: 0 additions & 296 deletions src/test2.xml

This file was deleted.

195 changes: 98 additions & 97 deletions src/xml_generate.ipynb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"cells" : [
"cells": [
{
"cell_type" : "code",
"execution_count" : 31,
"metadata" : {},
"outputs" : [],
"source" : [
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"import yaml\n",
"from pprint import pprint\n",
"import xml.etree.ElementTree as ET\n",
Expand All @@ -14,30 +14,32 @@
]
},
{
"cell_type" : "code",
"execution_count" : 32,
"metadata" : {},
"outputs" : [],
"source" : ["verbose=False"]
"cell_type": "code",
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
"verbose=False\n"
]
},
{
"cell_type" : "code",
"execution_count" : 33,
"metadata" : {},
"outputs" : [],
"source" : [
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"with open('../data/zynqmon_2.yml') as f:\n",
" y = yaml.load(f, Loader=yaml.FullLoader)\n",
" if (verbose) :\n",
" pprint(y)\n"
]
},
{
"cell_type" : "code",
"execution_count" : 34,
"metadata" : {},
"outputs" : [],
"source" : [
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"def makeNode(parent: ET.Element, id: str, c: dict, addr2: int, parent_id: str) -> ET.Element:\n",
" node = ET.SubElement(parent, 'node')\n",
" id = id.replace(' ', '_')\n",
Expand Down Expand Up @@ -93,11 +95,11 @@
]
},
{
"cell_type" : "code",
"execution_count" : 35,
"metadata" : {},
"outputs" : [],
"source" : [
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"# This is the parent (root) tag\n",
"# onto which other tags would be\n",
"# created\n",
Expand All @@ -107,11 +109,11 @@
]
},
{
"cell_type" : "code",
"execution_count" : 36,
"metadata" : {},
"outputs" : [],
"source" : [
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"config = y['config']\n",
"\n",
"for c in config: # loop over entries in configuration (sensor category)\n",
Expand Down Expand Up @@ -141,13 +143,13 @@
" else:\n",
" start = c['start']\n",
" makeNode(cm, n, c, start+i, \"\")\n",
" i += 1"
" i += 1\n"
]
},
{
"cell_type" : "markdown",
"metadata" : {},
"source" : [
"cell_type": "markdown",
"metadata": {},
"source": [
"config = y['config']\n",
"\n",
"for c in config: # loop over entries in configuration (sensor category)\n",
Expand Down Expand Up @@ -208,16 +210,16 @@
]
},
{
"cell_type" : "markdown",
"metadata" : {},
"source" : []
"cell_type": "markdown",
"metadata": {},
"source": []
},
{
"cell_type" : "code",
"execution_count" : 37,
"metadata" : {},
"outputs" : [],
"source" : [
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
"s_xml = ET.tostring(cm).decode()\n",
"\n",
"tree = ET.ElementTree(cm)\n",
Expand All @@ -226,14 +228,14 @@
]
},
{
"cell_type" : "code",
"execution_count" : 38,
"metadata" : {},
"outputs" : [
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"name" : "stdout",
"output_type" : "stream",
"text" : [
"name": "stdout",
"output_type": "stream",
"text": [
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n",
"<node address=\"0x00000000\" id=\"CM\">\n",
" <node address=\"0x0\" id=\"F1_P1_Tx12\" mask=\"0x000000FF\" parameters=\"Format=d;Row=F1_P1_Tx12;Table=CM_FF_MON;Column=Temp_C;Status=1;\" permission=\"r\"/>\n",
Expand Down Expand Up @@ -437,22 +439,22 @@
]
}
],
"source" : [
"source": [
"from bs4 import BeautifulSoup\n",
"\n",
"bs = BeautifulSoup(s_xml, 'xml')\n",
"pretty_xml = bs.prettify()\n",
"with open(\"test.xml\", \"w\") as f:\n",
" print(pretty_xml, file=f)\n",
"print(pretty_xml)"
"print(pretty_xml)\n"
]
},
{
"cell_type" : "code",
"execution_count" : 39,
"metadata" : {},
"outputs" : [],
"source" : [
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
"def calcSize(c: dict) -> int:\n",
" if 'size' in c:\n",
" size = c['size']*2 # extra factor of 2 for 16 to 32 bit\n",
Expand All @@ -466,14 +468,14 @@
]
},
{
"cell_type" : "code",
"execution_count" : 40,
"metadata" : {},
"outputs" : [
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [
{
"name" : "stdout",
"output_type" : "stream",
"text" : [
"name": "stdout",
"output_type": "stream",
"text": [
"[name: firefly start: 0 end: 19 size: 20,\n",
" name: psmon start: 32 end: 115 size: 84,\n",
" name: adcmon start: 128 end: 148 size: 21,\n",
Expand All @@ -485,7 +487,7 @@
]
}
],
"source" : [
"source": [
"# check overlaps\n",
"# create an object with a name, and a start end end register\n",
"# do so for every entry\n",
Expand Down Expand Up @@ -536,41 +538,40 @@
"for i in range(len(entries)):\n",
" for j in range(i+1, len(entries)):\n",
" if entries[i].overlaps(entries[j]):\n",
" print(f\"{entries[i].name} overlaps with {entries[j].name}\")\n",
"\n"
" print(f\"{entries[i].name} overlaps with {entries[j].name}\")\n"
]
},
{
"cell_type" : "code",
"execution_count" : null,
"metadata" : {},
"outputs" : [],
"source" : []
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata" : {
"interpreter" : {
"hash" : "d1bcf2015140efba1309a3b878c8a09b28a5da1fac13dcbb304588e5a25844fe"
},
"kernelspec" : {
"display_name" : "Python 3.8.12 ('base')",
"language" : "python",
"name" : "python3"
},
"language_info" : {
"codemirror_mode" : {
"name" : "ipython",
"version" : 3
},
"file_extension" : ".py",
"mimetype" : "text/x-python",
"name" : "python",
"nbconvert_exporter" : "python",
"pygments_lexer" : "ipython3",
"version" : "3.9.17"
},
"orig_nbformat" : 4
},
"nbformat" : 4,
"nbformat_minor" : 2
"metadata": {
"interpreter": {
"hash": "d1bcf2015140efba1309a3b878c8a09b28a5da1fac13dcbb304588e5a25844fe"
},
"kernelspec": {
"display_name": "Python 3.8.12 ('base')",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.18"
},
"orig_nbformat": 4
},
"nbformat": 4,
"nbformat_minor": 2
}
4 changes: 2 additions & 2 deletions src/xml_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ def overloads(self):
# custom file type for yaml file, to be used with argparse
def yaml_file(filename):
"""custom file type for yaml file, to be used with argparse"""
if not filename.endswith('.yaml'):
raise argparse.ArgumentTypeError('File must have a .yaml extension')
if not filename.endswith('.yml'):
raise argparse.ArgumentTypeError('File must have a .yml extension')
return filename

parser = argparse.ArgumentParser(description='Process YAML for XML.')
Expand Down

0 comments on commit 705d428

Please sign in to comment.