Skip to content

Commit 809f998

Browse files
committed
v0.10.0b
Working beta build of v0.10.0
1 parent c73844c commit 809f998

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

78 files changed

+6183
-1558
lines changed

build/lib/mudpi/__main__.py

+70-137
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
import os
88
import sys
99
import time
10+
import datetime
1011
import argparse
1112
import threading
12-
from mudpi import utils, boot, importer
13+
from mudpi.config import Config
14+
from mudpi import utils, importer
15+
from mudpi.logger.Logger import Logger, LOG_LEVEL
16+
from mudpi.managers.core_manager import CoreManager
1317
from mudpi.constants import __version__, PATH_CONFIG, DEFAULT_CONFIG_FILE, \
1418
FONT_RESET_CURSOR, FONT_RESET, YELLOW_BACK, GREEN_BACK, FONT_GREEN, FONT_RED, FONT_YELLOW, FONT_PADDING
1519
from mudpi.exceptions import ConfigNotFoundError, ConfigFormatError
16-
from mudpi.core import MudPi
17-
from mudpi.config import Config
18-
from mudpi.logger.Logger import Logger, LOG_LEVEL
1920

2021

2122
def main(args=None):
@@ -36,7 +37,7 @@ def main(args=None):
3637
Config().save_to_file(config_path)
3738
return
3839

39-
40+
#######################
4041
### Configurations ###
4142
config_path = os.path.abspath(os.path.join(os.getcwd(), arguments.config))
4243

@@ -45,18 +46,18 @@ def main(args=None):
4546
print(chr(27) + "[2J")
4647
display_greeting()
4748

48-
mudpi = MudPi()
49-
boot.mudpi_from_config(mudpi, config_path)
49+
manager = CoreManager()
50+
manager.load_mudpi_from_config(config_path)
5051

5152
print(f'{"Loading MudPi Configs ":.<{FONT_PADDING+1}} {FONT_GREEN}Complete{FONT_RESET}')
5253

53-
54+
#####################
5455
### Bootstrapping ###
5556

5657
if arguments.debug:
5758
print(f'{YELLOW_BACK}DEBUG MODE ENABLED{FONT_RESET}')
58-
mudpi.config.config["mudpi"]["debug"] = True
59-
print(arguments) #DEBUG
59+
manager.mudpi.config.config["mudpi"]["debug"] = True
60+
# print(arguments) #DEBUG
6061
print(f'Config path: {config_path}') #DEBUG
6162
print(f'Current Directory: {os.getcwd()}')
6263
# print(f'Config keys {mudpi.config.keys()}')
@@ -65,95 +66,77 @@ def main(args=None):
6566
# Logging Module
6667
try:
6768
print('Initializing Logger \r', end='', flush=True)
68-
boot.initialize_logging(mudpi)
69+
manager.initialize_logging()
6970
except Exception as e:
7071
print(f'{"Initializing Logger ":.<{FONT_PADDING}} {FONT_RED}Disabled{FONT_RESET}')
7172

72-
boot.load_mudpi_core(mudpi)
73+
# MudPi Core Systems
74+
manager.load_mudpi_core()
7375

74-
Logger.log_formatted(
75-
LOG_LEVEL["warning"], "Initializing Core ", "Complete", 'success'
76-
)
76+
Logger.log_formatted(LOG_LEVEL["warning"], "Initializing Core ", "Complete", 'success')
7777

78-
loaded_extensions = boot.load_all_extensions(mudpi)
78+
Logger.log(LOG_LEVEL["debug"], f'{" Detecting Configurations ":_^{FONT_PADDING+8}}')
79+
# Load the Extension System
80+
loaded_extensions = manager.load_all_extensions()
7981

8082
Logger.log_formatted(
81-
LOG_LEVEL["warning"], f"Loaded {len(loaded_extensions)} Prepared Extensions ", "Complete", 'success'
83+
LOG_LEVEL["warning"], f"Loaded {len(loaded_extensions)} Extensions ", "Complete", 'success'
8284
)
8385

84-
85-
# #########################
86-
# ### Register Workers ###
87-
# for worker in mudpi.config.workers:
88-
# worker_type = f'linux.{worker["type"]}_worker'
89-
# wrker = importer.get_worker(worker_type)
90-
# # Worker import magic
91-
# if wrker:
92-
# clss = [item for item in utils.get_module_classes(wrker.__name__) if 'Worker' in item[0] and item[0] is not "Worker"]
93-
# worker_instance = clss[0][1](mudpi, worker)
94-
# registered_worker_count += 1
95-
# else:
96-
# # Unable to import module
97-
# Logger.log(
98-
# LOG_LEVEL["error"],
99-
# f'{f"Failed Loading {worker_type} ":.<{FONT_PADDING}} {FONT_RED}Failed{FONT_RESET}'
100-
# )
101-
#
102-
103-
Logger.log_formatted(
104-
LOG_LEVEL["warning"],
105-
"Booting MudPi ", 'Complete', 'success'
106-
)
86+
Logger.log_formatted(LOG_LEVEL["warning"], "MudPi Fully Loaded", 'Complete', 'success')
10787

10888
#########################
10989
### Start All Systems ###
110-
Logger.log_formatted(
111-
LOG_LEVEL["info"],
112-
"Signaling All Workers to Start ", 'Pending', 'notice'
113-
)
114-
# for worker in mudpi.worker_registry:
115-
# t = mudpi.worker_registry[worker].run()
116-
# mudpi.threads.append(t)
117-
118-
mudpi.start()
119-
Logger.log_formatted(
120-
LOG_LEVEL["info"],
121-
"Signaling All Workers to Start ", 'Complete', 'success'
122-
)
123-
print(f'{"":_<{FONT_PADDING+8}}')
124-
print('')
90+
Logger.log(LOG_LEVEL["debug"], f'{" Start Systems ":_^{FONT_PADDING+8}}')
91+
Logger.log_formatted(LOG_LEVEL["debug"], "Starting All Workers ", 'Pending', 'notice')
92+
manager.mudpi.start_workers()
93+
Logger.log_formatted(LOG_LEVEL["info"], "Started All Workers ", 'Complete', 'success')
12594

95+
# Everything should be loaded and running
96+
Logger.log_formatted(LOG_LEVEL["info"], "MudPi Systems ", 'Online', 'success')
97+
print(f'{"":_<{FONT_PADDING+8}}\n')
12698

12799
""" Debug Mode Dump After System Online """
128-
if arguments.debug:
129-
debug_dump(mudpi)
100+
if arguments.debug and arguments.dump:
101+
manager.debug_dump(cache_dump=arguments.cache_dump)
102+
time.sleep(1)
103+
130104

105+
###############################
106+
""" MAIN PROGRAM HEARTBEAT """
107+
manager.mudpi.start()
108+
PROGRAM_RUNNING = True
109+
while PROGRAM_RUNNING:
110+
try:
111+
# Keep messages being processed
112+
manager.mudpi.events.get_message()
113+
current_clock = datetime.datetime.now().replace(microsecond=0)
114+
manager.mudpi.events.publish('clock', {"clock":current_clock.strftime("%m-%d-%Y %H-%M-%S"),
115+
"date":str(current_clock.date()), "time": str(current_clock.time())})
116+
for i in range(10):
117+
time.sleep(0.1)
118+
manager.mudpi.events.get_message()
119+
except KeyboardInterrupt as error:
120+
PROGRAM_RUNNING = False
121+
except Exception as error:
122+
Logger.log(
123+
LOG_LEVEL["error"],
124+
f"Runtime Error: {error}"
125+
)
126+
PROGRAM_RUNNING = False
131127

132128
""" PROGRAM SHUTDOWN """
133-
time.sleep(5)
134-
mudpi.shutdown()
135-
136-
for thread in mudpi.threads:
137-
thread.join()
138-
139-
# Check the config
140-
#
141-
# Check other options before running
142-
#
143-
# Boot Up MudPi
144-
# - MudPi Set to LOADING
145-
# - Load the Config from Conf Path
146-
# - Load the MudPi Core Components
147-
# - Load the Event Bus (redis)
148-
# - Load the State Manager (redis)
149-
# - Load all Workers and Register Them
150-
# - Workers initalize components
151-
#
152-
# - MudPi Set to STARTING
153-
# - Set Threading Event for Core
154-
# - Start Up all Registered Workers
155-
#
156-
# - MudPi Set to RUNNING
129+
print(f'{"":_<{FONT_PADDING+8}}')
130+
Logger.log_formatted(
131+
LOG_LEVEL["info"],
132+
"Stopping All Workers for Shutdown ", 'Pending', 'notice'
133+
)
134+
manager.mudpi.shutdown()
135+
136+
Logger.log_formatted(
137+
LOG_LEVEL["info"],
138+
"All MudPi Systems ", 'Offline', 'error'
139+
)
157140

158141

159142
def get_arguments():
@@ -174,6 +157,12 @@ def get_arguments():
174157
parser.add_argument(
175158
"--debug", action="store_true", help="Start MudPi in forced debug mode"
176159
)
160+
parser.add_argument(
161+
"--dump", action="store_true", help="Display important system information"
162+
)
163+
parser.add_argument(
164+
"--cache_dump", action="store_true", help="Display cache when --dump is set"
165+
)
177166
parser.add_argument(
178167
"--verbose", action="store_true", help="Enable verbose output."
179168
)
@@ -211,61 +200,5 @@ def display_greeting():
211200
print(FONT_RESET)
212201

213202

214-
def debug_dump(mudpi):
215-
""" Dump important data from MudPi instance for debugging mode """
216-
Logger.log(
217-
LOG_LEVEL["debug"],
218-
f'{YELLOW_BACK}MUDPI CACHE DUMP{FONT_RESET}'
219-
)
220-
for key in mudpi.cache.keys():
221-
Logger.log(
222-
LOG_LEVEL["debug"],
223-
f"{FONT_YELLOW}{key}:{FONT_RESET} {mudpi.cache[key]}"
224-
)
225-
226-
Logger.log(
227-
LOG_LEVEL["debug"],
228-
f'{YELLOW_BACK}MUDPI LOADED EXTENSIONS{FONT_RESET}'
229-
)
230-
for ext in mudpi.extensions.all():
231-
ext = mudpi.cache.get("extension_importers", {}).get(ext)
232-
Logger.log(
233-
LOG_LEVEL["debug"],
234-
f"Namespace: {FONT_YELLOW}{ext.namespace}{FONT_RESET}\n{ext.description}\n{ext.documentation}"
235-
)
236-
237-
if mudpi.components.all():
238-
Logger.log(
239-
LOG_LEVEL["debug"],
240-
f'{YELLOW_BACK}MUDPI REGISTERED COMPONENTS{FONT_RESET}'
241-
)
242-
Logger.log(
243-
LOG_LEVEL["debug"],
244-
f"{'COMPONENT':<10} {'ID':<20} NAME\n{'':-<60}"
245-
)
246-
for comp in mudpi.components.all():
247-
comp = mudpi.components.get(comp)
248-
Logger.log(
249-
LOG_LEVEL["debug"],
250-
f"{comp.__class__.__name__:<10} | {comp.id:<20} | {comp.name}"
251-
)
252-
253-
if mudpi.actions.all():
254-
Logger.log(
255-
LOG_LEVEL["debug"],
256-
f'{YELLOW_BACK}MUDPI REGISTERED ACTIONS{FONT_RESET}'
257-
)
258-
Logger.log(
259-
LOG_LEVEL["debug"],
260-
f"{'ACTION CALL':<24} {'ACTION':<20} NAMESPACE\n{'':-<60}"
261-
)
262-
for namespace, actions in mudpi.actions.items():
263-
for key, action in actions.items():
264-
action_command = f"{namespace}.{key}" if namespace else key
265-
Logger.log(
266-
LOG_LEVEL["debug"],
267-
f"{action_command:<24} | {key:<20} | {namespace}"
268-
)
269-
270203
if __name__ == "__main__":
271204
sys.exit(main())

build/lib/mudpi/action.py

-56
This file was deleted.

0 commit comments

Comments
 (0)