def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() cred_file = self.cred_file_line_edit.text() project = self.project_line_edit.text().strip() bucket = self.bucket_line_edit.text().strip() prefix = self.prefix_line_edit.text().strip() backup = Backup() backup.name = name backup.location = "Google Cloud" backup.password = password backup.gcp_cred_file = cred_file backup.gcp_project = project backup.gcp_bucket = bucket backup.cloud_prefix = prefix self.backup = backup fs = [Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_local_path, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_backend, Validator.validate_repo] args = [(name, ), (password, confirm_password), (cred_file, ), ("Project", project), ("Bucket", bucket), ("Prefix", prefix), ("Bucket", bucket), ("Prefix", prefix), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()
def start_opencv(self): """ Function to start the OpenCV gesture navigation window. Repositions the Google Earth window to take up half of the screen, then calls create_opencv to instantiate QtCapture window. The CommandThread class object is then instantiated to begin sending commands generated in the CaptureThread class to Google Earth. The QtCapture window is then displayed. Finally, the offSignal is emitted to change the state machine to the off state and the tips_button is disabled to prevent tips from being shown while gesture navigation is active. """ # Repositions Google Earth to take up one half of the available screen size self.google_earth.reposition_earth_small() # If opencv window not created, create it if not self.capture: self.create_opencv() else: self.capture = None self.create_opencv() # If command thread exists, remove it if self.command_thread: self.command_thread = None # Start command thread for sending commands to GE self.command_thread = CommandThread(self.capture, self.commands) self.command_thread.start() # Show opencv window self.capture.show() # Emits offSignal to ensure button in correct state self.offSignal.emit() # Disable tips button while gesture navigation is active self.tips_button.setEnabled(False)
def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() directory = self.local_directory_line_edit.text() backup = Backup() backup.name = name backup.location = "Local Directory" backup.password = password backup.local_directory = directory self.backup = backup fs = [ Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_local_path, Validator.validate_backend, Validator.validate_repo ] args = [(name, ), (password, confirm_password), (directory, ), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()
def accept(self): self.backup.paths = self.paths self.backup.exclude_rules = self.exclude_rules self.backup.retention = None if self.forever_radio_button.isChecked( ) else self.days_spin_box.value() self.backup.backup_daily_time = None if not self.daily_radio_button.isChecked( ) else self.schedule_time_edit.time() self.backup.backup_days = None if not self.daily_radio_button.isChecked( ) else ",".join(self.days_checked) self.backup.every_hour = None if not self.backup_every_radio_button.isChecked( ) else self.hourly_spinbox.value() self.backup.every_min = None if not self.backup_every_radio_button.isChecked( ) else self.mins_spinbox.value() self.backup.thread_count = self.thread_count_spin_box.value() self.backup.compression_level = self.compression_level_spin_box.value() if self.backup.backup_days == "": QMessageBox.warning(self.window, "Invalid details", "Please select some days of the week") return self.setEnabled(False) self.thread = CommandThread(self.worker, {}) self.thread.result.connect(self.command_done) self.thread.start()
def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() connection = self.connection_line_edit.text().strip() container = self.container_line_edit.text().strip() prefix = self.prefix_line_edit.text().strip() backup = Backup() backup.name = name backup.location = "Microsoft Azure" backup.password = password backup.azure_conn_str = connection backup.azure_container = container backup.cloud_prefix = prefix self.backup = backup fs = [ Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_backend, Validator.validate_repo ] args = [(name, ), (password, confirm_password), ("Connection String", connection), ("Container", container), ("Prefix", prefix), ("Container", container), ("Prefix", prefix), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()
def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() private_key = self.private_key_line_edit.text() username = self.username_line_edit.text().strip() sftp_password = self.sftp_password_line_edit.text().strip() server = self.server_line_edit.text().strip() prefix = self.prefix_line_edit.text().strip() backup = Backup() backup.name = name backup.location = "SFTP" backup.password = password if len(private_key) is not 0: backup.sftp_private_key = private_key backup.sftp_username = username if len(sftp_password) is not 0: backup.sftp_password = sftp_password backup.sftp_server = server backup.cloud_prefix = prefix self.backup = backup fs = [ Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_backend, Validator.validate_repo ] args = [(name, ), (password, confirm_password), ("Username", username), ("Server", server), ("Prefix", prefix), ("Server", server), ("Prefix", prefix), ("Username", username), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()
def accept(self): name = self.name_line_edit.text().strip() password = self.password_line_edit.text() if self.just_save: confirm_password = password else: confirm_password = self.confirm_password_line_edit.text() url = self.s3_url_line_edit.text().strip() key_id = self.key_id_line_edit.text().strip() key = self.key_line_edit.text().strip() bucket = self.bucket_line_edit.text().strip() prefix = self.prefix_line_edit.text().strip() backup = Backup() backup.name = name backup.location = "S3 Storage" backup.password = password backup.s3_url = url backup.aws_key_id = key_id backup.aws_key = key backup.aws_bucket = bucket backup.cloud_prefix = prefix self.backup = backup fs = [ Validator.validate_plan_name, Validator.validate_confirm_password, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_non_empty, Validator.validate_no_space, Validator.validate_no_space, Validator.validate_backend, Validator.validate_repo ] args = [(name, ), (password, confirm_password), ("AWS Key Id", key_id), ("S3 URL", url), ("AWS Key", key), ("Bucket", bucket), ("Prefix", prefix), ("Bucket", bucket), ("Prefix", prefix), (backup, ), (backup, self.just_save)] self.setEnabled(False) self.thread = CommandThread(config_worker, {"fs": fs, "args": args}) self.thread.result.connect(self.command_done) self.thread.start()
# import signal from event_logger import EventLogger from event_receiver_thread import EventReceiverThread from command_thread import CommandThread from command_tester import CommandTester # def signal_handler(signal, frame): # print('You pressed Ctrl+Z!') if __name__ == '__main__': # signal.signal(signal.SIGTSTP, signal_handler) outbound_queue = Queue() inbound_queue = Queue() command_thread = CommandThread(outbound_queue) command_thread.start() event_receiver_thread = EventReceiverThread(inbound_queue) event_receiver_thread.start() event_logger_thread = EventLogger(inbound_queue) event_logger_thread.start() command_tester = CommandTester(outbound_queue) command_tester.start() command_thread.join() event_receiver_thread.close() event_receiver_thread.join() event_logger_thread.join()
def main(config, thread=False): """ 主函数 config: {'server': {host:, port:, db:} } """ server = config['server'] # 动态注册task for module in server['modules'].split(): try: __import__(module) except ImportError: modules = module.split('.') __import__(modules[0], globals(), locals(), modules[1]) # 连结服务器 redis_host = server['host'] redis_port = int(server['port']) redis_db = int(server['db']) ztq_core.setup_redis('default', host=redis_host, port=redis_port, db=redis_db) # 开启一个命令线程 alias = server.get('alias', '') if not alias: alias = get_ip() server['alias'] = alias command_thread = CommandThread(worker_name=alias) sys.stdout.write('Starting server in PID %s\n' % os.getpid()) worker_state = ztq_core.get_worker_state() active_config = server.get('active_config', 'false') # 计算那些是需要根据线上配置启动的队列 active_queue_config = {} if active_config.lower( ) == 'true' and command_thread.worker_name in worker_state: # 如果服务器有这个机器的配置信息,需要自动启动工作线程 worker_config = ztq_core.get_worker_config() active_queue_config = worker_config.get(command_thread.worker_name, {}) # 根据本地配置,启动的队列 local_queue_config = {} if config['queues']: # 把worker监视队列的情况上报到服务器 queue_config = ztq_core.get_queue_config() # 如果配置有queues,自动启动线程监视 for queue_name, sleeps in config['queues'].items(): # 线上配置稍后再设置 if queue_name in active_queue_config: continue local_queue_config[queue_name] = [{ 'interval': int(sleep) } for sleep in sleeps.split(',')] if not queue_config.get(queue_name, []): queue_config[queue_name] = { 'name': queue_name, 'title': queue_name, 'widget': 5 } # 合并线上和线下的配置 active_queue_config.update(local_queue_config) init_job_threads(active_queue_config) loggers = config['log'] initlog( loggers.get('key', 'ztq_worker'), loggers.get('handler_file'), loggers.get('level', 'ERROR'), ) # 不是以线程启动 if thread: command_thread.setDaemon(True) command_thread.start() else: command_thread.run()
def main(): """ 主函数 """ conf_file = '' # 用户指定一个配置文件 if len(sys.argv) > 1: conf_file = sys.argv[1] init_config(conf_file) server = get_configs('server') alias = safe_get_host('server', 'alias') active_config = server.get('active_config', 'false') # 动态注册task for module in server['modules'].split(): try: __import__(module) except ImportError: raise Exception('Not imported the %s module' % module) # 连结服务器 ztq_core.setup_redis('default', host=server['host'], port=int(server['port']), db=int(server['db'])) # 开启一个命令线程 command_thread = CommandThread(worker_name=alias) sys.stdout.write('Starting server in PID %s\n' % os.getpid()) worker_state = ztq_core.get_worker_state() if active_config.lower( ) == 'true' and command_thread.worker_name in worker_state: # 如果服务器有这个机器的配置信息,需要自动启动工作线程 queue = ztq_core.get_worker_config() if command_thread.worker_name in queue: set_job_threads(queue[command_thread.worker_name]) elif get_configs('queues'): # 把worker监视队列的情况上报到服务器 queue_config = ztq_core.get_queue_config() # 如果配置有queues,自动启动线程监视 job_threads = {} for queue_name, sleeps in get_configs('queues').items(): job_threads[queue_name] = [{ 'interval': int(sleep) } for sleep in sleeps.split(',')] if not queue_config.get(queue_name, []): queue_config[queue_name] = { 'name': queue_name, 'title': queue_name, 'widget': 5 } init_job_threads(job_threads) loggers = get_configs('log') initlog( loggers.get('key', 'ztq_worker'), loggers.get('handler_file'), loggers.get('level', 'ERROR'), ) # 不是以线程启动 command_thread.run()