Skip to content

Commit

Permalink
[fixinventory][fix] Ensure backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
lloesche committed Mar 1, 2024
1 parent 7d348d6 commit df497f2
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fixcore/fixcore/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
from fixcore.web.certificate_handler import CertificateHandlerWithCA, CertificateHandlerNoCA
from fixcore.worker_task_queue import WorkerTaskQueue
from fixlib.asynchronous.web import runner
from fixlib.utils import ensure_bw_compat

log = logging.getLogger("fixcore")

Expand All @@ -75,6 +76,7 @@ def main() -> None:
"""
Application entrypoint - no arguments are allowed.
"""
ensure_bw_compat()

Check warning on line 79 in fixcore/fixcore/__main__.py

View check run for this annotation

Codecov / codecov/patch

fixcore/fixcore/__main__.py#L79

Added line #L79 was not covered by tests
try:
run(sys.argv[1:])
log.info("Process finished.")
Expand Down
11 changes: 11 additions & 0 deletions fixlib/fixlib/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -573,3 +573,14 @@ def freeze(elem: JsonElement) -> Any:
return frozendict({k: freeze(v) for k, v in elem.items()})
else:
return elem


def ensure_bw_compat() -> None:
for i, arg in enumerate(sys.argv):
if arg.startswith("--resoto"):
sys.argv[i] = "--fix" + arg[len("--resoto") :]

old_env_vars = [key for key in os.environ if key.startswith("RESOTO")]
for old_env_var in old_env_vars:
new_env_var = "FIX" + old_env_var[len("RESOTO") :]
os.environ[new_env_var] = os.environ.pop(old_env_var)
2 changes: 2 additions & 0 deletions fixmetrics/fixmetrics/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from threading import Event
from typing import Optional
from fixlib.args import ArgumentParser
from fixlib.utils import ensure_bw_compat


shutdown_event = Event()
Expand All @@ -45,6 +46,7 @@ def shutdown(event: FixEvent) -> None:


def main() -> None:
ensure_bw_compat()
setup_logger("fixmetrics")
fixlib.proc.parent_pid = os.getpid()

Expand Down
2 changes: 2 additions & 0 deletions fixshell/fixshell/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from fixshell import authorized_client
from fixshell.promptsession import PromptSession, core_metadata, FixHistory
from fixshell.shell import Shell, ShutdownShellError
from fixlib.utils import ensure_bw_compat


async def main_async() -> None:
Expand Down Expand Up @@ -218,6 +219,7 @@ def header_value(s: str) -> Tuple[str, str]:


def main() -> None:
ensure_bw_compat()
asyncio.run(main_async())
fixlib.proc.kill_children(SIGTERM, ensure_death=True)
log.debug("Shutdown complete")
Expand Down
2 changes: 2 additions & 0 deletions fixworker/fixworker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from fixworker.fixcore import FixCore
from fixworker.tag import core_tag_tasks_processor
from fixworker.exceptions import DuplicateMessageError
from fixlib.utils import ensure_bw_compat

# This will be used in main() and shutdown()
shutdown_event = threading.Event()
Expand All @@ -42,6 +43,7 @@


def main() -> None:
ensure_bw_compat()
setup_logger("fixworker")
# Try to run in a new process group and
# ignore if not possible for whatever reason
Expand Down

0 comments on commit df497f2

Please sign in to comment.