def reload_modules( self ): """Reload all modules. Warning: this is fairly destructive""" # remove modules that no longer exist for module_name in [ m for m in self.modules.keys() if m not in modules.get_modules() ]: self.remove_module( module_name ) # reload all modules for module_name in self.modules: self.reload_module( module_name ) # add modules that are not added yet for module_name in [ m for m in modules.get_modules() if m not in self.modules ]: self.add_module( module_name )
def plasma(): global ismodule while True: if sys.platform == 'win32' or sys.platform == 'win64': print(Fore.LIGHTCYAN_EX + 'plasma> ' + Fore.RESET, end='') cmd = input() else: cmd = input(Fore.LIGHTCYAN_EX + 'plasma> ' + Fore.RESET) #execute selected module for module in modules.get_modules(): if cmd.split(' ')[0] == module.cmdstring: module.execute(cmd) ismodule = True break #if command is not a module check for built in commands if not ismodule: if cmd == 'help': show_help() elif cmd == 'quit' or cmd == 'exit': exit_program() else: print( Fore.LIGHTRED_EX + '[!] Invalid command. Enter \'help\' to see a list of available commands' + Fore.RESET) ismodule = False
def __init__(self, bot, blacklist=None): self.bot = bot self.modules = {} self.loaded_modules = {} blacklist = blacklist or [] for module_name in modules.get_modules(): if module_name in blacklist: continue logging.info( 'Loading module {0}: {1}'.format( module_name, self.add_module( module_name ) ) )
def show_help(): print(Fore.LIGHTCYAN_EX + '\n-------- Commands --------' + Fore.RESET) for module in modules.get_modules(): if module.cmdstring != 'sample': print(Fore.LIGHTYELLOW_EX + module.cmdstring + Fore.RESET + ':\t ' + module.description) print(Fore.LIGHTYELLOW_EX + 'exit' + Fore.RESET + ':\t close all connections and exit program') print(Fore.LIGHTCYAN_EX + '--------------------------\n' + Fore.RESET)
def __init__(self, config, **kwargs): """ Initializes a Cloudjumper instance. Arguments: config: A configuration dict for the bot Keyword Arguments: check_login: Enables crashing on no login on a registered username. fail_after: How many seconds to crash after if you're not registered. use_ssl: Enables SSL, allowing for more security """ self.config = config self.login_info = self.config.get("login", {}) self.settings = self.config.get("settings", {}) self.folder = self.settings.get("module_folder", "main_modules") self.subscribers = collections.defaultdict(list) self.db_name = self.settings.get("database", ":memory:") self.database = sqlite3.connect(self.db_name) self.cursor = self.database.cursor() if self.settings.get("debug", False): lvl = logging.DEBUG else: lvl = logging.INFO logging.getLogger(irc.__name__).setLevel(lvl) # Setup Flag Table if not self.table_exists("Flags"): self.cursor.execute(""" CREATE TABLE Flags ( id INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT NOT NULL, flags TEXT ) """) # Nice and pretty, right? for i in {"__Myst__",}.union(self.settings.get("auto_admin", [])): self.add_flags(i, self.FLAGS["ADMIN"]) # Look, you can hear this 'line' say "Please kill me"! super().__init__(*[self.login_info[i] for i in ("user", "nick", "channel", "host", "port")], **{ "use_ssl": self.settings.get("use_ssl", False) }) if not modules: return self.modules = modules.get_modules(self.folder) for cls in self.modules: if hasattr(cls, "name"): config = self.get_config(cls.name) else: config = {} try: cls(self, config) except: # I hate broad exception clauses. self.logger.debug("[Class '{}' failed in __init__]".format(cls)) traceback.print_exc()
def main(): config = ConfigParser.SafeConfigParser() config.read(['config/general.conf']) lcd = LCD(config.get('Global', 'DisplayPort')) lcd.display_string("PertPy setup in progress...") if config.getboolean('Global', 'Backlight'): lcd.enable_backlight() else: lcd.disable_backlight() atexit.register(shutdown, lcd) waitlock = RLock() mods = modules.get_modules(config) if not mods: lcd.display_string('No modules loaded.') time.sleep(5) return for module in mods: if hasattr(module, 'PertInterrupt'): interrupt = module.PertInterrupt(lcd, waitlock) interrupt.start() lcd.display_string("PertPy Ready...") lcd.grab_attention() time.sleep(1) sleep_time = config.getint('Global', 'DisplayTime') while True: for mod in mods: print mod if hasattr(mod, 'PertModule'): module = mod.PertModule(lcd, waitlock) with waitlock: lcd.clear_screen() module.start() time.sleep(sleep_time) module.stop() print "Looping again."
def __init__( self, bot ): self.bot = bot self.modules = {} self.loaded_modules = {} for module_name in modules.get_modules(): logging.debug( 'Loading module {0}: {1}'.format( module_name, self.add_module( module_name ) ) )
# this program; if not, write to the Free Software Foundation, Inc., 51 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. # import modules from config import OpenChronosApp initcode = "\ /* This file is autogenerated by tools/make_modinit.py, do not edit! */\n\ \n\ void mod_init(void)\n\ {\n\ " app = OpenChronosApp() app.load_config() cfg = app.get_config() f = open('modinit.c', 'w') f.write(initcode) for mod in modules.get_modules(): MOD = mod.upper() try: if cfg["CONFIG_MOD_%s" % MOD]["value"]: f.write("\tmod_%s_init();\n" % (mod) ) except KeyError: pass f.write("}\n") f.close()
def publish(): for module in get_modules(): module.publish(get_version())
def update(username, password): info('Searching for version...') init_github(username, password) for module in get_modules(): module.update(get_version())
def reset(): for module in get_modules(): module.reset()
/* This file is autogenerated by tools/make_modinit.py, do not edit! */\n\ \n\n" initcode_2 = "\n\ void mod_init(void)\n\ {\n\ " app = OpenChronosApp() app.load_config() cfg = app.get_config() f = open('modinit.c', 'w') f.write(initcode_1) for mod in modules.get_modules(): MOD = mod.upper() try: if cfg["CONFIG_MOD_%s" % MOD]["value"]: f.write("extern void mod_%s_init();\n" % (mod)) except KeyError: pass f.write(initcode_2) for mod in modules.get_modules(): MOD = mod.upper() try: if cfg["CONFIG_MOD_%s" % MOD]["value"]: f.write(" mod_%s_init();\n" % (mod)) except KeyError: pass