-
Notifications
You must be signed in to change notification settings - Fork 3
Ticket3396 show global macros #450
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Chsudeepta
wants to merge
21
commits into
master
Choose a base branch
from
Ticket3396_ShowGlobalMacros
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
d0964b1
Added global macros to the configuration
ae34053
Removed print lines
9a64ced
Reformatted some files
2fb2aa5
Reformatted some files
964a846
Reformatted some files
f7246bd
Reformatted some files
5cc6e1a
Reformatted some files
71873df
Reformatted some files
17776be
Fixed some ruff comments
f4aa705
Fixed some ruff comments
615ff30
Fixed some ruff comments
7aa2e58
Fixed some ruff comments
58a35af
Fixed some more ruff findings
e01cebb
Ruff fixes
6521e05
More Ruff fixes
7d6e2af
More Ruff fixes
6e3aa66
More Ruff fixes
7b09e37
More Ruff fixes
cd5551d
More Ruff fixes
4d471c7
More Ruff fixes
06ce22e
More Ruff fixes
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| # This file is part of the ISIS IBEX application. | ||
| # Copyright (C) 2012-2025 Science & Technology Facilities Council. | ||
| # All rights reserved. | ||
| # | ||
| # This program is distributed in the hope that it will be useful. | ||
| # This program and the accompanying materials are made available under the | ||
| # terms of the Eclipse Public License v1.0 which accompanies this distribution. | ||
| # EXCEPT AS EXPRESSLY SET FORTH IN THE ECLIPSE PUBLIC LICENSE V1.0, THE PROGRAM | ||
| # AND ACCOMPANYING MATERIALS ARE PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES | ||
| # OR CONDITIONS OF ANY KIND. See the Eclipse Public License v1.0 for more details. | ||
| # | ||
| # You should have received a copy of the Eclipse Public License v1.0 | ||
| # along with this program; if not, you can obtain a copy from | ||
| # https://www.eclipse.org/org/documents/epl-v10.php or | ||
| # http://opensource.org/licenses/eclipse-1.0.php | ||
|
|
||
| import copy | ||
| from typing import Any, Dict, List, Union | ||
| from collections import OrderedDict | ||
|
|
||
|
|
||
| class Globalmacro: | ||
| """Represents an IOC with its global macros. | ||
|
|
||
| Attributes: | ||
| name (string): The name of the IOC | ||
| macros (dict): The IOC's macros | ||
| """ | ||
|
|
||
| def __init__( | ||
| self, | ||
| name: str, | ||
| macros: Dict[str, str], | ||
| ): | ||
| """Constructor. | ||
|
|
||
| Args: | ||
| name: The name of the IOC | ||
| macros: The IOC's macros | ||
| """ | ||
| self.name = name | ||
|
|
||
| if macros is None: | ||
| self.macros = {} | ||
| else: | ||
| self.macros = macros | ||
|
|
||
| @staticmethod | ||
| def _dict_to_list(in_dict: Dict[str, Any]) -> List[Any]: | ||
| """Converts into a format better for the GUI to parse, namely a list. | ||
|
|
||
| Args: | ||
| in_dict: The dictionary to be converted | ||
|
|
||
| Returns: | ||
| The newly created list | ||
| """ | ||
| out_list = [] | ||
| if in_dict: | ||
| for k, v in in_dict.items(): | ||
| # Take a copy as we do not want to modify the original | ||
| c = copy.deepcopy(v) | ||
| c["name"] = k | ||
| out_list.append(c) | ||
| return out_list | ||
|
|
||
| def __str__(self) -> str: | ||
| return f"{self.__class__.__name__}(name={self.name})" | ||
|
|
||
| def to_dict(self) -> Dict[str, Dict[str, str]]: | ||
| """Puts the IOC-globalmacro's details into a dictionary. | ||
|
|
||
| Returns: | ||
| The IOC-Global Macros' details | ||
| """ | ||
| return { | ||
| "name": self.name, | ||
| "macros": self.macros, | ||
| } | ||
|
|
||
| def get(self, name): | ||
| return self.__getattribute__(name) | ||
|
|
||
| def __getitem__(self, name): | ||
| return self.__getattribute__(name) | ||
|
|
||
|
|
||
| class GlobalmacroHelper: | ||
| """Converts global macro data to Globalmacro Object. | ||
|
|
||
| Consists of static methods only. | ||
| """ | ||
|
|
||
| @staticmethod | ||
| def row_to_globalmacro(globalmacros: Dict, row: str): | ||
| """converts a row from the globals file to globalmacro data. | ||
|
|
||
| Args: | ||
| globalmacros: The current list of global macros | ||
| row: The IOC's (or All IOCs) global macro record | ||
| """ | ||
| IOC_SEPARATOR = "__" | ||
| EQUAL_TO = "=" | ||
| ALL_IOCS = IOC_SEPARATOR | ||
| # Each record is of the form IOC__MACRO=VALUE | ||
| # Where there is no __ the Macro is applicable for all IOCs | ||
| if EQUAL_TO in row: | ||
| ioc_macro, value = row.rsplit(EQUAL_TO, maxsplit=1) | ||
| to_add_ioc = {} | ||
| if IOC_SEPARATOR in ioc_macro: | ||
| ioc, macro = ioc_macro.split(IOC_SEPARATOR, maxsplit=1) | ||
| else: | ||
| ioc = ALL_IOCS | ||
| macro = ioc_macro | ||
|
|
||
| if ioc in globalmacros: | ||
| to_add_ioc = globalmacros[ioc] | ||
| to_add_ioc[macro] = value.strip() | ||
| globalmacros[ioc] = to_add_ioc | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.