Skip to content

Commit

Permalink
Create purl for google code archive URL #78
Browse files Browse the repository at this point in the history
Signed-off-by: Jono Yang <[email protected]>
  • Loading branch information
JonoYang committed Feb 11, 2022
1 parent 34fe6c2 commit 99bd8d2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Changelog
- Increase the name field size for packageurl.contrib.django.models.PackageURLMixin to 255 #73
- Use project name as the Package name when creating generic sourceforge PackageURLs #74
- Update PyPI route pattern in url2purl to handle different file name formats #76
- Create generic PackageURL for code.google.com archive URLs #78

0.9.7 (2022-02-07)
------------------
Expand Down
17 changes: 17 additions & 0 deletions src/packageurl/contrib/url2purl.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import os
import re
import tarfile
from urllib.parse import unquote_plus
from urllib.parse import urlparse

Expand Down Expand Up @@ -615,3 +616,19 @@ def build_gitlab_purl(url):
)

register_pattern('hackage', hackage_pattern)


@purl_router.route('https?://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/.*')
def build_generic_google_code_archive_purl(uri):
# https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/android-notifier/android-notifier-desktop-0.5.1-1.i386.rpm
_, remaining_uri = uri.split('https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/') # android-notifier/android-notifier-desktop-0.5.1-1.i386.rpm
if remaining_uri:
split_remaining_uri = remaining_uri.split("/") # android-notifier, android-notifier-desktop-0.5.1-1.i386.rpm
if split_remaining_uri:
name = split_remaining_uri[0] # android-notifier
return PackageURL(
type='generic',
namespace='code.google.com',
name=name,
qualifiers={'download_url': uri}
)
3 changes: 2 additions & 1 deletion tests/contrib/data/url2purl.json
Original file line number Diff line number Diff line change
Expand Up @@ -249,5 +249,6 @@
"https://hackage.haskell.org/package/3d-graphics-examples-0.0.0.2/3d-graphics-examples-0.0.0.2.tar.gz": "pkg:hackage/[email protected]",
"https://salsa.debian.org/lxc-team/lxc/-/archive/master/lxc-master.tar.gz": "pkg:generic/lxc-master.tar.gz?download_url=https://salsa.debian.org/lxc-team/lxc/-/archive/master/lxc-master.tar.gz",
"http://apt-rpm.org/": null,
"": null
"": null,
"https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/android-notifier/android-notifier-desktop-0.5.1-1.i386.rpm": "pkg:generic/code.google.com/android-notifier?download_url=https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/android-notifier/android-notifier-desktop-0.5.1-1.i386.rpm"
}

0 comments on commit 99bd8d2

Please sign in to comment.