Skip to content

Home Information - Your home, your data, organized.

Python

Created simulator.py wrapper script.

Anthony Cassandra434be5a04075
diff --git a/src/hi/simulator/management/__init__.py b/src/hi/simulator/management/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/src/hi/simulator/management/commands/__init__.py b/src/hi/simulator/management/commands/__init__.py
deleted file mode 100644
index e69de29b..00000000
diff --git a/src/hi/simulator/management/commands/runsim.py b/src/hi/simulator/management/commands/runsim.py
deleted file mode 100644
index bc5ecb21..00000000
--- a/src/hi/simulator/management/commands/runsim.py
+++ /dev/null
@@ -1,23 +0,0 @@
-import os
-
-from django.core.management.commands.runserver import Command as RunserverCommand
-
-
-class Command(RunserverCommand):
-
- help = "Runs the simulator server (separate port, custom settings)."
-
- def add_arguments(self, parser):
- super().add_arguments( parser )
- parser.add_argument(
- '--port', type = int, default = 8001,
- help = 'Port number to run the simulator server on.',
- )
- return
-
- def handle(self, *args, **options):
- os.environ['DJANGO_SETTINGS_MODULE'] = 'hi.settings.simulator'
- options['addrport'] = str(options['port'])
- super().handle(*args, **options)
- return
-
diff --git a/src/hi/simulator/urls.py b/src/hi/simulator/urls.py
index 238656df..a95083fe 100644
--- a/src/hi/simulator/urls.py
+++ b/src/hi/simulator/urls.py
@@ -2,6 +2,6 @@ from django.urls import re_path
from . import views
urlpatterns = [
- re_path( r'^simulate$', views.simulate, name = 'simulator_home' ),
- re_path( r'^setup$', views.setup, name = 'simulator_setup' ),
+ re_path( r'^$', views.simulate, name = 'home' ),
+ re_path( r'^setup$', views.setup, name = 'setup' ),
]
diff --git a/src/simulator.py b/src/simulator.py
new file mode 100755
index 00000000..2cd0df5c
--- /dev/null
+++ b/src/simulator.py
@@ -0,0 +1,34 @@
+#!/usr/bin/env python3
+import os
+import sys
+from subprocess import run
+
+
+def main():
+ settings_module = 'hi.settings.simulator'
+ os.environ['DJANGO_SETTINGS_MODULE'] = settings_module
+
+ # Ensure manage.py is being used
+ manage_py_path = os.path.join( os.path.dirname(__file__), 'manage.py' )
+ if not os.path.exists( manage_py_path ):
+ print("Error: manage.py not found in the current directory.")
+ sys.exit(1)
+
+ if len(sys.argv) < 2:
+ print( "Usage: simulator.py <command> [options]" )
+ sys.exit(1)
+
+ # Different default port for simulator's "runserver"
+ command = sys.argv[1]
+ command_args = sys.argv[2:]
+ if command == "runserver":
+ if not any( arg.isdigit() for arg in command_args ):
+ command_args.append( "8001" )
+
+ full_command = [ 'python', manage_py_path, command ] + command_args + [ f'--settings={settings_module}' ]
+ result = run( full_command )
+ sys.exit( result.returncode )
+
+
+if __name__ == "__main__":
+ main()