Exemple #1
0
    def _GenerateSpecFile(self, project_name, project_version, source_filename,
                          source_helper_object):
        """Generates the rpm spec file.

    Args:
      project_name (str): name of the project.
      project_version (str): version of the project.
      source_filename (str): name of the source package file.
      source_helper_object (SourceHelper): source helper.

    Returns:
      str: path of the generated rpm spec file or None if not available.
    """
        source_directory = source_helper_object.Create()
        if not source_directory:
            logging.error('Extraction of source package: {0:s} failed'.format(
                source_filename))
            return None

        spec_file_generator = spec_file.RPMSpecFileGenerator(self._data_path)

        log_file_path = os.path.join('..', self.LOG_FILENAME)
        if not spec_file_generator.GenerateWithSetupPy(source_directory,
                                                       log_file_path):
            return None

        if project_name.startswith('python-'):
            project_name = project_name[7:]

        input_file_path = self._GetSetupPySpecFilePath(source_helper_object,
                                                       source_directory)

        spec_filename = '{0:s}.spec'.format(project_name)
        output_file_path = os.path.join(self._rpmbuild_specs_path,
                                        spec_filename)

        if not spec_file_generator.RewriteSetupPyGeneratedFile(
                self._project_definition, source_directory, source_filename,
                project_name, project_version, input_file_path,
                output_file_path):
            return None

        return output_file_path
Exemple #2
0
    def testSplitRequires(self):
        """Tests the _SplitRequires function."""
        spec_file_generator = spec_file.RPMSpecFileGenerator('')

        requires_list = spec_file_generator._SplitRequires(
            'Requires: libbde, liblnk >= 20190520')

        self.assertEqual(requires_list, ['libbde', 'liblnk >= 20190520'])

        requires_list = spec_file_generator._SplitRequires(
            'Requires: libbde liblnk >= 20190520')

        self.assertEqual(requires_list, ['libbde', 'liblnk >= 20190520'])

        requires_list = spec_file_generator._SplitRequires(
            'Requires: liblnk >= 20190520 libbde')

        self.assertEqual(requires_list, ['libbde', 'liblnk >= 20190520'])

        requires_list = spec_file_generator._SplitRequires(None)
        self.assertEqual(requires_list, [])

        with self.assertRaises(ValueError):
            spec_file_generator._SplitRequires('Bogus')
Exemple #3
0
    def testGetBuildDefinition(self):
        """Tests the _GetBuildDefinition function."""
        spec_file_generator = spec_file.RPMSpecFileGenerator('')

        _ = spec_file_generator
Exemple #4
0
    def Build(self, source_helper_object):
        """Builds the osc package.

    Args:
      source_helper_object (SourceHelper): source helper.

    Returns:
      bool: True if successful, False otherwise.
    """
        source_filename = source_helper_object.GetSourcePackageFilename()
        if not source_filename:
            logging.info('Missing source package of: {0:s}'.format(
                source_helper_object.project_name))
            return False

        source_directory = source_helper_object.GetSourceDirectoryPath()
        if not source_directory:
            logging.info('Missing source directory of: {0:s}'.format(
                source_helper_object.project_name))
            return False

        logging.info('Preparing osc build of: {0:s}'.format(source_filename))

        if not self._BuildPrepare(source_helper_object):
            return False

        osc_package_path = os.path.join(self._OSC_PROJECT,
                                        source_helper_object.project_name)

        osc_source_path = os.path.join(osc_package_path, source_filename)
        if not os.path.exists(osc_source_path):
            # Copy the source package to the package directory if needed.
            shutil.copy(source_filename, osc_source_path)

            osc_source_path = os.path.join(source_helper_object.project_name,
                                           source_filename)
            if not self._OSCAdd(osc_source_path):
                return False

        spec_file_generator = spec_file.RPMSpecFileGenerator(self._data_path)

        log_file_path = os.path.join('..', self.LOG_FILENAME)
        if not spec_file_generator.GenerateWithSetupPy(source_directory,
                                                       log_file_path):
            return False

        project_name = source_helper_object.project_name
        if project_name.startswith(
                'python-') and project_name != 'python-gflags':
            project_name = project_name[7:]

        project_version = source_helper_object.GetProjectVersion()

        input_file_path = self._GetSetupPySpecFilePath(source_helper_object,
                                                       source_directory)

        spec_filename = '{0:s}.spec'.format(project_name)
        osc_spec_file_path = os.path.join(osc_package_path, spec_filename)

        # Determine if the output file exists before it is generated.
        output_file_exists = os.path.exists(osc_spec_file_path)

        if not spec_file_generator.RewriteSetupPyGeneratedFile(
                self._project_definition, source_directory, source_filename,
                project_name, project_version, input_file_path,
                osc_spec_file_path):
            return None

        if not spec_file_generator.RewriteSetupPyGeneratedFileForOSC(
                osc_spec_file_path):
            return False

        if not output_file_exists:
            osc_spec_file_path = os.path.join(
                source_helper_object.project_name, spec_filename)
            if not self._OSCAdd(osc_spec_file_path):
                return False

        return self._OSCCommit(source_helper_object.project_name)
Exemple #5
0
    def Build(self, source_helper_object):
        """Builds the osc package.

    Args:
      source_helper_object (SourceHelper): source helper.

    Returns:
      bool: True if successful, False otherwise.
    """
        source_filename = source_helper_object.GetSourcePackageFilename()
        if not source_filename:
            logging.info('Missing source package of: {0:s}'.format(
                source_helper_object.project_name))
            return False

        source_directory = source_helper_object.GetSourceDirectoryPath()
        if not source_directory:
            logging.info('Missing source directory of: {0:s}'.format(
                source_helper_object.project_name))
            return False

        project_version = source_helper_object.GetProjectVersion()

        logging.info('Preparing osc build of: {0:s}'.format(source_filename))

        if not self._BuildPrepare(source_helper_object):
            return False

        osc_package_path = os.path.join(self._OSC_PROJECT,
                                        source_helper_object.project_name)

        # osc wants the project filename without the status indication.
        osc_source_filename = '{0:s}-{1!s}.tar.gz'.format(
            source_helper_object.project_name, project_version)

        # Copy the source package to the package directory.
        osc_source_path = os.path.join(osc_package_path, osc_source_filename)
        shutil.copy(source_filename, osc_source_path)

        osc_source_path = os.path.join(source_helper_object.project_name,
                                       osc_source_filename)
        if not self._OSCAdd(osc_source_path):
            return False

        # Extract the build files from the source package into the package
        # directory.
        spec_filename = '{0:s}.spec'.format(source_helper_object.project_name)

        osc_spec_file_path = os.path.join(osc_package_path, spec_filename)
        spec_file_exists = os.path.exists(osc_spec_file_path)

        command = 'tar xfO {0:s} {1:s}-{2!s}/{3:s} > {3:s}'.format(
            osc_source_filename, source_helper_object.project_name,
            project_version, spec_filename)
        exit_code = subprocess.call('(cd {0:s} && {1:s})'.format(
            osc_package_path, command),
                                    shell=True)
        if exit_code != 0:
            logging.error('Running: "{0:s}" failed.'.format(command))
            return False

        spec_file_generator = spec_file.RPMSpecFileGenerator(self._data_path)

        if not spec_file_generator.RewriteSetupPyGeneratedFileForOSC(
                osc_spec_file_path):
            return False

        if not spec_file_exists:
            osc_spec_file_path = os.path.join(
                source_helper_object.project_name, spec_filename)
            if not self._OSCAdd(osc_spec_file_path):
                return False

        return self._OSCCommit(source_helper_object.project_name)