def get_display(my): top = my.top top.add_class("spt_db_config_top") top.add_style("width: 430px") top.add_style("min-height: 500") top.add_style("padding: 15px") top.add_style("margin-left: auto") top.add_style("margin-right: auto") top.add_color("background", "background", -10) top.add_border() title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("System Configuration Setup") title_wdg.add_style("font-size: 20px") top.add("<hr/>") top.add("<i style='opacity: 0.5'>%s</i><br/>" % Config.get_config_path()) top.add("<br/>") checkin_keys=Config.get_section_values('checkin') checkin_keys=checkin_keys.keys() save_button = my.get_save_button(checkin_keys) top.add(save_button) vendor = Config.get_value("database", "vendor") title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("<b>Database Setup</b>") title_wdg.add_style("margin-bottom: 10px") db_select = SelectWdg("database/vendor") db_select.set_option("labels", "SQLite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_option("values", "Sqlite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_value(vendor) db_select.add_behavior( { 'type': 'change', 'cbjs_action': ''' var key; if (bvr.src_el.value == 'Sqlite') { key = 'Sqlite'; } else { key = 'Other'; } var top = bvr.src_el.getParent(".spt_db_config_top"); var options_els = top.getElements(".spt_db_options"); for (var i = 0; i < options_els.length; i++) { var vendor = options_els[i].getAttribute("spt_vendor"); if (vendor == key) { spt.show(options_els[i]); } else { spt.hide(options_els[i]); } } ''' } ) option_div = DivWdg() top.add(option_div) option_div.add("Vendor: ") option_div.add(db_select) option_div.add_style("margin: 20px") sqlite_wdg = my.get_sqlite_wdg() option_div.add(sqlite_wdg) otherdb_wdg = my.get_otherdb_wdg() option_div.add(otherdb_wdg) if vendor == 'Sqlite': otherdb_wdg.add_style("display: none") sqlite_wdg.add_style("display", "") else: otherdb_wdg.add_style("display", "") sqlite_wdg.add_style("display: none") test_button = ActionButtonWdg(title="<< Test >>", tip="Test connecting to database") option_div.add(test_button) test_button.add_style("margin-left: auto") test_button.add_style("margin-right: auto") test_button.add_behavior( { 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_db_config_top"); var values = spt.api.Utility.get_input_values(top, null, false); var class_name = 'tactic.ui.startup.DbConfigCbk'; var server = TacticServerStub.get(); var kwargs = {}; var ret_val = server.execute_cmd(class_name, kwargs, values); var info = ret_val.info; if (info.error) { spt.error(info.error); } else { spt.info("Connection to database successful"); } ''' } ) # # Install # top.add("<hr/>") top.add("<br/>") title = "Installation" category = "install" options = ['default_project'] if 'tmp_dir' not in options: options.append('tmp_dir') top.add( my.configure_category(title, category, options) ) top.add("<hr/>") top.add("<br/>") top.add("<br/>") title = "Asset Management Setup" category = "checkin" options=checkin_keys[:] my._remove_item_from_list(options,'win32_server_handoff_dir') my._remove_item_from_list(options,'linux_server_handoff_dir') if os.name == "nt": options.append('win32_server_handoff_dir') else: options.append('linux_server_handoff_dir') top.add( my.configure_category(title, category, options) ) top.add("<hr/>") top.add("<br/>") title = "Mail Server " category = "services" options = ['mailserver', 'mail_user', 'mail_password', 'mail_port', 'mail_tls_enabled', 'mail_sender_disabled'] top.add( my.configure_category(title, category, options) ) top.add("<hr/>") title = "Services" category = "services" options = ['process_count', 'process_time_alive', 'thread_count', 'python_path'] top.add( my.configure_category(title, category, options) ) top.add("<hr/>") title = "Look and Feel" category = "look" options = ['palette'] top.add( my.configure_category(title, category, options) ) #wizard_wdg = WizardWdg() #top.add(wizard_wdg) #wizard_wdg.add(DivWdg("cow"), "cow") #wizard_wdg.add(DivWdg("pig"), "pig") #wizard_wdg.add(DivWdg("dog"), "dog") return top
def _execute(self): '''if mode is normal, this runs both the main startup (init) logic plus monitor''' from pyasm.security import Batch Batch(login_code="admin") os.environ["TACTIC_MONITOR"] = "true" if not self.num_processes: self.num_processes = Config.get_value("services", "process_count") if self.num_processes: self.num_processes = int(self.num_processes) else: self.num_processes = 3 start_port = Config.get_value("services", "start_port") ports_str = os.environ.get("TACTIC_PORTS") if not ports_str: ports_str = Config.get_value("services", "ports") if ports_str: ports = ports_str.split("|") ports = [int(x) for x in ports] else: if start_port: start_port = int(start_port) else: start_port = 8081 ports = [] for i in range(0, self.num_processes): ports.append( start_port + i ) tactic_threads = [] #start_tactic = Config.get_value("services", "tactic") #start_job_queue = Config.get_value("services", "job_queue") #start_watch_folder = Config.get_value("services", "watch_folder") start_tactic = False start_job_queue = False start_watch_folder = False start_async = False services = Config.get_value("services", "enable") custom_services = [] if services: #services = services.split("|") services = re.split("[|,]", services) for service in services: if service == 'tactic': start_tactic = True elif service == 'job_queue': start_job_queue = True elif service == 'watch_folder': start_watch_folder = True elif service == 'async': start_async = True else: custom_services.append(service) else: start_tactic = True # create a number of processes if start_tactic: self.remove_monitor_pid() #for i in range(0, self.num_processes): for port in ports: # start cherrypy tactic_thread = TacticThread(port) tactic_thread.set_dev(self.dev_mode) tactic_thread.start() tactic_threads.append(tactic_thread) time.sleep(1) #port += 1 # aSync Queue services if start_async: num_processes = Config.get_value("async", "process_count") if not num_processes: num_processes = 1 else: num_processes = int(num_processes) for i in range(0, num_processes): job_thread = ASyncThread() job_thread.start() tactic_threads.append(job_thread) # Job Queue services if start_job_queue: num_processes = Config.get_value("services", "queue_process_count") if not num_processes: num_processes = 1 else: num_processes = int(num_processes) for i in range(0, num_processes): job_thread = JobQueueThread(i) job_thread.start() tactic_threads.append(job_thread) # Watch Folder services if start_watch_folder: search = Search("sthpw/watch_folder") watch_folders = search.get_sobjects() for watch_folder in watch_folders: project_code = watch_folder.get("project_code") base_dir = watch_folder.get("base_dir") search_type = watch_folder.get("search_type") process = watch_folder.get("process") script_path = watch_folder.get("script_path") watch_folder_code = watch_folder.get("code") if not project_code: print("Watch Folder missing project_code ... skipping") continue if not base_dir: print("Watch Folder missing base_dir ... skipping") continue if not search_type: print("Watch Folder missing search_type ... skipping") continue self.watch_folder_cleanup(base_dir) watch_thread = WatchFolderThread( project_code=project_code, base_dir=base_dir, search_type=search_type, process=process, script_path = script_path, watch_folder_code=watch_folder_code ) watch_thread.start() tactic_threads.append(watch_thread) # set up custom services for service in custom_services: kwargs = Config.get_section_values(service) custom_thread = CustomPythonProcessThread(**kwargs) custom_thread.start() tactic_threads.append(custom_thread) if len(tactic_threads) == 0: print("\n") print("No services started ...") print("\n") return # create a separate thread for timed processes # DEPRECATED tactic_timed_thread = TacticTimedThread() tactic_timed_thread.start() tactic_threads.append(tactic_timed_thread) # create a separate thread for scheduler processes start_scheduler = Config.get_value("services", "scheduler") if start_scheduler == 'true' or True: tactic_scheduler_thread = TacticSchedulerThread() tactic_scheduler_thread.set_dev(self.dev_mode) tactic_scheduler_thread.start() tactic_threads.append(tactic_scheduler_thread) DbContainer.close_thread_sql() self.tactic_threads = tactic_threads if self.mode == "normal": self.monitor()
def execute(my): from pyasm.security import Batch Batch(login_code="admin") os.environ["TACTIC_MONITOR"] = "true" if not my.num_processes: my.num_processes = Config.get_value("services", "process_count") if my.num_processes: my.num_processes = int(my.num_processes) else: my.num_processes = 3 start_port = Config.get_value("services", "start_port") ports_str = os.environ.get("TACTIC_PORTS") if not ports_str: ports_str = Config.get_value("services", "ports") if ports_str: ports = ports_str.split("|") ports = [int(x) for x in ports] else: if start_port: start_port = int(start_port) else: start_port = 8081 ports = [] for i in range(0, my.num_processes): ports.append( start_port + i ) tactic_threads = [] #start_tactic = Config.get_value("services", "tactic") #start_job_queue = Config.get_value("services", "job_queue") #start_watch_folder = Config.get_value("services", "watch_folder") start_tactic = False start_job_queue = False start_watch_folder = False start_async = False services = Config.get_value("services", "enable") custom_services = [] if services: #services = services.split("|") services = re.split("[|,]", services) for service in services: if service == 'tactic': start_tactic = True elif service == 'job_queue': start_job_queue = True elif service == 'watch_folder': start_watch_folder = True elif service == 'async': start_async = True else: custom_services.append(service) else: start_tactic = True # create a number of processes if start_tactic: #for i in range(0, my.num_processes): for port in ports: # start cherrypy tactic_thread = TacticThread(port) tactic_thread.set_dev(my.dev_mode) tactic_thread.start() tactic_threads.append(tactic_thread) time.sleep(1) #port += 1 # aSync Queue services if start_async: num_processes = Config.get_value("async", "process_count") if not num_processes: num_processes = 1 else: num_processes = int(num_processes) for i in range(0, num_processes): job_thread = ASyncThread() job_thread.start() tactic_threads.append(job_thread) # Job Queue services if start_job_queue: num_processes = Config.get_value("services", "queue_process_count") if not num_processes: num_processes = 1 else: num_processes = int(num_processes) for i in range(0, num_processes): job_thread = JobQueueThread() job_thread.start() tactic_threads.append(job_thread) # Watch Folder services if start_watch_folder: search = Search("sthpw/watch_folder") watch_folders = search.get_sobjects() for watch_folder in watch_folders: project_code = watch_folder.get("project_code") base_dir = watch_folder.get("base_dir") search_type = watch_folder.get("search_type") process = watch_folder.get("process") if not project_code: print "Watch Folder missing project_code ... skipping" continue if not project_code: print "Watch Folder missing base_dir ... skipping" continue if not search_type: print "Watch Folder missing search_type ... skipping" continue watch_thread = WatchFolderThread( project_code=project_code, base_dir=base_dir, search_type=search_type, process=process ) watch_thread.start() tactic_threads.append(watch_thread) # set up custom services for service in custom_services: kwargs = Config.get_section_values(service) custom_thread = CustomPythonProcessThread(**kwargs) custom_thread.start() tactic_threads.append(custom_thread) if len(tactic_threads) == 0: print print "No services started ..." print return # create a separate thread for timed processes # DEPRECATED tactic_timed_thread = TacticTimedThread() tactic_timed_thread.start() tactic_threads.append(tactic_timed_thread) # create a separate thread for scheduler processes start_scheduler = Config.get_value("services", "scheduler") if start_scheduler == 'true': tactic_scheduler_thread = TacticSchedulerThread() tactic_scheduler_thread.start() tactic_threads.append(tactic_scheduler_thread) DbContainer.close_thread_sql() # check each thread every 20 seconds while 1: end = False try: if my.check_interval: time.sleep(my.check_interval) for tactic_thread in tactic_threads: tactic_thread._check() else: # FIXME: break for now (for windows service) break except KeyboardInterrupt, e: print "Keyboard interrupt ... exiting Tactic" for tactic_thread in tactic_threads: tactic_thread.end = True end = True if end: break
def get_display(my): top = my.top top.add_class("spt_db_config_top") top.add_style("width: 430px") top.add_style("min-height: 500") top.add_style("padding: 15px") top.add_style("margin-left: auto") top.add_style("margin-right: auto") top.add_color("background", "background", -10) top.add_border() title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("System Configuration Setup") title_wdg.add_style("font-size: 20px") top.add("<hr/>") top.add("<i style='opacity: 0.5'>%s</i><br/>" % Config.get_config_path()) top.add("<br/>") checkin_keys = Config.get_section_values('checkin') checkin_keys = checkin_keys.keys() save_button = my.get_save_button(checkin_keys) top.add(save_button) vendor = Config.get_value("database", "vendor") title_wdg = DivWdg() top.add(title_wdg) title_wdg.add("<b>Database Setup</b>") title_wdg.add_style("margin-bottom: 10px") db_select = SelectWdg("database/vendor") db_select.set_option("labels", "SQLite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_option("values", "Sqlite|PostgreSQL|MySQL|Oracle|SQLServer") db_select.set_value(vendor) db_select.add_behavior({ 'type': 'change', 'cbjs_action': ''' var key; if (bvr.src_el.value == 'Sqlite') { key = 'Sqlite'; } else if (bvr.src_el.value == 'MySQL') { key = 'MySQL'; } else { key = 'Other'; } var top = bvr.src_el.getParent(".spt_db_config_top"); var options_els = top.getElements(".spt_db_options"); for (var i = 0; i < options_els.length; i++) { var vendor = options_els[i].getAttribute("spt_vendor"); if (vendor == key) { spt.show(options_els[i]); } else { spt.hide(options_els[i]); } } ''' }) option_div = DivWdg() top.add(option_div) option_div.add("Vendor: ") option_div.add(db_select) option_div.add_style("margin: 20px") sqlite_wdg = my.get_sqlite_wdg() option_div.add(sqlite_wdg) mysql_wdg = my.get_mysql_wdg() option_div.add(mysql_wdg) otherdb_wdg = my.get_otherdb_wdg() option_div.add(otherdb_wdg) if vendor == 'Sqlite': sqlite_wdg.add_style("display", "") otherdb_wdg.add_style("display: none") mysql_wdg.add_style("display: none") if vendor == 'MySQL': mysql_wdg.add_style("display", "") otherdb_wdg.add_style("display: none") sqlite_wdg.add_style("display: none") else: otherdb_wdg.add_style("display", "") mysql_wdg.add_style("display: none") sqlite_wdg.add_style("display: none") test_button = ActionButtonWdg(title=" Test ", tip="Test connecting to database") option_div.add(test_button) test_button.add_style("margin-left: auto") test_button.add_style("margin-right: auto") test_button.add_behavior({ 'type': 'click_up', 'cbjs_action': ''' var top = bvr.src_el.getParent(".spt_db_config_top"); var values = spt.api.Utility.get_input_values(top, null, false); var class_name = 'tactic.ui.startup.DbConfigCbk'; var server = TacticServerStub.get(); var kwargs = {}; var ret_val = server.execute_cmd(class_name, kwargs, values); var info = ret_val.info; if (info.error) { spt.error(info.error); } else { spt.info("Connection to database successful"); } ''' }) # # Install # top.add("<hr/>") top.add("<br/>") title = "Installation" category = "install" options = ['default_project'] if 'tmp_dir' not in options: options.append('tmp_dir') top.add(my.configure_category(title, category, options)) top.add("<hr/>") top.add("<br/>") top.add("<br/>") title = "Asset Management Setup" category = "checkin" options = checkin_keys[:] my._remove_item_from_list(options, 'win32_server_handoff_dir') my._remove_item_from_list(options, 'linux_server_handoff_dir') if os.name == "nt": options.append('win32_server_handoff_dir') else: options.append('linux_server_handoff_dir') top.add(my.configure_category(title, category, options)) top.add("<hr/>") top.add("<br/>") title = "Mail Server" category = "services" options = [ 'mailserver', 'mail_user', 'mail_password', 'mail_port', 'mail_tls_enabled', 'mail_sender_disabled' ] top.add(my.configure_category(title, category, options)) top.add("<hr/>") title = "Services" category = "services" options = [ 'process_count', 'process_time_alive', 'thread_count', 'python_path' ] top.add(my.configure_category(title, category, options)) top.add("<hr/>") title = "Look and Feel" category = "look" options = ['palette'] top.add(my.configure_category(title, category, options)) #wizard_wdg = WizardWdg() #top.add(wizard_wdg) #wizard_wdg.add(DivWdg("cow"), "cow") #wizard_wdg.add(DivWdg("pig"), "pig") #wizard_wdg.add(DivWdg("dog"), "dog") return top
def _execute(self): '''if mode is normal, this runs both the main startup (init) logic plus monitor''' from pyasm.security import Batch Batch(login_code="admin") os.environ["TACTIC_MONITOR"] = "true" if not self.num_processes: self.num_processes = Config.get_value("services", "process_count") if self.num_processes: self.num_processes = int(self.num_processes) else: self.num_processes = 3 start_port = Config.get_value("services", "start_port") ports_str = os.environ.get("TACTIC_PORTS") if not ports_str: ports_str = Config.get_value("services", "ports") if ports_str: ports = ports_str.split("|") ports = [int(x) for x in ports] else: if start_port: start_port = int(start_port) else: start_port = 8081 ports = [] for i in range(0, self.num_processes): ports.append(start_port + i) tactic_threads = [] #start_tactic = Config.get_value("services", "tactic") #start_job_queue = Config.get_value("services", "job_queue") #start_watch_folder = Config.get_value("services", "watch_folder") start_tactic = False start_job_queue = False start_watch_folder = False start_async = False services = Config.get_value("services", "enable") custom_services = [] if services: #services = services.split("|") services = re.split("[|,]", services) for service in services: if service == 'tactic': start_tactic = True elif service == 'job_queue': start_job_queue = True elif service == 'watch_folder': start_watch_folder = True elif service == 'async': start_async = True else: custom_services.append(service) else: start_tactic = True # create a number of processes if start_tactic: self.remove_monitor_pid() #for i in range(0, self.num_processes): for port in ports: # start cherrypy tactic_thread = TacticThread(port) tactic_thread.set_dev(self.dev_mode) tactic_thread.start() tactic_threads.append(tactic_thread) time.sleep(1) #port += 1 # aSync Queue services if start_async: num_processes = Config.get_value("async", "process_count") if not num_processes: num_processes = 1 else: num_processes = int(num_processes) for i in range(0, num_processes): job_thread = ASyncThread() job_thread.start() tactic_threads.append(job_thread) # Job Queue services if start_job_queue: num_processes = Config.get_value("services", "queue_process_count") if not num_processes: num_processes = 1 else: num_processes = int(num_processes) for i in range(0, num_processes): job_thread = JobQueueThread(i) job_thread.start() tactic_threads.append(job_thread) # Watch Folder services if start_watch_folder: search = Search("sthpw/watch_folder") watch_folders = search.get_sobjects() for watch_folder in watch_folders: project_code = watch_folder.get("project_code") base_dir = watch_folder.get("base_dir") search_type = watch_folder.get("search_type") process = watch_folder.get("process") script_path = watch_folder.get("script_path") watch_folder_code = watch_folder.get("code") if not project_code: print("Watch Folder missing project_code ... skipping") continue if not base_dir: print("Watch Folder missing base_dir ... skipping") continue if not search_type: print("Watch Folder missing search_type ... skipping") continue self.watch_folder_cleanup(base_dir) watch_thread = WatchFolderThread( project_code=project_code, base_dir=base_dir, search_type=search_type, process=process, script_path=script_path, watch_folder_code=watch_folder_code) watch_thread.start() tactic_threads.append(watch_thread) # set up custom services for service in custom_services: kwargs = Config.get_section_values(service) custom_thread = CustomPythonProcessThread(**kwargs) custom_thread.start() tactic_threads.append(custom_thread) if len(tactic_threads) == 0: print("\n") print("No services started ...") print("\n") return # create a separate thread for timed processes # DEPRECATED tactic_timed_thread = TacticTimedThread() tactic_timed_thread.start() tactic_threads.append(tactic_timed_thread) # create a separate thread for scheduler processes start_scheduler = Config.get_value("services", "scheduler") if start_scheduler == 'true' or True: tactic_scheduler_thread = TacticSchedulerThread() tactic_scheduler_thread.set_dev(self.dev_mode) tactic_scheduler_thread.start() tactic_threads.append(tactic_scheduler_thread) DbContainer.close_thread_sql() self.tactic_threads = tactic_threads if self.mode == "normal": self.monitor()