Parser Helpers
apply_rewrite_rule(rewrite_rule, arg_list)
Apply a rewrite rule to an argument list. Rewrite rules often look like '$(A),$(A).SEVR', which can expand a single argument into multiple arguments by replacing placeholders.
For example
rewrite_rule = '$(A),$(A).SEVR' arg_list = ['myPV']
=> new_args = ['myPV', 'myPV.SEVR']
Parameters
rewrite_rule : str The rewrite rule, without the leading '@' (e.g. '$(A),$(A).SEVR'). arg_list : List[str] The list of arguments to which we apply the rule.
Returns
List[str] A new list of arguments produced by the rewrite rule.
Source code in pydmconverter/edm/parser_helpers.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
|
clean_escape_characters(expr)
Remove extra ' characters from CALC/LOC expressions.
Parameters
expression : str The expression to be cleaned.
Returns
str The new expression with \s removed.
Source code in pydmconverter/edm/parser_helpers.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 |
|
convert_color_property_to_qcolor(fillColor, color_data)
Convert the EDM 'fillColor', 'bgColor', 'fgColor' property into a tuple representing RGBA values.
Returns:
Type | Description |
---|---|
Optional[Tuple[int, int, int, int]]
|
Optional[Tuple[int, int, int, int]]: A tuple (red, green, blue, alpha) or None. |
Source code in pydmconverter/edm/parser_helpers.py
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 |
|
get_color_by_index(color_data, index)
Retrieve the color definition from color_data using an index string like 'index 3'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color_data
|
Dict[str, Any]
|
The parsed colors.list data. |
required |
index
|
str
|
The color index string, e.g., 'index 3'. |
required |
Returns:
Type | Description |
---|---|
Optional[Dict[str, Any]]
|
Optional[Dict[str, Any]]: The corresponding color dictionary (expected to have an 'rgb' key) or None if not found. |
Source code in pydmconverter/edm/parser_helpers.py
814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 |
|
get_color_by_rgb(colorStr)
Retrieve the color definition from color_data using an rgb string like 'rgb 0 0 0'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
colorStr
|
str
|
The color index string, e.g., 'rgb 0 0 0'. |
required |
Returns:
Type | Description |
---|---|
Optional[Dict[str, Any]]
|
Optional[Dict[str, Any]]: The corresponding color dictionary (expected to have an 'rgb' key) or None if not found. |
Source code in pydmconverter/edm/parser_helpers.py
837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 |
|
loc_conversion(edm_string)
Convert an EDM local PV string to a PyDM local variable string, mapping types to supported PyDM types.
Supported PyDM types: - int - float - str - array (numpy.ndarray)
Enum ('e') is mapped to int for simplicity in this conversion.
Parameters
edm_string : str EDM local PV string to be converted. Expected format is: "LOC\name=type:value" (with optional scope modifiers and ignoring special functions).
Returns
pydm_string : str
Corresponding PyDM string in the format:
"loc://
Raises
ValueError If the EDM string does not start with 'LOC\' or if it lacks the proper format.
Source code in pydmconverter/edm/parser_helpers.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 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 |
|
parse_calc_list(calc_list_path)
Parse an EPICS-style calc.list file and return a dictionary mapping calculation names to a tuple of (rewrite_rule, expression).
The file format typically looks like
CALC1 ...
# ...
<calc_name>
[@rewrite_rule]
<expression>
# ...
Parameters
calc_list_path : str Path to the calc.list file.
Returns
Dict[str, Tuple[Optional[str], Optional[str]]] A dictionary with keys as calculation names (e.g. 'sum', 'diff') and values as a 2-tuple (rewrite_rule, expression). Both are optional: rewrite_rule may be None if not present, and expression may also be None if the file has incomplete entries.
Source code in pydmconverter/edm/parser_helpers.py
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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
parse_calc_pv(edm_pv)
Parse an EDM-style CALC PV reference and extract the calculation name (or inline expression), list of arguments, and whether it's an inline expression (curly braces).
EDM CALC PV examples
- 'CALC\sum(pv1, pv2)'
- 'CALC\{A+B}(pv1, pv2)'
- 'CALC\{(A)}($(P)$(R)Acquire)'
Parameters
edm_pv : str The EDM-style CALC PV string to parse. For example, 'CALC\sum(pv1, pv2)'.
Returns
calc_name_or_expr : str The calculation name (e.g. 'sum') or inline expression (e.g. 'A+B'). arg_list : List[str] The list of arguments, e.g. ['pv1', 'pv2']. is_inline_expr : bool True if the EDM PV used inline curly brace syntax (e.g. '{A+B}'), False otherwise.
Raises
ValueError If the given edm_pv string doesn't match the expected CALC syntax.
Source code in pydmconverter/edm/parser_helpers.py
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
parse_colors_list(filepath)
Parse an EDM colors.list
file into a structured Python dictionary.
Parameters
filepath : str
Path to the colors.list
file.
Returns
Dict[str, Any]
A dictionary representing the parsed content of the colors.list
file.
Keys
----
version : Dict[str, int]
Dictionary containing {"major", "minor", "release"}.
blinkms : int or None
The blink period in milliseconds.
columns : int or None
Number of columns in the color palette.
max : int or None
The maximum RGB component value + 1 (e.g. 256 or 0x10000).
alias : Dict[str, str]
Maps an alias name to a (static or rule-based) color name.
static : Dict[int, Dict[str, Union[str, List[int]]]]
Static color definitions keyed by their numeric index.
Each value is a dictionary containing:
- "name": str
- "rgb": List[int] (3 values) or 6 values if blinking
rules : Dict[int, Dict[str, Any]]
Rule definitions keyed by their numeric index.
Each value is a dictionary containing:
- "name": str
- "conditions": List[Dict[str, str]]
Each condition has:
- "condition": str (e.g. ">0 && <10" or "default")
- "color": str
menumap : List[str]
List of color names as displayed in the color name menu.
alarm : Dict[str, str]
Alarm color configuration. Keys are alarm states, values are color names.
Notes
- The first non-comment, non-empty line must be the version line: e.g. "4 0 0".
- The parser assumes a well-formed file. If your file structure differs, you may need to handle additional edge cases (e.g. malformed lines, trailing braces, etc.).
- A “blinking” static color has six numeric components for its two RGB states.
- A rule line has the form: rule
{ ... }. - The menumap and alarm blocks must each be enclosed in braces.
- The alias lines have the form: alias
.
Source code in pydmconverter/edm/parser_helpers.py
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 |
|
replace_calc_and_loc_in_edm_content(edm_content, filepath)
Replace both CALC...(...) and LOC...=... references in the EDM file content with PyDM equivalents. The first time each unique reference appears, the replacement is the full PyDM string; subsequent appearances use the short form.
Parameters
edm_content : str The full text of the EDM file, as a single string. filepath : str path of the given edm file
Returns
new_content : str The EDM content after all CALC and LOC references have been replaced. encountered_calcs : Dict[str, Dict[str, str]] A dictionary of all encountered CALC references, mapping the original EDM reference to {"full": ..., "short": ...}. encountered_locs : Dict[str, Dict[str, str]] A dictionary of all encountered LOC references, similarly mapping each unique original LOC reference to "full" and "short" addresses.
Source code in pydmconverter/edm/parser_helpers.py
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 |
|
search_calc_list(file_path)
search for a calc.list file and return the path if found, returns None if no calc.list exists.
This function reads a file, filters out comment lines (lines starting with '#') and empty lines, and assumes each definition in the file is specified by two consecutive non-comment lines:
Parameters
file_path : str The path to a file whose directory will be searched for 'calc.list'.
Returns
Optional[str] The full path to the found 'calc.list' file, in either the local directory or in $EDMFILES, as a string if it exists; otherwise, None.
Source code in pydmconverter/edm/parser_helpers.py
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
|
search_color_list(cli_color_file=None)
Attempt to find the EDM color file by the following priority:
- CLI argument (cli_color_file), if provided.
- EDMCOLORFILE env variable (absolute path).
- EDMFILES env variable + "colors.list".
- Default path: "/etc/edm/colors.list".
Parameters
cli_color_file : str or None, optional A file path passed via command line argument. If this is provided and valid, it overrides other checks.
Returns
str or None The path to the EDM color file if found, else None.
Source code in pydmconverter/edm/parser_helpers.py
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 |
|
translate_calc_pv_to_pydm(edm_pv, calc_dict=None, default_prefix='channel://')
Translate an EDM-style CALC PV (e.g., 'CALC\sum(pv1, pv2)') into a PyDM calc plugin address, e.g.:
calc://my_variable_name?A=channel://pv1&B=channel://pv2&expr=A+B
Parameters
edm_pv : str
The CALC PV in EDM syntax. For instance, "CALC\sum(pv1, pv2)"
or "CALC{A-B}(myPv, 10.5)".
calc_dict : dict, optional
A dictionary mapping calculation names to (rewrite_rule, expression).
Typically from parse_calc_list()
. This is required if the CALC PV
references a named calc (e.g. 'sum') that is defined in a calc.list file.
If the CALC PV uses an inline expression ({A+B}), this dictionary
may be omitted.
default_prefix : str, optional
A prefix to apply to each argument if it doesn't already include a protocol.
Defaults to 'channel://'.
Returns
str
A PyDM calc plugin address string in the format:
'calc://
Raises
ValueError
If the named calculation does not exist in the provided calc_dict
.
Source code in pydmconverter/edm/parser_helpers.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 |
|