Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions IoTuring/Configurator/AutostartConfigurator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import sys
import autostarter # works only with https://github.com/richibrics/autostarter.git at the moment, waiting for PR to be merged
from IoTuring.MyApp.App import App

# todo check if autostart is enabled or disabled (need autostarter creator to add this feature)
class AutostartConfigurator():
def run():
selection = False
while selection is False:
print("\nConfiguring autostart...")
print("1 - Enable autostart [system-wide]")
print("2 - Disable autostart [system-wide]")
print("3 - Enable autostart [user-wide]")
print("4 - Disable autostart [user-wide]")
selection = input("Select an option: ")

if selection == "1":
AutostartConfigurator.enable(True)
elif selection == "2":
AutostartConfigurator.disable(True)
elif selection == "3":
AutostartConfigurator.enable(False)
elif selection == "4":
AutostartConfigurator.disable(False)
else:
selection = False

def enable(system_wide):
try:
app_name = App.getName()
script_location = f"-m {app_name}"
interpreter=sys.executable

autostarter.add(
script_location,
identifier=app_name,
system_wide=system_wide,
interpreter=interpreter
)
print("Autostart enabled successfully")
except Exception as e:
print("Autostart could not be enabled")
print("Error: " + str(e))

def disable(system_wide):
try:
app_name = App.getName()
result = autostarter.remove(app_name, system_wide=system_wide)

if result is True:
print("Autostart disabled successfully")
else:
print("Autostart could not be disabled")
except Exception as e:
print("Autostart could not be disabled")
print("Error: " + str(e))
5 changes: 5 additions & 0 deletions IoTuring/Configurator/Configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

from IoTuring.Configurator.MenuPreset import MenuPreset

from IoTuring.Configurator.AutostartConfigurator import AutostartConfigurator

BLANK_CONFIGURATION = {'active_entities': [
{"type": "AppInfo"}], 'active_warehouses': []}

Expand Down Expand Up @@ -41,6 +43,7 @@ def Menu(self) -> None:
self.PrintSeparator()
print("1 - Manage entities")
print("2 - Manage warehouses")
print("A - Configure autostart")
print("C - Start IoTuring")
print("Q - Quit\n")

Expand All @@ -58,6 +61,8 @@ def Menu(self) -> None:
run_app = True # Will start the program exiting from here
print("") #  Blank line
self.WriteConfigurations()
elif choice == "a" or choice == "A":
AutostartConfigurator.run()
elif choice == "q" or choice == "Q":
self.WriteConfigurations()
exit(0)
Expand Down
2 changes: 2 additions & 0 deletions IoTuring/Entity/Deployments/Monitor/Monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

from IoTuring.Entity.EntityData import EntityCommand



KEY_TURN_ALL_OFF = 'turn_all_off'
KEY_TURN_ALL_ON = 'turn_all_on'

Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ dependencies = [
"psutil",
"notify2",
"PyYAML",
"importlib_metadata"
"importlib_metadata",
"autostarter @ git+https://github.com/richibrics/autostarter.git"
]

[project.optional-dependencies]
Expand Down