def _write_pid_file(self, filename): fs.write_file(str(os.getpid()), filename) def remove_pid_file(): try: os.remove(filename) except OSError: pass UnhandledExceptionHandler.singleton().add_teardown_callback(remove_pid_file)
def test_update_timing_file(self, existing_timing_data, new_timing_data, expected_final_timing_data): fs.write_file(json.dumps(existing_timing_data), self._timing_file_path) build_artifact = BuildArtifact('/some/dir/doesnt/matter') build_artifact._update_timing_file(self._timing_file_path, new_timing_data) with open(self._timing_file_path, 'r') as timing_file: updated_timing_data = json.load(timing_file) self.assertDictEqual(updated_timing_data, expected_final_timing_data)
def _execute_atom_command(self, atomic_command, atom_environment_vars, atom_artifact_dir): """ Run the main command for this atom. Output the command, console output and exit code to files in the atom artifact directory. :type atomic_command: str :type atom_environment_vars: dict[str, str] :type atom_artifact_dir: str """ fs_util.create_dir(atom_artifact_dir) start_time = time.time() output, exit_code = self._project_type.execute_command_in_project(atomic_command, atom_environment_vars) elapsed_time = time.time() - start_time console_output_path = os.path.join(atom_artifact_dir, Subjob.OUTPUT_FILE) fs_util.write_file(output, console_output_path) exit_code_output_path = os.path.join(atom_artifact_dir, Subjob.EXIT_CODE_FILE) fs_util.write_file(str(exit_code) + '\n', exit_code_output_path) command_output_path = os.path.join(atom_artifact_dir, Subjob.COMMAND_FILE) fs_util.write_file(str(atomic_command) + '\n', command_output_path) time_output_path = os.path.join(atom_artifact_dir, Subjob.TIMING_FILE) fs_util.write_file('{:.2f}\n'.format(elapsed_time), time_output_path)
def _execute_atom_command(self, atomic_command, atom_environment_vars, atom_artifact_dir): """ Run the main command for this atom. Output the command, console output and exit code to files in the atom artifact directory. Return the exit code. :type atomic_command: str :type atom_environment_vars: dict[str, str] :type atom_artifact_dir: str :rtype: int """ fs_util.create_dir(atom_artifact_dir) start_time = time.time() output, exit_code = self._project_type.execute_command_in_project( atomic_command, atom_environment_vars) elapsed_time = time.time() - start_time console_output_path = os.path.join(atom_artifact_dir, Subjob.OUTPUT_FILE) fs_util.write_file(output, console_output_path) exit_code_output_path = os.path.join(atom_artifact_dir, Subjob.EXIT_CODE_FILE) fs_util.write_file(str(exit_code) + '\n', exit_code_output_path) command_output_path = os.path.join(atom_artifact_dir, Subjob.COMMAND_FILE) fs_util.write_file(str(atomic_command) + '\n', command_output_path) time_output_path = os.path.join(atom_artifact_dir, Subjob.TIMING_FILE) fs_util.write_file('{:.2f}\n'.format(elapsed_time), time_output_path) return exit_code
def write_package_version_file(package_version_string): """ Write the specfied version string to package_version.py. This method is intended to be called during the process of freezing a package for release. This in-effect hard codes the version into the frozen package. This also backs up the original file, which can be restored with another method in this module. :param package_version_string: The version to write to the file -- presumably the output of get_version() :type package_version_string: str """ package_version_file_contents = 'version = "{}" # DO NOT COMMIT\n'.format(package_version_string) os.rename(_VERSION_FILE_PATH, _VERSION_FILE_BACKUP_PATH) # Backup the original file. fs.write_file(package_version_file_contents, _VERSION_FILE_PATH)
def setUpClass(cls): # For timing file test cls._timing_file_fd, cls._timing_file_path = mkstemp() # For parsing subjob/atom ids from build artifact test. cls._artifact_directory_path = TemporaryDirectory().name fs.write_file('0', os.path.join(cls._artifact_directory_path, 'artifact_1_0', 'clusterrunner_exit_code')) fs.write_file('1', os.path.join(cls._artifact_directory_path, 'artifact_1_1', 'clusterrunner_exit_code')) fs.write_file('0', os.path.join(cls._artifact_directory_path, 'artifact_2_0', 'clusterrunner_exit_code')) fs.write_file('1', os.path.join(cls._artifact_directory_path, 'artifact_2_1', 'clusterrunner_exit_code'))
def _execute_atom_command(self, atomic_command, atom_environment_vars, atom_artifact_dir): """ Run the main command for this atom. Output the command, console output and exit code to files in the atom artifact directory. Return the exit code. :type atomic_command: str :type atom_environment_vars: dict[str, str] :type atom_artifact_dir: str :rtype: int """ fs_util.create_dir(atom_artifact_dir) # This console_output_file must be opened in 'w+b' mode in order to be interchangeable with the # TemporaryFile instance that gets instantiated in self._project_type.execute_command_in_project. with open(os.path.join(atom_artifact_dir, BuildArtifact.OUTPUT_FILE), mode='w+b') as console_output_file: start_time = time.time() _, exit_code = self._project_type.execute_command_in_project(atomic_command, atom_environment_vars, output_file=console_output_file) elapsed_time = time.time() - start_time exit_code_output_path = os.path.join(atom_artifact_dir, BuildArtifact.EXIT_CODE_FILE) fs_util.write_file(str(exit_code) + '\n', exit_code_output_path) command_output_path = os.path.join(atom_artifact_dir, BuildArtifact.COMMAND_FILE) fs_util.write_file(str(atomic_command) + '\n', command_output_path) time_output_path = os.path.join(atom_artifact_dir, BuildArtifact.TIMING_FILE) fs_util.write_file('{:.2f}\n'.format(elapsed_time), time_output_path) return exit_code
def setUpClass(cls): # For timing file test cls._timing_file_fd, cls._timing_file_path = mkstemp() # For parsing subjob/atom ids from build artifact test. cls._artifact_directory_path = TemporaryDirectory().name fs.write_file( '0', os.path.join(cls._artifact_directory_path, 'artifact_1_0', 'clusterrunner_exit_code')) fs.write_file( '1', os.path.join(cls._artifact_directory_path, 'artifact_1_1', 'clusterrunner_exit_code')) fs.write_file( '0', os.path.join(cls._artifact_directory_path, 'artifact_2_0', 'clusterrunner_exit_code')) fs.write_file( '1', os.path.join(cls._artifact_directory_path, 'artifact_2_1', 'clusterrunner_exit_code'))
def _execute_atom_command(self, atomic_command, atom_environment_vars, atom_artifact_dir): """ Run the main command for this atom. Output the command, console output and exit code to files in the atom artifact directory. Return the exit code. :type atomic_command: str :type atom_environment_vars: dict[str, str] :type atom_artifact_dir: str :rtype: int """ fs_util.create_dir(atom_artifact_dir) # This console_output_file must be opened in 'w+b' mode in order to be interchangeable with the # TemporaryFile instance that gets instantiated in self._project_type.execute_command_in_project. with open(os.path.join(atom_artifact_dir, BuildArtifact.OUTPUT_FILE), mode='w+b') as console_output_file: start_time = time.time() _, exit_code = self._project_type.execute_command_in_project( atomic_command, atom_environment_vars, output_file=console_output_file) elapsed_time = time.time() - start_time exit_code_output_path = os.path.join(atom_artifact_dir, BuildArtifact.EXIT_CODE_FILE) fs_util.write_file(str(exit_code) + '\n', exit_code_output_path) command_output_path = os.path.join(atom_artifact_dir, BuildArtifact.COMMAND_FILE) fs_util.write_file(str(atomic_command) + '\n', command_output_path) time_output_path = os.path.join(atom_artifact_dir, BuildArtifact.TIMING_FILE) fs_util.write_file('{:.2f}\n'.format(elapsed_time), time_output_path) return exit_code