def initialize(self): # Create a directory to store temporary files with commands if not self.tmp_path.exists(): self.tmp_path.mkdir() # Clear the directory for file in self.tmp_path.glob('*'): file.unlink() with Settings(self.settings_path) as settings: if not settings['username']: settings['username'] = Windows.username( settings['username']).text if not settings['auth']: settings['auth'] = Windows.auth(settings['auth']).text if not settings['url']: settings['url'] = Windows.url(settings['url']).text if not settings['rsa_path']: settings['rsa_path'] = Windows.rsa_path( settings['rsa_path']).text self.update_client()
def rename_preset(self, preset: dict): response = Windows.preset_name(preset['name'], 'Save') if response.clicked: preset['name'] = response.text self.update_preset(preset) self.render_menu()
def change_preset(self, preset: dict): response = Windows.preset_params(preset['job_params'], 'Save', 'Cancel') if response.clicked: preset['job_params'] = response.text self.update_preset(preset) self.render_menu()
def submit_preset(self, preset: dict): response = Windows.job_description(preset['name']) if response.clicked: try: params = f'-d \'{response.text}\' ' + preset['job_params'] self.client.submit_raw(params) self.set_active_mode() except Exception as e: rumps.notification('Failed to create new job', '', str(e))
def create_preset(self, *args): preset = {'id': str(uuid4()), 'name': '', 'job_params': ''} while True: response = Windows.preset_name(preset['name'], 'Next') if not response.clicked: return preset['name'] = response.text response = Windows.preset_params(preset['job_params'], 'Create', 'Prev') if response.clicked: preset['job_params'] = response.text self.update_preset(preset) self.render_menu() return
def kill_job(self, job: JobDescription): response = Windows.kill_job() if response.clicked: try: self.client.job_kill(job.id) del self.menu[job.id] self.set_active_mode() except Exception as e: rumps.notification('Failed to kill the job', '', str(e))
def create_job(self, *args): try: with Settings(self.settings_path) as settings: while True: response = Windows.create_job(settings['job_params']) settings['job_params'] = str(response.text) if not response.clicked: return response = Windows.job_description(settings['job_name'], 'Prev') if response.clicked: settings['job_name'] = response.text params = f'-d \'{response.text}\' ' + settings[ 'job_params'] self.client.submit_raw(params) self.set_active_mode() return except Exception as e: rumps.notification('Failed to create new job', '', str(e))
def remote_debug(self, job: JobDescription): try: with Settings(self.settings_path) as settings: response = Windows.port(settings['port']) settings['port'] = str(response.text) if response.clicked: try: local_port = int(response.text) except ValueError: raise ValueError(f'Bad local port: {response.text}') self.client.remote_debug(job.id, local_port) except Exception as e: rumps.notification('Remote debug error', '', str(e))
def remove_preset(self, preset: dict): response = Windows.remove_preset() if response.clicked: self.update_preset(preset, remove=True) self.render_menu()