def test_ignition(self, mock_conn): """Should engage autopilot, wait, & stage.""" capcom = Launcher(target_altitude=10, target_inclination=30) vessel = mock_conn().space_center.active_vessel vessel.control.sas = True vessel.control.rcs = True vessel.control.throttle = 0.0 vessel.surface_reference_frame = 'RF' with patch('Launcher.time', spec=True) as mock_time: vessel.auto_pilot.engage.assert_not_called() vessel.control.activate_next_stage.assert_not_called() mock_time.sleep.assert_not_called() capcom.ignition() self.assertEqual(vessel.auto_pilot.target_pitch, 90) self.assertEqual(vessel.auto_pilot.target_heading, 90-30) self.assertEqual(vessel.auto_pilot.target_roll, 180) self.assertEqual(vessel.auto_pilot.reference_frame, 'RF') self.assertIs(vessel.control.sas, False) self.assertIs(vessel.control.rcs, False) self.assertAlmostEqual(vessel.control.throttle, 1.0) vessel.auto_pilot.engage.assert_called_once_with() vessel.control.activate_next_stage.assert_called_once_with() mock_time.sleep.assert_called_once_with(1)
def execute(command, host=None, bg=True, **kwds): '''execute a command (possibly) on a remote host Execute a process, and return the launcher. Use 'response' to retrieve the response from the executed command. Use 'kill' to kill the launcher, and 'pid' to get the process id for the launcher. Inputs: command -- command string to be executed host -- hostname of execution target [default = None (i.e. run locally)] bg -- run as background process? [default = True] ''' #XXX: options, background, stdin can be set w/ kwds (also name, launcher) bg = bool(bg) # overrides 'background' if host in [None, '']: from Launcher import Launcher launcher = Launcher(**kwds) launcher(command=command, background=bg) else: from LauncherSSH import LauncherSSH opt = kwds.pop('options', '-q') launcher = LauncherSSH(**kwds) launcher(options=opt, command=command, host=host, background=bg) logging.info('executing {%s}', launcher.message) launcher.launch() #response = launcher.response() #launcher.kill() #return response return launcher
def __init__(self, server_name, **kwargs): server_name = server_name.upper() os.environ['CURRENT_PACKAGE_NAME'] = server_name self.open_init_file = kwargs.get('open_init_file', False) self.files = None if not self.open_init_file: self.files = kwargs.get('files', None) self.emacsExpr = None if self.open_init_file: self.emacsExpr = EmacsExpression() self.emacsExpr.addStatement('skg/open-init-file') line = kwargs.get('line', None) if line: self._gotoLine(line) self.exePath = Locator('emacs') self.exeClientPath = Locator('emacsclient') self.homeEnv = os.environ['HOME'] if self._serverRunning(server_name): self._launcher = Launcher(self.exeClientPath) self._launcher += ['-n', '-f', server_name] else: self._launcher = Launcher(self.exePath)
def test__wait_to_go_around_again(self, mock_conn): """Check it calls time.sleep() for 10 ms.""" capcom = Launcher(target_altitude=10) with patch('Launcher.time', spec=True) as mock_time: capcom._wait_to_go_around_again() mock_time.sleep.assert_called_once_with(0.01)
def _debug_app(self, **kwargs): launcher = Launcher(self.debugger) launcher.addArg(self.exe_file) if self.debugger_is_cgdb: launcher.addArg('--') launcher = self._add_init_file_to_launcher(launcher) return launcher
def test_execute_launch(self, mock_conn): """Should run ignition, ascent and setup_circularization.""" capcom = Launcher(target_altitude=10) with patch.object(Launcher, 'ignition'), \ patch.object(Launcher, 'ascent'), \ patch.object(Launcher, 'setup_circularization'): capcom.execute_launch() capcom.ignition.assert_called_once_with() capcom.ascent.assert_called_once_with() capcom.setup_circularization.assert_called_once_with()
def test_setup_circularization(self, mock_conn): """Should add the circularization maneuver node.""" vessel = mock_conn().space_center.active_vessel vessel.orbit.body.gravitational_parameter = 1 vessel.orbit.apoapsis = 200 vessel.orbit.semi_major_axis = 100 mock_conn().space_center.ut = 10 vessel.orbit.time_to_apoapsis = 20 capcom = Launcher(target_altitude=200) capcom.setup_circularization() vessel.control.add_node.assert_called_once() args, kargs = vessel.control.add_node.call_args self.assertEqual(args, (30,)) self.assertAlmostEqual(kargs['prograde'], 0.0707, 4)
def test__ascent_angle_manager(self, mock_conn): """Should set autopilot ascent angle from altitude.""" capcom = Launcher(target_altitude=10) values = [[0, 90], [1000, 90], [1001, 80], [25500, 40], [50000, 0], ] for altitude, ascent_angle in values: capcom._ascent_angle_manager(altitude=altitude) auto_pilot = mock_conn().space_center.active_vessel.auto_pilot self.assertAlmostEqual(auto_pilot.target_pitch, ascent_angle, 0)
def wait(self): outcome = Launcher.wait(self) if self.__user.enabled(): import Uploader Uploader.upload(self.app, self.__user, outcome, 'text/html') return outcome
def test_no_krpc_connection(self): """Server unreachable should raise ConnectionRefusedError.""" try: Launcher(target_altitude=10) except Exception as e: self.assertIsInstance(e, ConnectionRefusedError) return
def test___repr__(self, mock_conn): """Check that the __repr__() method works.""" actual_str = repr(Launcher(target_altitude=10, target_inclination=20)) expect_str = 'Launcher(target_altitude=10, ' expect_str += 'target_inclination=20)' self.assertEqual(actual_str, expect_str)
def prepare_workspace(project, repo_top, args): # Since we dispatch to remote machines, a project specific python # virtualenv is exists, needs to be activated when launching the job. Launcher.set_python_venv(project) if Launcher.python_venv is None: return # Python_venv needs to be a valid tarfile. Extract it in the scratch # area if it does not exist. It is upto the user to delete it if it is # stale. stem = Path(Launcher.python_venv).stem.split('.')[0] path = Path(args.scratch_root, stem) if not path.is_dir(): with tarfile.open(Launcher.python_venv, mode='r') as tar: tar.extractall(path=args.scratch_root) Launcher.python_venv = path
def test_init_without_arg(self, mock_conn): """Invoking w/o arg should raise TypeError.""" try: Launcher() except Exception as e: self.assertIsInstance(e, TypeError) return
def __call__(self, **kwargs): launcher = None wait = True if self.debug: if self.useEmacs: launcher = self._emacs_debugger(**kwargs) elif self.debugger: launcher = self._debug_app(**kwargs) else: wait = self.wait launcher = Launcher(self.exe_file, stdout_to_console = True, stderr_to_console = True) if kwargs is not None: for key in kwargs: launcher.addArg('--%s' % key, '%s' % kwargs[key], append=True) launcher(dry_run = self.dry_run, wait_for_command_to_complete = wait)
def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWindow")) MainWindow.resize(652, 458) MainWindow.setStyleSheet( _fromUtf8("#backgroundFrame\n" "{\n" " background-color: rgba(0, 0, 0, 190);\n" "}\n" "")) self.gridLayout = QtGui.QGridLayout(MainWindow) self.gridLayout.setMargin(0) self.gridLayout.setSpacing(0) self.gridLayout.setObjectName(_fromUtf8("gridLayout")) self.backgroundFrame = QtGui.QFrame(MainWindow) self.backgroundFrame.setAutoFillBackground(True) self.backgroundFrame.setObjectName(_fromUtf8("backgroundFrame")) self.gridLayout_2 = QtGui.QGridLayout(self.backgroundFrame) self.gridLayout_2.setMargin(0) self.gridLayout_2.setSpacing(0) self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2")) spacerItem = QtGui.QSpacerItem(20, 215, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.gridLayout_2.addItem(spacerItem, 0, 1, 1, 1) spacerItem1 = QtGui.QSpacerItem(311, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.gridLayout_2.addItem(spacerItem1, 1, 0, 1, 1) self.Launcher = Launcher(self.backgroundFrame) self.Launcher.setAutoFillBackground(True) self.Launcher.setFrameShape(QtGui.QFrame.StyledPanel) self.Launcher.setFrameShadow(QtGui.QFrame.Raised) self.Launcher.setObjectName(_fromUtf8("Launcher")) self.gridLayout_2.addWidget(self.Launcher, 1, 1, 1, 1) spacerItem2 = QtGui.QSpacerItem(310, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.gridLayout_2.addItem(spacerItem2, 1, 2, 1, 1) spacerItem3 = QtGui.QSpacerItem(20, 212, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.gridLayout_2.addItem(spacerItem3, 2, 1, 1, 1) self.gridLayout_2.setColumnStretch(0, 1) self.gridLayout_2.setColumnStretch(2, 1) self.gridLayout_2.setRowStretch(0, 1) self.gridLayout_2.setRowStretch(2, 1) self.gridLayout.addWidget(self.backgroundFrame, 0, 0, 1, 1) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
def __init__(self, server_name, **kwargs): super(EmacsGdb, self).__init__(server_name, **kwargs) self.exeToDebug = kwargs.get('exe_to_debug') self.gdb = Locator('gdb').locate() self.gdbCl = Launcher(self.gdb) self.gdbCl.addArg('-i', 'mi', append = True) self.gdbCl.addArg(self.exeToDebug) self.firstArg = True
def test_ascent(self, mock_conn): """Should manage the ascent until apoapsis is reached.""" def _80_once_then_100(): yield 50 while True: yield 100 capcom = Launcher(target_altitude=80) mock_conn().stream().__enter__().side_effect = _80_once_then_100() vessel = mock_conn().space_center.active_vessel vessel.control.throttle = 1.0 vessel.available_thrust = 20 with patch.object(Launcher, '_ascent_angle_manager'), \ patch.object(Launcher, '_auto_stage'), \ patch.object(Launcher, '_wait_to_go_around_again'): capcom.ascent() capcom._ascent_angle_manager.assert_called_once_with(100) capcom._auto_stage.assert_called_once_with(20) capcom._wait_to_go_around_again.assert_called_once_with() self.assertAlmostEqual(vessel.control.throttle, 0.0)
def prepare_workspace(project, repo_top, args): '''Overrides Launcher.prepare_workspace.''' # Since we dispatch to remote machines, a project specific python # virtualenv is exists, needs to be activated when launching the job. Launcher.set_python_venv(project) if Launcher.python_venv is None: return # Python_venv needs to be a valid tarfile. Extract it in the scratch # area if it does not exist. It is upto the user to delete it if it is # stale. if tarfile.is_tarfile(Launcher.python_venv): path = Path(args.scratch_root, Path(Launcher.python_venv).stem) if not path.is_dir(): with tarfile.open(Launcher.python_venv, mode='r') as tar: tar.extractall(path=args.scratch_root) Launcher.python_venv = path else: raise LauncherError("{} is not a valid tar file".format( Launcher.python_venv))
def test__auto_stage(self, mock_time, mock_conn): """Should return available_thrust, with side effect of staging.""" capcom = Launcher(target_altitude=10) vessel = mock_conn().space_center.active_vessel control = vessel.control VALUES = [[95, False], [89, True], [50, True], [25, True], ] for new_thrust, calls_made in VALUES: with self.subTest(f'thrust_ratio: {new_thrust}%'): mock_conn().reset_mock() mock_time.reset_mock() vessel.available_thrust = new_thrust self.assertEqual(capcom._auto_stage(100), new_thrust) if calls_made: control.activate_next_stage.assert_called_once_with() mock_time.sleep.assert_has_calls([call(0.1), call(0.1)]) else: mock_time.sleep.assert_not_called()
def prepare_workspace(project, repo_top, args): # Since we dispatch to remote machines, a project specific python # virtualenv is exists, needs to be activated when launching the job. Launcher.set_pyvenv(project) if Launcher.pyvenv is None: return # If it is already a dir, then nothing to be done. if os.path.isdir(Launcher.pyvenv): return # If not, then it needs to be a valid tarball. Extract it in the # scratch area if it does not exist. stem = Path(Launcher.pyvenv).stem if stem.endswith("tar"): stem = stem[:-4] path = Path(args.scratch_root, stem) if not path.is_dir(): log.info("[prepare_workspace]: [pyvenv]: Extracting %s", Launcher.pyvenv) with tarfile.open(Launcher.pyvenv, mode='r') as tar: tar.extractall(args.scratch_root) log.info("[prepare_workspace]: [pyvenv]: Done: %s", path) Launcher.pyvenv = path
class Ui_MainWindow(object): def setupUi(self, MainWindow): MainWindow.setObjectName(_fromUtf8("MainWindow")) MainWindow.resize(652, 458) MainWindow.setStyleSheet(_fromUtf8("#backgroundFrame\n" "{\n" " background-color: rgba(0, 0, 0, 190);\n" "}\n" "")) self.gridLayout = QtGui.QGridLayout(MainWindow) self.gridLayout.setMargin(0) self.gridLayout.setSpacing(0) self.gridLayout.setObjectName(_fromUtf8("gridLayout")) self.backgroundFrame = QtGui.QFrame(MainWindow) self.backgroundFrame.setAutoFillBackground(True) self.backgroundFrame.setObjectName(_fromUtf8("backgroundFrame")) self.gridLayout_2 = QtGui.QGridLayout(self.backgroundFrame) self.gridLayout_2.setMargin(0) self.gridLayout_2.setSpacing(0) self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2")) spacerItem = QtGui.QSpacerItem(20, 215, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.gridLayout_2.addItem(spacerItem, 0, 1, 1, 1) spacerItem1 = QtGui.QSpacerItem(311, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.gridLayout_2.addItem(spacerItem1, 1, 0, 1, 1) self.Launcher = Launcher(self.backgroundFrame) self.Launcher.setAutoFillBackground(True) self.Launcher.setFrameShape(QtGui.QFrame.StyledPanel) self.Launcher.setFrameShadow(QtGui.QFrame.Raised) self.Launcher.setObjectName(_fromUtf8("Launcher")) self.gridLayout_2.addWidget(self.Launcher, 1, 1, 1, 1) spacerItem2 = QtGui.QSpacerItem(310, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum) self.gridLayout_2.addItem(spacerItem2, 1, 2, 1, 1) spacerItem3 = QtGui.QSpacerItem(20, 212, QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Expanding) self.gridLayout_2.addItem(spacerItem3, 2, 1, 1, 1) self.gridLayout_2.setColumnStretch(0, 1) self.gridLayout_2.setColumnStretch(2, 1) self.gridLayout_2.setRowStretch(0, 1) self.gridLayout_2.setRowStretch(2, 1) self.gridLayout.addWidget(self.backgroundFrame, 0, 0, 1, 1) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow) def retranslateUi(self, MainWindow): MainWindow.setWindowTitle(_translate("MainWindow", "Dialog", None))
class EmacsGdb (Emacs): def __init__(self, server_name, **kwargs): super(EmacsGdb, self).__init__(server_name, **kwargs) self.exeToDebug = kwargs.get('exe_to_debug') self.gdb = Locator('gdb').locate() self.gdbCl = Launcher(self.gdb) self.gdbCl.addArg('-i', 'mi', append = True) self.gdbCl.addArg(self.exeToDebug) self.firstArg = True def addArg(self, key, *value, **kwargs): self.gdbCl.addArg (key, *value, **kwargs) def launch(self, **kwargs): self._emacsExpr().addStatement('gdb "%s"' % (self.gdbCl)) self._emacsExpr().addStatement('gdb-many-windows t') super(EmacsGdb, self).launch(**kwargs) def __call__(self, **kwargs): dry_run = kwargs.get('dry_run') self.launch(dry_run = dry_run)
def __init__(self, name = "lsf_launcher"): Launcher.__init__(self, name) return
def test_init_with_arg(self, mock_conn): """Invoking w/ arg should set altitude & default inclination.""" capcom = Launcher(target_altitude=10) self.assertEqual(capcom.target_altitude, 10) self.assertEqual(capcom.target_inclination, 0)
def test_krpc_connection(self, mock_conn): """Check that __init__ connects to KRPC server.""" Launcher(target_altitude=10) mock_conn.assert_called_once_with(name='Launcher')
#!/usr/bin/env python from Launcher import Launcher cute_launcher = Launcher() cute_launcher.start()
def __init__(self): Launcher.__init__(self, "mpirun") return
def _configure(self): Launcher._configure(self) return
def test_init_with_optional_karg(self, mock_conn): """Invoking w/ karg should set altitude & inclination.""" capcom = Launcher(target_altitude=10, target_inclination=90) self.assertEqual(capcom.target_altitude, 10) self.assertEqual(capcom.target_inclination, 90)
def __init__(self, app): Launcher.__init__(self, app)
def OnInit(self): self.GunShotMatch = Launcher(None, wx.ID_ANY, "") self.SetTopWindow(self.GunShotMatch) self.GunShotMatch.Show() return True
def __init__(self, name = 'serial_launcher'): Launcher.__init__(self, name) return
class Emacs(object): def __init__(self, server_name, **kwargs): server_name = server_name.upper() os.environ['CURRENT_PACKAGE_NAME'] = server_name self.open_init_file = kwargs.get('open_init_file', False) self.files = None if not self.open_init_file: self.files = kwargs.get('files', None) self.emacsExpr = None if self.open_init_file: self.emacsExpr = EmacsExpression() self.emacsExpr.addStatement('skg/open-init-file') line = kwargs.get('line', None) if line: self._gotoLine(line) self.exePath = Locator('emacs') self.exeClientPath = Locator('emacsclient') self.homeEnv = os.environ['HOME'] if self._serverRunning(server_name): self._launcher = Launcher(self.exeClientPath) self._launcher += ['-n', '-f', server_name] else: self._launcher = Launcher(self.exePath) def _serverRunning(self, server_name): server_list = self._serverList() s = [item for item in server_list if os.path.basename(item) == server_name] if not s: return False f = open(s[0], 'r') lines = f.read() f.close() pid = int(lines.split('\n')[0].split()[1]) try: os.kill(pid, 0) return True except OSError: return False def _emacsExpr(self): if not self.emacsExpr: self.emacsExpr = EmacsExpression() return self.emacsExpr def _gotoLine(self, line): self._emacsExpr().addStatement('goto-line %s' % (line)) def _serverList(self): servers_dir = os.path.join(self.homeEnv, '.emacs.d', 'server') if os.path.exists(servers_dir): files = [join(servers_dir, f) for f in listdir(servers_dir) if isfile(join(servers_dir, f))] return files return [] def launch(self, **kwargs): dry_run = kwargs.get('dry_run') if self.files: self._launcher.addFiles(self.files) else: self._emacsExpr().addStatement('raise-frame') if self.emacsExpr: self._launcher.addArg('--eval', self.emacsExpr()) debug = kwargs.get('debug', False) if debug: self._launcher.addArg('--debug-init') self._launcher(dry_run = dry_run)
def __init__(self, name = 'mpich2_launcher'): Launcher.__init__(self, name) return
def __init__(self, name='serial_launcher'): Launcher.__init__(self, name) return
def test___str__(self, mock_conn): """Check that the __str__() method works.""" actual_str = str(Launcher(target_altitude=1000)) expect_str = 'Will launch to 1.0km ' expect_str += 'and set up the circularization maneuver node.\n' self.assertEqual(actual_str, expect_str)
def setUp(self): launcher = Launcher(open_dev_tools=False) self.auto_chrome = launcher.launch()
def __init__(self, app, user, sparsity): Launcher.__init__(self, app) self.__user = user self.__sparsity = sparsity