def read_data(year, month, day, hour): month = str(month).zfill(2) day = str(day).zfill(2) filename = "data/%d-%s-%s-%d.json.gz" % (year, month, day, hour) command = Command("parse_file", filename) command.execute()
def run(force_setup=False): if sys.version_info[0] == 2: CLI.colored_print("╔═══════════════════════════════════════════════════════════════╗", CLI.COLOR_ERROR) CLI.colored_print("║ DEPRECATION: Python 2.7 has reached the end of its life on ║", CLI.COLOR_ERROR) CLI.colored_print("║ January 1st, 2020. Please upgrade your Python as Python 2.7 ║", CLI.COLOR_ERROR) CLI.colored_print("║ is not maintained anymore. ║", CLI.COLOR_ERROR) CLI.colored_print("║ A future version of KoBoInstall will drop support for it. ║", CLI.COLOR_ERROR) CLI.colored_print("╚═══════════════════════════════════════════════════════════════╝", CLI.COLOR_ERROR) if not platform.system() in ["Linux", "Darwin"]: CLI.colored_print("Not compatible with this OS", CLI.COLOR_ERROR) else: config = Config() current_config = config.get_config() if config.first_time: force_setup = True if force_setup: current_config = config.build() Setup.clone_kobodocker(config) Template.render(config) config.init_letsencrypt() Setup.update_hosts(current_config) else: if config.auto_detect_network(): Template.render(config) Setup.update_hosts(current_config) Command.start()
def post_update(cls, cron): config = Config() # When `cron` is True, we want to bypass question and just recreate # YML and environment files from new templates if cron is True: current_dict = config.get_template() current_dict.update(config.get_dict()) config.set_config(current_dict) Template.render(config, force=True) sys.exit(0) message = ('After an update, it is strongly recommended to run\n' '`python3 run.py --setup` to regenerate environment files.') CLI.framed_print(message, color=CLI.COLOR_INFO) response = CLI.yes_no_question('Do you want to proceed?') if response is True: current_dict = config.build() Template.render(config) config.init_letsencrypt() Setup.update_hosts(current_dict) question = 'Do you want to (re)start containers?' response = CLI.yes_no_question(question) if response is True: Command.start()
def run(force_setup=False): if not platform.system() in ['Linux', 'Darwin']: CLI.colored_print('Not compatible with this OS', CLI.COLOR_ERROR) else: config = Config() dict_ = config.get_dict() if config.first_time: force_setup = True if force_setup: dict_ = config.build() Template.render(config) support = Support() support.copy_support_scripts() # # config.init_letsencrypt() # # Setup.update_hosts(dict_) else: print("Running smoothly") # if config.auto_detect_network(): # Template.render(config) # Setup.update_hosts(dict_) Command.start()
def run(force_setup=False): if sys.version_info[0] == 2: message = ( 'DEPRECATION: Python 2.7 has reached the end of its life on ' 'January 1st, 2020. Please upgrade your Python as Python 2.7 is ' 'not maintained anymore.\n\n' 'A future version of KoBoInstall will drop support for it.') CLI.framed_print(message) if not platform.system() in ['Linux', 'Darwin']: CLI.colored_print('Not compatible with this OS', CLI.COLOR_ERROR) else: config = Config() dict_ = config.get_dict() if config.first_time: force_setup = True if force_setup: dict_ = config.build() Setup.clone_kobodocker(config) Template.render(config) config.init_letsencrypt() Setup.update_hosts(dict_) else: if config.auto_detect_network(): Template.render(config) Setup.update_hosts(dict_) Command.start()
def download_data(year, month, day, hour): month = str(month).zfill(2) day = str(day).zfill(2) url = "http://data.githubarchive.org/%d-%s-%s-%d.json.gz" % ( year, month, day, hour) command = Command("download_file", url) command.execute()
def test_toggle_frontend(): config_object = read_config() Command.start(frontend_only=True) mock_docker = MockDocker() expected_containers = MockDocker.FRONTEND_CONTAINERS + \ MockDocker.LETSENCRYPT assert sorted(mock_docker.ps()) == sorted(expected_containers) Command.stop() assert len(mock_docker.ps()) == 0 del mock_docker
def test_toggle_trivial(): config_object = read_config() Command.start() mock_docker = MockDocker() expected_containers = MockDocker.FRONTEND_CONTAINERS + \ MockDocker.PRIMARY_BACKEND_CONTAINERS + \ MockDocker.LETSENCRYPT assert sorted(mock_docker.ps()) == sorted(expected_containers) Command.stop() assert len(mock_docker.ps()) == 0 del mock_docker
def test_toggle_no_letsencrypt(): config_object = read_config() config_object._Config__config['use_letsencrypt'] = Config.FALSE Command.start() mock_docker = MockDocker() expected_containers = MockDocker.FRONTEND_CONTAINERS + \ MockDocker.PRIMARY_BACKEND_CONTAINERS assert sorted(mock_docker.ps()) == sorted(expected_containers) Command.stop() assert len(mock_docker.ps()) == 0 del mock_docker
def test_toggle_primary_backend(): config_object = read_config() config_object._Config__config['backend_server_role'] = 'primary' config_object._Config__config['server_role'] = 'backend' config_object._Config__config['multi'] = Config.TRUE Command.start() mock_docker = MockDocker() expected_containers = MockDocker.PRIMARY_BACKEND_CONTAINERS assert sorted(mock_docker.ps()) == sorted(expected_containers) Command.stop() assert len(mock_docker.ps()) == 0 del mock_docker
def test_toggle_secondary_backend(): config_object = read_config() config_object._Config__dict['backend_server_role'] = 'secondary' config_object._Config__dict['server_role'] = 'backend' config_object._Config__dict['multi'] = True mock_docker = MockDocker() Command.start() expected_containers = MockDocker.SECONDARY_BACKEND_CONTAINERS assert sorted(mock_docker.ps()) == sorted(expected_containers) Command.stop() assert len(mock_docker.ps()) == 0 del mock_docker
def run(force_setup=False): if not platform.system() in ["Linux", "Darwin"]: CLI.colored_print("Not compatible with this OS", CLI.COLOR_ERROR) else: config = Config() current_config = config.get_config() if not current_config: force_setup = True if force_setup: current_config = config.build() Setup.run(current_config) Template.render(config) Setup.update_hosts(current_config) else: if config.auto_detect_network(): Template.render(config) Setup.update_hosts(current_config) Command.start()
def run(force_setup=False): if not platform.system() in ['Linux', 'Darwin']: CLI.colored_print('Not compatible with this OS', CLI.COLOR_ERROR) else: config = Config() dict_ = config.get_dict() if config.first_time: force_setup = True if force_setup: dict_ = config.build() Setup.clone_kobodocker(config) Template.render(config) Setup.update_hosts(dict_) else: if config.auto_detect_network(): Template.render(config) Setup.update_hosts(dict_) config.validate_passwords() Command.start(force_setup=force_setup)
def post_update(cls, cron): config_object = Config() # When `cron` is True, we want to bypass question and just recreate # YML and environment files from new templates if cron is True: current_config = config_object.get_config_template() current_config.update(config_object.get_config()) config_object.set_config(current_config) Template.render(config_object, force=True) sys.exit(0) CLI.colored_print("╔═════════════════════════════════════════════════════╗", CLI.COLOR_WARNING) CLI.colored_print("║ After an update, it's strongly recommended to run ║", CLI.COLOR_WARNING) CLI.colored_print("║ `./run.py --setup` to regenerate environment files. ║", CLI.COLOR_WARNING) CLI.colored_print("╚═════════════════════════════════════════════════════╝", CLI.COLOR_WARNING) CLI.colored_print("Do you want to proceed?", CLI.COLOR_SUCCESS) CLI.colored_print("\t1) Yes") CLI.colored_print("\t2) No") response = CLI.get_response([Config.TRUE, Config.FALSE], Config.TRUE) if response == Config.TRUE: current_config = config_object.build() Template.render(config_object) config_object.init_letsencrypt() Setup.update_hosts(current_config) CLI.colored_print("Do you want to (re)start containers?", CLI.COLOR_SUCCESS) CLI.colored_print("\t1) Yes") CLI.colored_print("\t2) No") response = CLI.get_response([Config.TRUE, Config.FALSE], Config.TRUE) if response == Config.TRUE: Command.start()
def test_toggle_maintenance(): config_object = read_config() mock_docker = MockDocker() Command.start() expected_containers = MockDocker.FRONTEND_CONTAINERS + \ MockDocker.PRIMARY_BACKEND_CONTAINERS + \ MockDocker.LETSENCRYPT assert sorted(mock_docker.ps()) == sorted(expected_containers) config_object._Config__config['maintenance_enabled'] = True Command.start() maintenance_containers = MockDocker.PRIMARY_BACKEND_CONTAINERS + \ MockDocker.MAINTENANCE_CONTAINERS + \ MockDocker.LETSENCRYPT assert sorted(mock_docker.ps()) == sorted(maintenance_containers) config_object._Config__config['maintenance_enabled'] = False Command.start() assert sorted(mock_docker.ps()) == sorted(expected_containers) Command.stop() assert len(mock_docker.ps()) == 0 del mock_docker
def message_received(self, text): message = text.message.strip() user = GM.mumble.users[text.actor] if "<img" in message: reg_print(f"Message Received: [{user['name']} -> Image Data]") elif "<a href=" in message: reg_print(f"Message Received: [{user['name']} -> Hyperlink Data]") else: reg_print(f"Message Received: [{user['name']} -> {message}]") if message[0] == self.cmd_token: GM.logger.info(f"Commands Received: [{user['name']} -> {message}]") self.live_plugin_check() # example input: !version ; !about ; !yt twice ; !p ; !status all_commands = [msg.strip() for msg in message.split(';')] # example output: ["!version", "!about", "!yt twice", "!p", "!status"] # add to command history cmd_list = [GM.cmd_history.insert(cmd) for cmd in all_commands] if len(all_commands) > self.multi_cmd_limit: reg_print( f"The multi-command limit was reached! The multi-command limit is {self.multi_cmd_limit} commands per line.") GM.logger.warning( f"The multi-command d! The multi-command limit is {self.multi_cmd_limit} commands per line.") return # Iterate through all commands provided and generate commands. for i, item in enumerate(all_commands): # Generate command with parameters new_text = copy.deepcopy(text) new_text.message = item new_command = None try: new_command = Command(item[1:].split()[0], new_text) except IndexError: continue if new_command.command in aliases.aliases: alias_commands = [msg.strip() for msg in aliases.aliases[new_command.command].split('|')] if len(alias_commands) > self.multi_cmd_limit: reg_print( f"The multi-command limit was reached! The multi-command limit is {self.multi_cmd_limit} commands per line.") GM.logger.warning( f"The multi-command limit was reached! The multi-command limit is {self.multi_cmd_limit} commands per line.") return for x, sub_item in enumerate(alias_commands): sub_text = copy.deepcopy(text) if len(item[1:].split()) > 1: sub_text.message = f"{sub_item} {item[1:].split(' ', 1)[1]}" else: sub_text.message = sub_item sub_command = None try: sub_command = Command(sub_item[1:].split()[0], sub_text) except IndexError: continue self.command_queue.insert(sub_command) else: # Insert command into the command queue self.command_queue.insert(new_command) # Process commands if the queue is not empty while not self.command_queue.is_empty(): # Process commands in the queue self.process_command_queue(self.command_queue.pop()) time.sleep(self.tick_rate)
if __name__ == '__main__': try: # avoid infinite self-updating loops update_self = Updater.NO_UPDATE_SELF_OPTION not in sys.argv while True: try: sys.argv.remove(Updater.NO_UPDATE_SELF_OPTION) except ValueError: break if len(sys.argv) > 2: if sys.argv[1] == '-cf' or sys.argv[1] == '--compose-frontend': Command.compose_frontend(sys.argv[2:]) elif sys.argv[1] == '-cb' or sys.argv[1] == '--compose-backend': Command.compose_backend(sys.argv[2:]) elif sys.argv[1] == '-u' or sys.argv[1] == '--update': Updater.run(sys.argv[2], update_self=update_self) elif sys.argv[1] == '--upgrade': Updater.run(sys.argv[2], update_self=update_self) elif sys.argv[1] == '--auto-update': Updater.run(sys.argv[2], cron=True, update_self=update_self) else: CLI.colored_print("Bad syntax. Try 'run.py --help'", CLI.COLOR_ERROR) elif len(sys.argv) == 2: if sys.argv[1] == '-h' or sys.argv[1] == '--help': Command.help() elif sys.argv[1] == '-u' or sys.argv[1] == '--update':
def remote_command(self, message): if message[0] == self.cmd_token: GM.logger.info(f"Commands Received: [RemoteWebCall] -> {message}]") self.live_plugin_check() text = RemoteTextMessage(channel_id=GM.mumble.users.myself['channel_id'], session=GM.mumble.users.myself['session'], message=message, actor=GM.mumble.users.myself['session']) all_commands = [msg.strip() for msg in message.split(';')] # add to command history cmd_list = [GM.cmd_history.insert(cmd) for cmd in all_commands] if len(all_commands) > self.multi_cmd_limit: reg_print( f"The multi-command limit was reached! The multi-command limit is {self.multi_cmd_limit} commands per line.") GM.logger.warning( f"The multi-command limit was reached! The multi-command limit is {self.multi_cmd_limit} commands per line.") return # Iterate through all commands provided and generate commands. for i, item in enumerate(all_commands): # Generate command with parameters # new_text = copy.deepcopy(text) new_text = RemoteTextMessage(channel_id=GM.mumble.users.myself['channel_id'], session=GM.mumble.users.myself['session'], message=message, actor=GM.mumble.users.myself['session']) new_text.message = item new_command = None try: new_command = Command(item[1:].split()[0], new_text) except IndexError: continue if new_command.command in aliases.aliases: alias_commands = [msg.strip() for msg in aliases.aliases[new_command.command].split('|')] if len(alias_commands) > self.multi_cmd_limit: reg_print( f"The multi-command limit was reached! The multi-command limit is {self.multi_cmd_limit} commands per line.") GM.logger.warning( f"The multi-command limit was reached! The multi-command limit is {self.multi_cmd_limit} commands per line.") return for x, sub_item in enumerate(alias_commands): # sub_text = copy.deepcopy(text) sub_text = RemoteTextMessage(channel_id=GM.mumble.users.myself['channel_id'], session=GM.mumble.users.myself['session'], message=message, actor=GM.mumble.users.myself['session']) if len(item[1:].split()) > 1: sub_text.message = f"{sub_item} {item[1:].split(' ', 1)[1]}" else: sub_text.message = sub_item sub_command = None try: sub_command = Command(sub_item[1:].split()[0], sub_text) except IndexError: continue self.command_queue.insert(sub_command) else: # Insert command into the command queue self.command_queue.insert(new_command) # Process commands if the queue is not empty while not self.command_queue.is_empty(): # Process commands in the queue self.process_command_queue(self.command_queue.pop()) time.sleep(self.tick_rate)
config.init_letsencrypt() Setup.update_hosts(current_config) else: if config.auto_detect_network(): Template.render(config) Setup.update_hosts(current_config) Command.start() if __name__ == "__main__": if len(sys.argv) > 2: CLI.colored_print("Bad syntax. Try 'run.py --help'", CLI.COLOR_ERROR) elif len(sys.argv) == 2: if sys.argv[1] == "-h" or sys.argv[1] == "--help": Command.help() elif sys.argv[1] == "-u" or sys.argv[1] == "--upgrade": Command.upgrade() elif sys.argv[1] == "-i" or sys.argv[1] == "--info": Command.info(0) elif sys.argv[1] == "-s" or sys.argv[1] == "--setup": run(force_setup=True) elif sys.argv[1] == "-S" or sys.argv[1] == "--stop": Command.stop() elif sys.argv[1] == "-l" or sys.argv[1] == "--logs": Command.logs() elif sys.argv[1] == "-b" or sys.argv[1] == "--build": Command.build() elif sys.argv[1] == "-bkf" or sys.argv[1] == "--build-kpi": Command.build("kf") elif sys.argv[1] == "-bkc" or sys.argv[1] == "--build-kobocat":
# if config.auto_detect_network(): # Template.render(config) # Setup.update_hosts(dict_) Command.start() if __name__ == '__main__': try: if len(sys.argv) > 2: CLI.colored_print("Bad syntax. Try 'run.py --help'", CLI.COLOR_ERROR) elif len(sys.argv) == 2: if sys.argv[1] == '-h' or sys.argv[1] == '--help': Command.help() Updater.run(cron=True, update_self=update_self) elif sys.argv[1] == '-s' or sys.argv[1] == '--setup': run(force_setup=True) elif sys.argv[1] == '-S' or sys.argv[1] == '--stop': Command.stop() # elif sys.argv[1] == '-l' or sys.argv[1] == '--logs': # Command.logs() # elif sys.argv[1] == '-v' or sys.argv[1] == '--version': # Command.version() else: CLI.colored_print("Bad syntax. Try 'run.py --help'", CLI.COLOR_ERROR) else: run() except KeyboardInterrupt:
Template.render(config) Setup.update_hosts(current_config) else: if config.auto_detect_network(): Template.render(config) Setup.update_hosts(current_config) Command.start() if __name__ == "__main__": if len(sys.argv) > 2: CLI.colored_print("Bad syntax. Try 'run.py --help'", CLI.COLOR_ERROR) elif len(sys.argv) == 2: if sys.argv[1] == "-h" or sys.argv[1] == "--help": Command.help() elif sys.argv[1] == "-u" or sys.argv[1] == "--upgrade": Command.upgrade() elif sys.argv[1] == "-i" or sys.argv[1] == "--info": Command.info(0) elif sys.argv[1] == "-s" or sys.argv[1] == "--setup": run(force_setup=True) elif sys.argv[1] == "-S" or sys.argv[1] == "--stop": Command.stop() elif sys.argv[1] == "-l" or sys.argv[1] == "--logs": Command.logs() else: CLI.colored_print("Bad syntax. Try 'run.py --help'", CLI.COLOR_ERROR) else: run()
Setup.run(current_config) Template.render(config) config.init_letsencrypt() Setup.update_hosts(current_config) else: if config.auto_detect_network(): Template.render(config) Setup.update_hosts(current_config) Command.start() if __name__ == "__main__": if len(sys.argv) > 2: if sys.argv[1] == "-cf" or sys.argv[1] == "--compose-frontend": Command.compose_frontend(sys.argv[2:]) elif sys.argv[1] == "-cb" or sys.argv[1] == "--compose-backend": Command.compose_backend(sys.argv[2:]) else: CLI.colored_print("Bad syntax. Try 'run.py --help'", CLI.COLOR_ERROR) elif len(sys.argv) == 2: if sys.argv[1] == "-h" or sys.argv[1] == "--help": Command.help() elif sys.argv[1] == "-u" or sys.argv[1] == "--upgrade": Command.upgrade() elif sys.argv[1] == "-i" or sys.argv[1] == "--info": Command.info(0) elif sys.argv[1] == "-s" or sys.argv[1] == "--setup": run(force_setup=True) elif sys.argv[1] == "-S" or sys.argv[1] == "--stop":