def __init__(self, apps_info): self.app_manager = AppManager() logging.debug("apps info: %s", apps_info) for app_info in apps_info: app = AppInst(app_info["name"], app_info["cmd"], app_info["tags"]) self.app_manager.add_app(app)
def run(self): self.util = Util(self.config) util = self.util appManager = AppManager(self.config, util) api_success_list, api_error_list, service_account, key, setIamPolicyStatus = appManager.run() if api_success_list and len(api_success_list) != 0: self.printProjectList(api_success_list, "Successfully Enabled APIs in following projects") if api_error_list and len(api_error_list) != 0: self.printProjectErrorList(api_error_list, "Error Enabling APIs in following projects") if self.config.getSetIAMPolicy(): self.printIamPolicyStatus(setIamPolicyStatus, "IAM Policy Set Status") self.printInterationData(service_account, key) if key: try: path = os.getcwd() +"/credentials.txt" self.writeToFile(service_account, key, path) logging.info("Copy Of Credentials written to file: " + path) except: logging.exception("Could not write data to file ")
def __init__(self, args, options): self._args = args self._options = options self._usage = "usage: Dandrop start|stop|restart|create|status|config|factoryreset|help" self._app = AppManager(self.pid_file(), debug=self._options.debugmode) self._config = self._app._config self._globs = globals.Globals() self.parseArgs()
class TestAppManager(object): def __init__(self): self.app_manager = AppManager() self.app1 = AppInst("app1", "cmd1", "tag,tag1a,tag1b") self.app_manager.add_app(self.app1) self.app2 = AppInst("app2", "cmd2", "tag,tag2a,tag2b") self.app_manager.add_app(self.app2) def test_list_all_apps(self): apps = self.app_manager.list_all_apps() eq_(len(apps), 2) expect = {self.app1, self.app2} eq_(expect, set(apps)) def test_list_all_tags(self): tags = self.app_manager.list_all_tags() expect = ["tag", "tag1a", "tag1b", "tag2a", "tag2b"] eq_(expect, tags) def test_select_app_by_tags(self): apps = self.app_manager.select_app_by_tags({"tag2a"}) eq_(len(apps), 1) eq_(self.app2, apps[0]) def test_get_app_by_name(self): app = self.app_manager.get_app_by_name("app1") eq_(self.app1, app)
def _setup(self): is_owner = self.sid == AppManager().sio.sid self.text_display.setReadOnly((not is_owner)) self.layout.addWidget(self.text_display) if is_owner: self.layout.addWidget(self.update_button) self.update_button.clicked.connect(self.update_submission) self.setLayout(self.layout)
def _send_text(self): if len(self.text_edit.toPlainText()) == 0: return payload = { "event": "submission", "category": self.radio_list.active, "user_response": self.text_edit.toPlainText() } AppManager().emit("retro", payload)
def init_update(self, server_data): color_game_data = server_data['color_game'] user_data = server_data['users'][AppManager().sio.sid] self._set_user_color(user_data.get('color', None)) color = color_game_data.get("current_color", None) print("Current color:", color) if color: self._set_current_color(color)
def __init__(self): self.root = tk.Tk() self.text = tk.Text(self.root, background='black', foreground='white', font=('Roboto Slab', 72)) self.initialize_gui() self.initialize_logging() self.current_cmd = '' self.app_manager = AppManager()
def __init__(self, args, options): self._args = args self._options = options self._usage = "usage: pythondrop start|stop|restart|create|status|config|factoryreset|help" self._app = AppManager(self.pid_file(), debug=self._options.debugmode) self._config = self._app._config self._globs = globals.Globals() self.parseArgs()
def set_name(self): if self.name.isEnabled(): if len(self.name.text()) == 0: print("Enter a name!") return self.name.setDisabled(True) self.set_name_button.setDisabled(True) name_payload = {"event": "join", "name": self.name.text()} AppManager().emit("retro", name_payload) self.row_one.setEnabled(True) self.row_two.setEnabled(True) self.submit_row.setEnabled(True)
def main(): try: # paths PATH_CURRENT_DIR = os.path.dirname(os.path.abspath(__file__)) app_man = AppManager( os.path.join(PATH_CURRENT_DIR, '../assets/data/config_data.json'), os.path.join(PATH_CURRENT_DIR, '../assets/data/learning_data.csv')) app_man.run() app_man.close() except Exception as ex: print(ex)
def __init__(self, app_man, *args, **kwargs): super(RetroWidget, self).__init__(*args, **kwargs) self.app_man = app_man self.layout = QVBoxLayout() self.name_row = QHBoxLayout() ##### Everything we need for display boxes ##### self.row_one = QHBoxLayout() self.row_two = QHBoxLayout() self.submit_row = QVBoxLayout() self.display_boxes = dict() self.categories = [ "What went well?", "What did not go well?", "Share something we should start doing.", "Hate it? Want to stop doing something?" ] for category in self.categories: self.display_boxes.update({category: LabelTextBox(category)}) ##### Done with display boxes ##### ##### Evertyhing to setting up the name #### self.name = LabelTextBox("Name:", orientation="H", read_only=False, line=True) self.set_name_button = QPushButton("Set Name") ##### Done with name boxes ##### ##### Everything we need for submit box ##### self.radio_list = RadioList('H', self.categories, self.radio_signal) self.text_edit = QTextEdit("Enter text") self.submit_button = QPushButton("Submit") ##### Done with submit box ##### self._setup() self.submit_button.clicked.connect(self._send_text) AppManager().emit("retro", {"event": "join"})
# Create a plotly dashboard using flask #plotly_dash = Dashboard() #app = plotly_dash.create_dashboard(app) thread = None thread_lock = Lock() # Socket IO count = 0 # Current serial port selected_serial_port = None selected_baud_rate = None # Maintain the state of the application app_mgr = AppManager(socketio=socketio) @app.route("/") def main_page(): # Use Download page as main #return download_page(None, None) #return redirect('/serial') #return serial_page(None, None) bar = app_mgr.get_plot() #return render_template('serial.j2', form=form) return render_template('home.html', plot=bar, state=app_mgr.app_state) @app.route('/setup') def view_setup():
def __init__(self): self.app_manager = AppManager() self.app1 = AppInst("app1", "cmd1", "tag,tag1a,tag1b") self.app_manager.add_app(self.app1) self.app2 = AppInst("app2", "cmd2", "tag,tag2a,tag2b") self.app_manager.add_app(self.app2)
def _send(self): if self.username: payload = {"user": self.username, "color_submit": self.user_color} AppManager().sio.emit("color_game", payload)
class Cli(): def __init__(self, args, options): self._args = args self._options = options self._usage = "usage: Dandrop start|stop|restart|create|status|config|factoryreset|help" self._app = AppManager(self.pid_file(), debug=self._options.debugmode) self._config = self._app._config self._globs = globals.Globals() self.parseArgs() def parseArgs(self): # Check for the correct numbers of arguments if len(self._args) < 1: self.print_help_message() sys.exit(2) if self._args[0] == 'start': self.start() elif self._args[0] == 'stop': self.stop() elif self._args[0] == 'restart': self.restart() elif self._args[0] == 'create': self.create() elif self._args[0] == 'status': self.status() elif self._args[0] == 'config': self.config() elif self._args[0] == 'factoryreset': pass elif self._args[0] == 'help': self.help() elif self._args[0] == 'rm': pass else: print "Unknown command" print self._usage sys.exit(2) def start(self): print "Starting DanDrop..." if self.stopped() and not self._options.debugmode: self._app.start() elif self.stopped() and self._options.debugmode: # Start in debug mode self._app.run() else: print "DanDrop is already running, please use restart" def stop(self): print "Stopping DanDrop..." if self.running: self._app.stop() print "DanDrop stopped" else: print "DanDrop is not running" def restart(self): self.stop() self.start() def create(self): if len(self._args) is not 5: print "False number of arguments!" return # Add new repository self._config.add_share(self._args[1], self._args[2], self._args[3], self._args[4]) # Restart DanDrop if self.running(): self.restart() def status(self): print "DanDrop v" + self._globs.version print "Running: True" if self.running() else "Running: False" print "Shares:" print "\n".join(" - " + share.sync_folder for share in self._config.get_shares()) def config(self): if len(self._args) == 1: # TODO: Print configuration print "Settings:" print " - Log Level: " + self._config.logLevel print " - API Listen IP: " + self._config.tcpListenIp print " - API Listen Port: " + str(self._config.tcpListenPort) print " - Web Server Enabled: " + str( self._config.enableWebServer) print " - Web Server Listen IP: " + self._config.webServerListenIp print " - Web Server Listen Port: " + str( self._config.webServerListenPort) print " - Systray Enabled: " + str(self._config.enableSystray) elif len(self._args) > 1: pass def help(self): self.print_help_message() def running(self): return self._app.running() def stopped(self): return self._app.stopped() def pid_file(self): return "/tmp/Dandrop.pid" def print_help_message(self): print self._usage print "Type Dandrop -h or Dandrop --help to get more information about all options" print print "Commands:" print " start Start DanDrop" print " stop Stop DanDrop" print " restart Restart DanDrop" print " create Create and add a new share." print " Usage: create sync_directory remote_host remote_directory remote_user" print " rm Removes the specified share" print " status Shows the current status" print " config Shows the current configuration" print " factoryreset Resets all settings" print " help Prints this help message"
def runApp(self): config = self.__config appManager = AppManager(config, self.__registerProviders) appManager.run()
from PySide2.QtWidgets import QApplication, QLabel, QWidget, QPushButton, QTextEdit, QStyle from PySide2.QtWidgets import QHBoxLayout, QVBoxLayout from app_manager import AppManager from store import create_store from apps.retro_widget import RetroWidget from apps.color_game import ColorGame from apps.retro_app import RetroApp if __name__ == "__main__": app_man = app = None try: app = QApplication(sys.argv) main_widget = QWidget() main_layout = QHBoxLayout(main_widget) app_man = AppManager() app_man.connect_qt(app, main_widget, main_layout) # Each "Component" will be treated as a view # Each view must be added to the app_man widgets # wid = ColorGame() # app_man.add_widget(wid, ['color_game']) # rw = RetroWidget(app_man) # app_man.add_widget(rw, ["retro"]) rw = RetroApp(app_man) app_man.add_widget(rw, ["retro"]) app_man.run()
class TextUI(object): def __init__(self, apps_info): self.app_manager = AppManager() logging.debug("apps info: %s", apps_info) for app_info in apps_info: app = AppInst(app_info["name"], app_info["cmd"], app_info["tags"]) self.app_manager.add_app(app) def _pretty_list_apps(self, apps): print( "================================ Apps ================================" ) index = 0 for app in apps: index += 1 print("%-15s" % app.name, end="") if index % 5 == 0: print() if index % 5 != 0: print() print( "======================================================================" ) def _pretty_list_tags(self, tags): print( "================================ Tags ================================" ) index = 0 for tag in tags: index += 1 print("%-15s" % tag, end="") if index % 5 == 0: print() if index % 5 != 0: print() print( "======================================================================" ) def cmd_list_apps(self): apps = self.app_manager.list_all_apps() self._pretty_list_apps(apps) def cmd_list_tags(self): tags = self.app_manager.list_all_tags() self._pretty_list_tags(tags) def cmd_select_apps(self, cmd): if len(cmd) != 2: print("Cmd error, check your input, try again!") return tags_str = cmd[1] tags = set(tags_str.split(",")) apps = self.app_manager.select_app_by_tags(tags) self._pretty_list_apps(apps) def cmd_run_app(self, cmd): if len(cmd) != 2: print("Cmd error, check your input, try again!") return name = cmd[1] app = self.app_manager.get_app_by_name(name) if app is not None: ret, info = app.run() if ret: print("Run success, wait for a moment!") else: print("Run fail,", info) else: print("Can not find %s, add it to apps.info first!" % name) def cmd_quit(self): sys.exit(0) def cmd_help(self): print("Cmd: list(l) - show all apps") print("Cmd: tags(t) - show all tags") print("Cmd: select(s) tag1,tag2 - select app by tags") print("Cmd: run(r) app - start app") print("Cmd: quit(q) - quit") print("Cmd: help(h) - show this help") def run(self): self.cmd_help() while True: cmd_str = input("Please Input Your Cmd: ") logging.info(cmd_str) cmd_str = cmd_str.strip() if len(cmd_str) == 0: continue cmd = cmd_str.split(" ", 1) if cmd[0] == "list" or cmd[0] == "l": self.cmd_list_apps() elif cmd[0] == "tags" or cmd[0] == "t": self.cmd_list_tags() elif cmd[0] == "select" or cmd[0] == "s": self.cmd_select_apps(cmd) elif cmd[0] == "run" or cmd[0] == "r": self.cmd_run_app(cmd) elif cmd[0] == "quit" or cmd[0] == "q": self.cmd_quit() elif cmd[0] == "help" or cmd[0] == "h": self.cmd_help() else: print("Unknown cmd, try again!")
def fileMain(): config, registerProviders = ConfigParser.getParsedData(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + "/" + CONFIG_FILE) appManager = AppManager(config, registerProviders) appManager.run()
import azureml.core from azureml.core import Workspace, Run from azureml.core.model import Model from azureml.core.authentication import ServicePrincipalAuthentication import logging, os from app_manager import AppManager manager = AppManager() ## Connect to our Azure Machine Learning Workspace auth_obj = ServicePrincipalAuthentication(manager.azure_tenant_id, manager.client_id, manager.client_secret) ws = Workspace.get(name=manager.aml_workspace_name, auth=auth_obj, subscription_id=manager.azure_subscription_id, resource_group=manager.aml_resource_group) deploy_folder = os.getcwd() weather_data_extractor = """ import json, requests import numpy as np import os, sys import datetime, time def init(): return None def run(api_token):
class ShhShell(object): def __init__(self): self.root = tk.Tk() self.text = tk.Text(self.root, background='black', foreground='white', font=('Roboto Slab', 72)) self.initialize_gui() self.initialize_logging() self.current_cmd = '' self.app_manager = AppManager() def initialize_gui(self): self.root.attributes('-topmost', 1) self.root.focus_set() self.root.geometry('800x600') self.text.pack() self.root.bind('<KeyPress>', self.onKeyPress) self.root.bind('<FocusIn>', self.onFocusIn) self.text.bind('<FocusIn>', self.onTextFocusIn) self.text.bind('<FocusOut>', self.onFocusOut) def initialize_logging(self): os.system("mkdir -p {}".format(settings.secure.LOG_DIR)) os.system("mkdir -p {}".format(settings.secure.TEXT_DIR)) now_str = str(datetime.now()).replace(" ", "_") log_filename = "{}/log-{}".format(settings.secure.LOG_DIR, now_str) self.log_file = open(log_filename, 'w') text_filename = "{}/text-{}".format(settings.secure.TEXT_DIR, now_str) self.text_file = open(text_filename, 'w') os.system("touch shh-text && rm shh-text") os.system("touch shh-log && rm shh-log") os.system("ln -s {} shh-text".format(text_filename)) os.system("ln -s {} shh-log".format(log_filename)) def start(self): self.root.mainloop() def onFocusIn(self, event): self.text.focus_set() def onTextFocusIn(self, event): self.root.attributes('-topmost', 1) self.root.attributes('-topmost', 0) os.system('say focused &') def onFocusOut(self, event): os.system('say focus lost &') def onKeyPress(self, event): # Log event log_str = "{}:{},{},{},{},{},{}\n".format( datetime.now(), event.num, event.keysym_num, event.keysym, event.serial, event.state, event.char, ) self.log_file.write(log_str) self.log_file.flush() text_str = event.char # Handle commands if event.keysym == 'BackSpace': if self.app_manager.in_app() and self.current_cmd == '': self.app_manager.quit_app() self.current_cmd = self.current_cmd[:-1] elif event.keysym == 'Return': text_str = '\n' cmd = self.current_cmd.strip() self.current_cmd = '' self.app_manager.handle_line(cmd) elif event.char: self.current_cmd += event.char # Edit text file self.text_file.write(text_str) self.text_file.flush()
class Cli(): def __init__(self, args, options): self._args = args self._options = options self._usage = "usage: pythondrop start|stop|restart|create|status|config|factoryreset|help" self._app = AppManager(self.pid_file(), debug=self._options.debugmode) self._config = self._app._config self._globs = globals.Globals() self.parseArgs() def parseArgs(self): # Check for the correct numbers of arguments if len(self._args) < 1: self.print_help_message() sys.exit(2) if self._args[0] == 'start': self.start() elif self._args[0] == 'stop': self.stop() elif self._args[0] == 'restart': self.restart() elif self._args[0] == 'create': self.create() elif self._args[0] == 'status': self.status() elif self._args[0] == 'config': self.config() elif self._args[0] == 'factoryreset': pass elif self._args[0] == 'help': self.help() elif self._args[0] == 'rm': pass else: print "Unknown command" print self._usage sys.exit(2) def start(self): print "Starting PythonDrop..." if self.stopped() and not self._options.debugmode: self._app.start() elif self.stopped() and self._options.debugmode: # Start in debug mode self._app.run() else: print "PythonDrop is already running, please use restart" def stop(self): print "Stopping PythonDrop..." if self.running: self._app.stop() print "PythonDrop stopped" else: print "PythonDrop is not running" def restart(self): self.stop() self.start() def create(self): if len(self._args) is not 5: print "False number of arguments!" return # Add new repository self._config.add_share(self._args[1], self._args[2], self._args[3], self._args[4]) # Restart PythonDrop if self.running(): self.restart() def status(self): print "PythonDrop v" + self._globs.version print "Running: True" if self.running() else "Running: False" print "Shares:" print "\n".join(" - " + share.sync_folder for share in self._config.get_shares()) def config(self): if len(self._args) == 1: # TODO: Print configuration print "Settings:" print " - Log Level: " + self._config.logLevel print " - API Listen IP: " + self._config.tcpListenIp print " - API Listen Port: " + str(self._config.tcpListenPort) print " - Web Server Enabled: " + str(self._config.enableWebServer) print " - Web Server Listen IP: " + self._config.webServerListenIp print " - Web Server Listen Port: " + str(self._config.webServerListenPort) print " - Systray Enabled: " + str(self._config.enableSystray) elif len(self._args) > 1: pass def help(self): self.print_help_message() def running(self): return self._app.running() def stopped(self): return self._app.stopped() def pid_file(self): return "/tmp/pythondrop.pid" def print_help_message(self): print self._usage print "Type pythondrop -h or pythondrop --help to get more information about all options" print print "Commands:" print " start Start PythonDrop" print " stop Stop PythonDrop" print " restart Restart PythonDrop" print " create Create and add a new share." print " Usage: create sync_directory remote_host remote_directory remote_user" print " rm Removes the specified share" print " status Shows the current status" print " config Shows the current configuration" print " factoryreset Resets all settings" print " help Prints this help message"