Ejemplo n.º 1
0
    def recognize(cls, location):
        """
        Yield one or more Package manifest objects given a file ``location`` pointing to a
        package archive, manifest or similar.
        """
        infos = pe_info(location)

        version = get_first(
            infos,
            'Full Version',
            'ProductVersion',
            'FileVersion',
            'Assembly Version',
        )
        release_date = get_first(infos, 'BuildDate')
        if release_date:
            if len(release_date) >= 10:
                release_date = release_date[:10]
            release_date = release_date.replace('/', '-')

        name = get_first(
            infos,
            'ProductName',
            'OriginalFilename',
            'InternalName',
        )
        copyr = get_first(infos, 'LegalCopyright')

        LegalCopyright = copyr,

        LegalTrademarks = concat(infos, 'LegalTrademarks', 'LegalTrademarks1',
                                 'LegalTrademarks2', 'LegalTrademarks3')

        License = get_first(infos, 'License')

        declared_license = {}
        if LegalCopyright or LegalTrademarks or License:
            declared_license = dict(LegalCopyright=copyr,
                                    LegalTrademarks=LegalTrademarks,
                                    License=License)

        description = concat(infos, 'FileDescription', 'Comments')

        parties = []
        cname = get_first(infos, 'CompanyName', 'Company')

        if cname:
            parties = [Party(type=party_org, role='author', name=cname)]
        homepage_url = get_first(infos, 'URL', 'WWW')

        yield cls(
            name=name,
            version=version,
            release_date=release_date,
            copyright=copyr,
            declared_license=declared_license,
            description=description,
            parties=parties,
            homepage_url=homepage_url,
        )
Ejemplo n.º 2
0
 def test_Package_full(self):
     package = Package(
         type='rpm',
         namespace='fedora',
         name='Sample',
         version='12.2.3',
         qualifiers={
             'this': 'that',
             'abc': '12'
         },
         subpath='asdasd/asdasd/asdasd/',
         primary_language='C/C++',
         description='Some package',
         size=12312312312,
         release_date='2012-10-21',
         parties=[
             Party(name='Some Author',
                   role='author',
                   email='*****@*****.**')
         ],
         keywords=['some', 'other', 'keyword'],
         homepage_url='http://homepage.com',
         download_url='http://homepage.com/dnl',
         sha1='ac978f7fd045f5f5503772f525e0ffdb533ba0f8',
         md5='12ed302c4b4c2aa10638db389082d07d',
         sha256=
         '0b07d5ee2326cf76445b12a32456914120241d2b78c5b55273e9ffcbe6ffbc9f',
         sha512=
         'c9a92789e94d68029629b9a8380afddecc147ba48f0ae887b89b88492d02aec96a92cf3c7eeb200111a6d94d1b7419eecd66e79de32c826e694f05d2eda644ae',
         bug_tracking_url='http://homepage.com/issues',
         code_view_url='http://homepage.com/code',
         vcs_url=
         'git+http://homepage.com/code.git@12ed302c4b4c2aa10638db3890',
         copyright='copyright (c) nexB Inc.',
         license_expression='apache-2.0',
         declared_license=u'apache-2.0',
         notice_text='licensed under the apacche 2.0 \nlicense',
         root_path='',
         dependencies=[
             DependentPackage(purl='pkg:maven/org.aspectj/aspectjtools',
                              requirement='1.5.4',
                              scope='relocation',
                              is_runtime=True,
                              is_optional=False,
                              is_resolved=False),
             DependentPackage(purl='pkg:maven/org.aspectj/aspectjruntime',
                              requirement='1.5.4-release',
                              scope='runtime',
                              is_runtime=True,
                              is_optional=False,
                              is_resolved=True)
         ],
         contains_source_code=True,
         source_packages=[
             "pkg:maven/aspectj/[email protected]?classifier=sources"
         ],
     )
     expected_loc = 'models/full-expected.json'
     self.check_package(package, expected_loc, regen=False)
Ejemplo n.º 3
0
def parse(location):
    """
    Return a WindowsExecutable package from the file at `location` or None.
    """
    if not filetype.is_file(location):
        return

    T = contenttype.get_type(location)
    if not T.is_winexe:
        return

    infos = pe_info(location)

    version = get_first(infos, 'Full Version', 'ProductVersion', 'FileVersion',
                        'Assembly Version')
    release_date = get_first(infos, 'BuildDate')
    if release_date:
        if len(release_date) >= 10:
            release_date = release_date[:10]
        release_date = release_date.replace('/', '-')

    name = get_first(infos, 'ProductName', 'OriginalFilename', 'InternalName')
    copyr = get_first(infos, 'LegalCopyright')

    LegalCopyright = copyr,

    LegalTrademarks = concat(infos, 'LegalTrademarks', 'LegalTrademarks1',
                             'LegalTrademarks2', 'LegalTrademarks3')

    License = get_first(infos, 'License')

    declared_license = {}
    if LegalCopyright or LegalTrademarks or License:
        declared_license = dict(LegalCopyright=copyr,
                                LegalTrademarks=LegalTrademarks,
                                License=License)

    description = concat(infos, 'FileDescription', 'Comments')

    parties = []
    cname = get_first(infos, 'CompanyName', 'Company')

    if cname:
        parties = [Party(type=party_org, role='author', name=cname)]
    homepage_url = get_first(infos, 'URL', 'WWW')

    return WindowsExecutable(
        name=name,
        version=version,
        release_date=release_date,
        copyright=copyr,
        declared_license=declared_license,
        description=description,
        parties=parties,
        homepage_url=homepage_url,
    )
Ejemplo n.º 4
0
def contributors_mapper(contributors, package):
    """
    Update package contributors and return package.
    https://docs.npmjs.com/files/package.json#people-fields-author-contributors
    "contributors" is an array of people.
    """
    contribs = []
    if isinstance(contributors, list):
        for contrib in contributors:
            name, email, url = parse_person(contrib)
            contribs.append(
                Party(type=Party.party_person, name=name, email=email,
                      url=url))
    else:  # a string or dict
        name, email, url = parse_person(contributors)
        contribs.append(
            Party(type=Party.party_person, name=name, email=email, url=url))
    package.contributors = contribs
    return package
Ejemplo n.º 5
0
def maintainers_mapper(maintainers, package):
    """
    Update package maintainers and return package.
    https://docs.npmjs.com/files/package.json#people-fields-author-contributors
    npm also sets a top-level "maintainers" field with your npm user info.
    """
    # note this is the same code as contributors_mappers... should be refactored
    maintains = []
    if isinstance(maintainers, list):
        for contrib in maintainers:
            name, email, url = parse_person(contrib)
            maintains.append(
                Party(type=Party.party_person, name=name, email=email,
                      url=url))
    else:  # a string or dict
        name, email, url = parse_person(maintainers)
        maintains.append(
            Party(type=Party.party_person, name=name, email=email, url=url))
    package.maintainers = maintains
    return package
Ejemplo n.º 6
0
def author_mapper(author, package):
    """
    Update package author and return package.
    https://docs.npmjs.com/files/package.json#people-fields-author-contributors
    The "author" is one person.
    """
    name, email, url = parse_person(author)
    package.authors = [
        Party(type=Party.party_person, name=name, email=email, url=url)
    ]
    return package
Ejemplo n.º 7
0
 def test_Package_simple(self):
     package = Package(type='rpm',
                       name='Sample',
                       description='Some package',
                       parties=[
                           Party(name='Some Author',
                                 role='author',
                                 email='*****@*****.**')
                       ],
                       keywords=['some', 'keyword'],
                       vcs_url='git+https://somerepo.com/that.git',
                       declared_license='apache-2.0')
     expected_loc = 'models/simple-expected.json'
     self.check_package(package, expected_loc, regen=False)
Ejemplo n.º 8
0
 def test_msi_create_package_from_msiinfo_results(self):
     result = create_package_from_msiinfo_results(self.python_3_9_5_add_to_path_results)
     expected = MsiInstallerPackage(
         name='Python 3.9.5 Add to Path (64-bit)',
         version='v 3.9.5',
         description='This installer database contains the logic and data required to install Python 3.9.5 Add to Path (64-bit).',
         parties=[
             Party(
                 type=None,
                 role='author',
                 name='Python Software Foundation'
             )
         ],
         keywords='Installer',
         extra_data=self.python_3_9_5_add_to_path_results
     )
     self.assertEqual(result, expected)
 def test_Package_simple(self):
     package = PackageData(
         datasource_id='rpm_archive',
         type='rpm',
         name='Sample',
         description='Some package',
         parties=[
             Party(name='Some Author',
                   role='author',
                   email='*****@*****.**')
         ],
         keywords=['some', 'keyword'],
         vcs_url='git+https://somerepo.com/that.git',
         declared_license='apache-2.0',
     )
     expected_loc = 'models/simple-expected.json'
     self.check_package_data(package,
                             expected_loc,
                             regen=REGEN_TEST_FIXTURES)
Ejemplo n.º 10
0
 def test_msi_create_package_data_from_msiinfo_results(self):
     result = create_package_data_from_msiinfo_results(
         self.python_3_9_5_add_to_path_results.copy()).to_dict()
     expected = models.PackageData(
         type=MsiInstallerHandler.default_package_type,
         datasource_id=MsiInstallerHandler.datasource_id,
         name='Python 3.9.5 Add to Path (64-bit)',
         version='v 3.9.5',
         description=
         'This installer database contains the logic and data required to install Python 3.9.5 Add to Path (64-bit).',
         parties=[
             Party(type=None,
                   role='author',
                   name='Python Software Foundation')
         ],
         keywords='Installer',
     ).to_dict()
     result['extra_data'] = {}
     assert result == expected
 def test_validate_package(self):
     package = Package(
         type='RPM',
         name='Sample',
         summary='Some package',
         payload_type='source',
         authors=[Party(name='Some Author', email='*****@*****.**')],
         keywords=['some', 'keyword'],
         vcs_tool='git',
         asserted_licenses=[AssertedLicense(license='apache-2.0')],
     )
     expected = [('type', 'RPM'), ('name', u'Sample'), ('version', None),
                 ('primary_language', None), ('packaging', None),
                 ('summary', u'Some package'), ('description', None),
                 ('payload_type', u'source'), ('size', None),
                 ('release_date', None),
                 ('authors', [
                     OrderedDict([('type', None), ('name', u'Some Author'),
                                  ('email', u'*****@*****.**'),
                                  ('url', None)])
                 ]), ('maintainers', []), ('contributors', []),
                 ('owners', []), ('packagers', []), ('distributors', []),
                 ('vendors', []), ('keywords', [u'some', u'keyword']),
                 ('keywords_doc_url', None), ('metafile_locations', []),
                 ('metafile_urls', []), ('homepage_url', None),
                 ('notes', None), ('download_urls', []),
                 ('download_sha1', None), ('download_sha256', None),
                 ('download_md5', None), ('bug_tracking_url', None),
                 ('support_contacts', []), ('code_view_url', None),
                 ('vcs_tool', u'git'), ('vcs_repository', None),
                 ('vcs_revision', None), ('copyright_top_level', None),
                 ('copyrights', []),
                 ('asserted_licenses', [
                     OrderedDict([('license', u'apache-2.0'), ('url', None),
                                  ('text', None), ('notice', None)])
                 ]), ('legal_file_locations', []),
                 ('license_expression', None), ('license_texts', []),
                 ('notice_texts', []), ('dependencies', {}),
                 ('related_packages', [])]
     assert expected == package.to_dict().items()
     package.validate()
Ejemplo n.º 12
0
    def parse(cls, location):
        infos = pe_info(location)

        version = get_first(
            infos,
            'Full Version',
            'ProductVersion',
            'FileVersion',
            'Assembly Version',
        )
        release_date = get_first(infos, 'BuildDate')
        if release_date:
            if len(release_date) >= 10:
                release_date = release_date[:10]
            release_date = release_date.replace('/', '-')

        name = get_first(
            infos,
            'ProductName',
            'OriginalFilename',
            'InternalName',
        )
        copyr = get_first(infos, 'LegalCopyright')

        LegalCopyright = copyr,

        LegalTrademarks = concat(infos, 'LegalTrademarks', 'LegalTrademarks1',
                                 'LegalTrademarks2', 'LegalTrademarks3')

        License = get_first(infos, 'License')

        declared_license = {}
        if LegalCopyright or LegalTrademarks or License:
            declared_license = dict(LegalCopyright=copyr,
                                    LegalTrademarks=LegalTrademarks,
                                    License=License)

        description = concat(infos, 'FileDescription', 'Comments')

        parties = []
        cname = get_first(infos, 'CompanyName', 'Company')

        if cname:
            parties = [Party(type=party_org, role='author', name=cname)]
        homepage_url = get_first(infos, 'URL', 'WWW')

        package_data = models.PackageData(
            datasource_id=cls.datasource_id,
            type=cls.default_package_type,
            name=name,
            version=version,
            release_date=release_date,
            copyright=copyr,
            declared_license=declared_license,
            description=description,
            parties=parties,
            homepage_url=homepage_url,
        )

        if not package_data.license_expression and package_data.declared_license:
            package_data.license_expression = models.compute_normalized_license(
                package_data.declared_license)

        yield package_data