Ejemplo n.º 1
0
def get_package_columns(_columns=set()):
    """
    Return (and cache in_columns) a set of package column names included in the
    CSV output.
    Some columsn are excluded for now such as lists of mappings: these do not
    serialize well to CSV
    """
    if _columns:
        return _columns

    from packagedcode.models import Package

    # exclude some columns for now that contain list of items
    excluded_columns = {
        # list of strings
        'keywords',
        # list of dicts
        'parties',
        'dependencies',
        'source_packages',
    }

    # some extra columns for components
    extra_columns = [
        'components',
        'owner_name',
        'reference_notes',
        'description',
        'notice_filename',
        'notice_url',
    ]

    fields = Package.fields() + extra_columns
    _columns = set(f for f in fields if f not in excluded_columns)
    return _columns
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)
 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.º 4
0
def package_summarizer(resource, children, keep_details=False):
    """
    Populate a packages summary list of packages mappings.

    Note: `keep_details` is never used, as we are not keeping details of
    packages as this has no value.
    """
    packages = []

    # Collect current data
    current_packages = getattr(resource, 'packages') or []

    if TRACE_LIGHT and current_packages:
        from packagedcode.models import Package
        packs = [Package.create(**p) for p in current_packages]
        logger_debug('package_summarizer: for:', resource,
                     'current_packages are:', packs)

    current_packages = add_files(current_packages, resource)
    packages.extend(current_packages)

    if TRACE_LIGHT and packages:
        logger_debug()
        from packagedcode.models import Package  # NOQA
        packs = [Package.create(**p) for p in packages]
        logger_debug('package_summarizer: for:', resource, 'packages are:',
                     packs)

    # Collect direct children packages summary
    for child in children:
        child_summaries = get_resource_summary(
            child, key='packages', as_attribute=False) or []
        packages.extend(child_summaries)

    # summarize proper
    set_resource_summary(resource,
                         key='packages',
                         value=packages,
                         as_attribute=False)
    return packages
Ejemplo n.º 5
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.º 6
0
    def get_package_root(cls, manifest_resource, codebase):
        if manifest_resource.name.endswith(('pom.xml', '.pom',)):
            # the root is either the parent or further up for poms stored under
            # a META-INF dir
            package_data = manifest_resource.packages
            if not package_data:
                return manifest_resource
            package_data = package_data[0]
            package = Package.create(**package_data)
            ns = package.namespace
            name = package.name
            path = 'META-INF/maven/{ns}/{name}/pom.xml'.format(**locals())
            if manifest_resource.path.endswith(path):
                for ancestor in manifest_resource.ancestors(codebase):
                    if ancestor.name == 'META-INF':
                        jar_root_dir = ancestor.parent(codebase)
                        return jar_root_dir

            return manifest_resource.parent(codebase)

        return manifest_resource