|
| 1 | +# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +# |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
| 23 | +""" |
| 24 | +Unregisters the Code Generator extension registry files (SRG). |
| 25 | +
|
| 26 | +Refer to the :ref:`installation <getting_started/index:install in user mode>` |
| 27 | +steps for more information. |
| 28 | +
|
| 29 | +It addresses SCADE 2024 R2 and prior releases. |
| 30 | +SCADE 2025 R1 and above use the package's |
| 31 | +``ansys.scade.registry`` entry point. |
| 32 | +""" |
| 33 | + |
| 34 | +import os |
| 35 | +from pathlib import Path |
| 36 | +import sys |
| 37 | +from typing import Tuple |
| 38 | + |
| 39 | +from ansys.scade.python_wrapper import get_srg_name |
| 40 | + |
| 41 | +_APPDATA = os.getenv('APPDATA') |
| 42 | + |
| 43 | + |
| 44 | +def _unregister_srg_file(name: str): |
| 45 | + """Delete the srg file from Customize.""" |
| 46 | + assert _APPDATA |
| 47 | + dst = Path(_APPDATA, 'SCADE', 'Customize', name) |
| 48 | + dst.unlink(missing_ok=True) |
| 49 | + |
| 50 | + |
| 51 | +def unregister() -> Tuple[int, str]: |
| 52 | + """Implement the ``ansys.scade.registry/unregister`` entry point.""" |
| 53 | + _unregister_srg_file(get_srg_name()) |
| 54 | + return (0, '') |
| 55 | + |
| 56 | + |
| 57 | +def main(): |
| 58 | + """Implement the ``ansys.scade.python_wrapper.unregister`` packages's project script.""" |
| 59 | + code, message = unregister() |
| 60 | + if message: |
| 61 | + print(message, file=sys.stderr if code else sys.stdout) |
| 62 | + return code |
| 63 | + |
| 64 | + |
| 65 | +if __name__ == '__main__': |
| 66 | + code = main() |
| 67 | + sys.exit(code) |
0 commit comments