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 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 ")
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()
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() except Exception as e: print(f"Exception - {e}") raise finally: if app_man: app_man.destroy() if app: app.quit()
def fileMain(): config, registerProviders = ConfigParser.getParsedData(os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) + "/" + CONFIG_FILE) appManager = AppManager(config, registerProviders) appManager.run()
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"