Parser
EDMFileParser
EDMFileParser class parses .edl files and creates a tree of EDMObjects and EDMGroups
Source code in pydmconverter/edm/parser.py
399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 | |
literal_braces
property
Whether the display or a symbol file read so far has a literal
$\{ that :func:read_edm_string marks when literal_brace is set.
__init__(file_path, output_file_path, calc_list_file=None, calc_reuse_short=True, color_list_file=None, search_paths=None, confine_file_refs=False, literal_brace=None)
Creates an instance of EDMFileParser for the given file_path
Parameters
file_path : str | Path
EDM file to parse
calc_list_file : str, optional
Explicit path to a calc.list file used to resolve named CALC PVs
calc_reuse_short : bool, optional
Emit short calc://<id> reuse forms after a calc's first
appearance (PyDM plugin semantics). The react/IR target passes
False so every occurrence keeps its full query for formula hoisting.
color_list_file : str, optional
Explicit path to an EDM colors.list palette used to resolve the
screen's own bgColor. Falls back to EDMCOLORFILE,
$EDMFILES/colors.list, then /etc/edm/colors.list when omitted.
search_paths : str | Path | Sequence[str | Path], optional
Extra directories searched for symbol files (activeSymbolClass) and
calc.list, after the file's own directory and before EDMDATAFILES
(e.g. the original directory of an upload staged in a temp dir).
confine_file_refs : bool, optional
For untrusted input: read a symbol file only from inside the file's own
directory or one of search_paths. A file name may use
subdirectories or .. as long as it resolves inside one of those
directories (not necessarily the one it was joined to). An absolute name,
or one that resolves outside all of them (.., or a symlink pointing
elsewhere), is rejected before any existence check and leaves an empty
group. EDMDATAFILES (and its . default, the CWD) is not searched, so
the caller names every directory a symbol may come from.
literal_brace : str, optional
Written in place of the { of a literal ${VAR} in a value (see
:func:read_edm_string). The react/IR target passes a marker so the
IR builder doesn't declare VAR as a macro; the default keeps
${VAR}.
Source code in pydmconverter/edm/parser.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
add_symbol_properties(temp_group, properties)
Add properties to each sub object within a symbol group. (isSymbol and symbolChannel) These are used to determine if the symbol should hide when symbolChannel is disconnected.
Parameters
temp_group: EDMGroup Group of groups whose objects will be modified properties: dict[str, bool | str | list[str]] Object properties from the activesymbolclass
Source code in pydmconverter/edm/parser.py
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 | |
edm_search_dirs()
The directories EDM looks in for a file the display names, in order: the
display's own directory, then search_paths, then EDMDATAFILES (which a
confined parser skips).
Source code in pydmconverter/edm/parser.py
824 825 826 827 828 829 830 831 | |
find_matching_end_group(text, begin_group_pos)
Find the matching endGroup for a beginGroup, handling nested groups
Source code in pydmconverter/edm/parser.py
1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 | |
generate_pv_ranges(properties)
Given minValues and maxValues (through properties), generate the ranges that the min/maxValues represent.
EDM (symbol.cc) reads both as arrays indexed by state number, so an entry
lands on the state its index names (minValues { 1 "1" } is state 1)
and a state the file leaves out keeps EDM's default 0.
Parameters
properties: dict[str, bool | str | list[str]] Object properties from the activesymbolclass
Returns
list[list[str]]
[min, max] per state
Source code in pydmconverter/edm/parser.py
1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 | |
get_object_properties(text, literal_brace=None)
classmethod
Get the object properties from the given text. This can be any property that an EDM Object may use (e.g. fillColor, value, editable). Size properties and version information are ignored.
Parameters
text : str
Text to extract properties from
literal_brace : str, optional
Passed on to :func:read_edm_string
Returns
dict : str, bool | str | list[str] A dictionary containing the properties of an object
Source code in pydmconverter/edm/parser.py
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 | |
get_size_properties(text, strict=False)
staticmethod
Get the size properties from the given text (x, y, width, height)
Parameters
text : str Text to extract size properties from
Returns
dict : str, int A dictionary containing the size properties from the text
Source code in pydmconverter/edm/parser.py
1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 | |
get_symbol_group(properties, size_properties)
Generate an EDMGroup made up of child EDMGroups each representing a symbol.
These EDMGroups are mapped from the inner groups within the activesymbolclass
embedded file. A symbol file that is not found, is outside the search paths
(confine_file_refs) or includes itself (directly or through other symbol
files) gives an empty group whose properties say why.
Parameters
properties : dict[str, bool | str | list[str]] The activesymbolclass properties used to generate the output EDM Group size_properties : dict[str, int] The coordinate and size_properties of the activesymbolclass
Returns
EDMGroup A group representing a collection of ActiveSymbolclass groups
Source code in pydmconverter/edm/parser.py
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 | |
parse_objects_and_groups(text, parent_group)
Recursively parse the given text into a tree of EDMObjects and EDMGroups. The parsed EDMObjects and EDMGroups are added to the given parent_group, which is the root EDMGroup of the tree. Parameters
text : str Text from the file to be parsed parent_group : EDMGroup Parent EDMGroup to add the parsed EDMObjects and EDMGroups to
Source code in pydmconverter/edm/parser.py
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 | |
parse_screen_properties()
Get the screen properties from the .edl file and set the UI height and width.
A w/h that is missing or not an integer (template fragments write
h $(DISP_HEIGHT)), or a file with no beginScreenProperties block at
all, does not abort the parse: the dimension is recorded in
missing_screen_size and sized from the content once the objects are
parsed (:meth:size_missing_from_content).
Source code in pydmconverter/edm/parser.py
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 | |
populate_symbol_pvs(temp_group, properties, ranges)
Given a group of symbol groups, add visPvs to each group based on their respective ranges. This will determine which group will appear based on the value of the pv connected to this activeSymbolClass.
Parameters
temp_group: EDMGroup Group of groups whose objects will be modified properties: dict[str, bool | str | list[str]] Object properties from the activesymbolclass ranges: list[list[str]] The ranges taht determine the visPv ranges
Source code in pydmconverter/edm/parser.py
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 | |
remove_extra_groups(temp_group, ranges)
Given a group of symbol groups, remove extra groups that are outside of the ranges given. (if there are more groups than ranges, the extra groups are removed) Also, if there are no ranges, only include the first group.
Parameters
temp_group: EDMGroup The EDMGroup making up each symbol group whose objects will be modified ranges: list[list[str]] A list encompassing the ranges (mainly the len(ranges) is important)
Source code in pydmconverter/edm/parser.py
999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 | |
remove_prepended_index(lines, literal_brace=None)
staticmethod
Clean the raw lines of a multi-line (brace-block) property value.
EDM writes array tags (displayFileName, symbols, minValues,
xPoints, ...) as <index> <value> lines, and may skip indices
(symbols { 2 "P=X" }) or start at 1. When every line carries an
unquoted leading index and at least one line also carries a value, the
values are returned as an :class:IndexedBlock whose indices keep
each value's EDM index, so consumers can align parallel arrays (a related
display's symbols[i] belongs to its displayFileName[i]). Otherwise
(quoted text such as value { "1 GeV" }, or bare numbers such as
value { 5 }) every line is kept as text. Values are unquoted with
:func:read_edm_string either way.
In an indexed block, a line without a leading index continues the
previous entry (a quoted value spanning lines, 0 "Label then "),
and a repeated index replaces the earlier entry, as EDM's array read does.
Parameters
lines : list[str]
The raw lines between { and }
literal_brace : str, optional
Passed on to :func:read_edm_string
Returns
list[str]
The cleaned values (an :class:IndexedBlock for an indexed block)
Source code in pydmconverter/edm/parser.py
1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 | |
reorient_symbol_groups(temp_group, orientation, size_properties, num_states=1, box=None)
Given a group of symbol groups, rotate (rotateCW, rotateCCW) or flip (FlipV, FlipH) every state group and everything in it, nested groups included, about the symbol's midpoint (symbol.cc createFromFile calls rotateInternal/flipInternal at getXMid(), getYMid(), after any scaling).
Parameters
temp_group: EDMGroup
The EDMGroup making up each symbol group whose objects will be modified
orientation : str
The orientation instruction to flip or rotate
size_properties : dict[str, int]
The coordinate and size_properties of the activesymbolclass
num_states : int
The symbol's numStates (at least 1); groups past it don't size the symbol
box : tuple[int, int], optional
The symbol's width and height from :meth:scale_symbol_groups. Without
it, the largest of the first num_states groups, the ones EDM reads.
Source code in pydmconverter/edm/parser.py
959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 | |
resize_symbol_groups(temp_group, size_properties)
Given a group of symbol groups, modify the coordinates of each object within the symbol groupsto be in relation to the coordinates of the new file rather than from the embedded file.
Parameters
temp_group: EDMGroup The EDMGroup making up each symbol group whose objects will be modified size_properties : dict[str, int] The coordinate and size_properties of the activesymbolclass
Source code in pydmconverter/edm/parser.py
876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 | |
scale_symbol_groups(temp_group, properties, size_properties, num_states, warnings)
Given a group of symbol groups moved to the symbol's position, scale every
state to the symbol's saved size, as EDM does unless the symbol has
useOriginalSize (symbol.cc createFromFile). readSymbolFile leaves the
symbol as wide and tall as the largest of the first num_states groups
(w = maxW; h = maxH); when the saved w/h differ, resizeAbs scales the
content of every state by saved/max, per axis, about the symbol's top-left
corner.
EDM refuses when an object would end up under 2 pixels wide or high
("Symbol resize underflow - using original size"); the symbol then keeps
the symbol file's size and a warning is added to warnings.
Parameters
temp_group: EDMGroup The EDMGroup making up each symbol group whose objects will be modified properties: dict[str, bool | str | list[str]] Object properties from the activesymbolclass size_properties : dict[str, int] The coordinate and size_properties of the activesymbolclass num_states : int The symbol's numStates (at least 1); groups past it don't size the symbol warnings : list[str] The symbol's warnings, extended when EDM would refuse to scale it
Returns
tuple[int, int] The symbol's width and height afterwards
Source code in pydmconverter/edm/parser.py
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 | |
size_missing_from_content()
Size each dimension in missing_screen_size from the content.
The dimension becomes the top-level content extent (max x + width /
y + height over the screen's objects and groups, ignoring zero-size
ones) plus the IR builder's 8 px margin, so the .ui window is not 0-sized.
missing_screen_size is kept: the IR adapter still passes None for these
dimensions and lets the builder size them the same way.
Source code in pydmconverter/edm/parser.py
559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 | |
EDMGroup
dataclass
Bases: EDMObjectBase
EDM Group class represents a group in .edl files
Source code in pydmconverter/edm/parser.py
199 200 201 202 203 204 205 206 207 208 209 | |
EDMObject
dataclass
Bases: EDMObjectBase
EDM Object class represents an object in .edl files
Source code in pydmconverter/edm/parser.py
212 213 214 215 216 217 | |
EDMObjectBase
dataclass
EDM Abstract Object class represents an abstract object in .edl files
Source code in pydmconverter/edm/parser.py
189 190 191 192 193 194 195 196 | |
IndexedBlock
Bases: list
A brace-block value parsed from EDM <index> <value> lines.
Behaves as the compact list of values (what positional consumers always
saw); indices[i] is the EDM array index of item i.
Source code in pydmconverter/edm/parser.py
83 84 85 86 87 88 89 90 91 92 | |
block_items(value)
A brace-block prop value -> [(EDM array index, value)].
An :class:IndexedBlock keeps the indices the file wrote (symbols { 2
"P=X" } is entry 2, not 0); another list is numbered by position and a bare
string is entry 0.
Source code in pydmconverter/edm/parser.py
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 | |
block_list(value)
A brace-block prop value as a list indexed by EDM array index, with ""
for each entry the file leaves out (xPv { 1 "X" } -> ["", "X"]), for
consumers that pair parallel arrays by position.
Source code in pydmconverter/edm/parser.py
113 114 115 116 117 118 119 120 121 | |
closing_display_indices(properties)
The related display entries (EDM array indices) that close the parent window after opening their display.
EDM (related_display.cc) reads the closeAction and closeDisplay tags
into the same closeAction array, each setting only the indices it lists, so
where a file writes both for one index the later tag wins.
popupDisplay closes the parent only when the display isn't a popup, so none
close with button3Popup (a right-click popup) or with useFocus on a
button of one menu item (a hover popup). EDM counts numDsps menu items, less
a helpCommand "item N" entry, which this doesn't model.
Source code in pydmconverter/edm/parser.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
edm_int(value)
EDM's integer read of a tag value (strtol semantics): the leading integer, else 0.
Source code in pydmconverter/edm/parser.py
124 125 126 127 128 129 130 131 | |
literal_macro_clashes(text)
Names an EDM file uses both as a literal $\{NAME\} (a shell variable,
which EDM never expands) and as a $(NAME) macro, given the file's text
after :meth:EDMFileParser.modify_text (which writes the macro as ${NAME}).
Once read, both are ${NAME}, so a target that substitutes macros puts the
macro's value into the shell variable.
Source code in pydmconverter/edm/parser.py
71 72 73 74 75 76 77 78 79 80 | |
read_edm_string(value, literal_brace=None)
Unquote one EDM tag value.
EDM writes strings in double quotes and escapes \, ", { and
} with a backslash; its reader skips leading whitespace and the opening
quote and turns any \x into x. A quoted value ends at the first
unescaped " or line break (or at the end of the text when the closing
quote is missing). Spaces inside the quotes are kept, as EDM keeps them
(value { "Currently: " }). A value that doesn't start with a quote keeps
the old handling: strip spaces, newlines and quotes at both ends, and
unescape \".
EDM expands only $(NAME) macros, so $\{VAR\} reads as the literal
text ${VAR} (a shell variable in a command). With literal_brace set,
that brace is replaced by literal_brace, so the text can't be mistaken
for a $(NAME) macro, which :meth:EDMFileParser.modify_text writes as
${NAME}.
Source code in pydmconverter/edm/parser.py
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |