Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 2 additions & 19 deletions src/fosslight_util/_get_downloadable_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,11 @@


def extract_name_version_from_link(link):
# Github : https://github.com/(owner)/(repo)
# npm : https://www.npmjs.com/package/(package)/v/(version)
# npm2 : https://www.npmjs.com/package/@(group)/(package)/v/(version)
# pypi : https://pypi.org/project/(oss_name)/(version)
# pypi2 : https://files.pythonhosted.org/packages/source/(alphabet)/(oss_name)/(oss_name)-(version).tar.gz
# Maven: https://mvnrepository.com/artifact/(group)/(artifact)/(version)
# pub: https://pub.dev/packages/(package)/versions/(version)
# Cocoapods: https://cocoapods.org/(package)
pkg_pattern = {
"pypi": r'https?:\/\/pypi\.org\/project\/([^\/]+)[\/]?([^\/]*)',
"pypi2": r'https?:\/\/files\.pythonhosted\.org\/packages\/source\/[\w]\/([^\/]+)\/[\S]+-([^\-]+)\.tar\.gz',
"maven": r'https?:\/\/mvnrepository\.com\/artifact\/([^\/]+)\/([^\/]+)\/?([^\/]*)',
"npm": r'https?:\/\/www\.npmjs\.com\/package\/([^\/\@]+)(?:\/v\/)?([^\/]*)',
"npm2": r'https?:\/\/www\.npmjs\.com\/package\/(\@[^\/]+\/[^\/]+)(?:\/v\/)?([^\/]*)',
"pub": r'https?:\/\/pub\.dev\/packages\/([^\/]+)(?:\/versions\/)?([^\/]*)',
"pods": r'https?:\/\/cocoapods\.org\/pods\/([^\/]+)'
}
oss_name = ""
oss_version = ""
if link.startswith("www."):
link = link.replace("www.", "https://www.", 1)
for key, value in pkg_pattern.items():
for key, value in constant.PKG_PATTERN.items():
p = re.compile(value)
match = p.match(link)
if match:
Expand All @@ -57,7 +40,7 @@ def extract_name_version_from_link(link):
elif key == "pub":
oss_name = f"pub:{origin_name}"
oss_version = match.group(2)
elif key == "pods":
elif key == "cocoapods":
oss_name = f"cocoapods:{origin_name}"
except Exception as ex:
logger.info(f"extract_name_version_from_link {key}:{ex}")
Expand Down
20 changes: 20 additions & 0 deletions src/fosslight_util/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,23 @@
f'SRC_{FL_DEPENDENCY}': FL_DEPENDENCY,
f'BIN_{FL_BINARY}': FL_BINARY,
f'DEP_{FL_DEPENDENCY}': FL_DEPENDENCY}

# Github : https://github.com/(owner)/(repo)
# npm : https://www.npmjs.com/package/(package)/v/(version)
# npm2 : https://www.npmjs.com/package/@(group)/(package)/v/(version)
# pypi : https://pypi.org/project/(oss_name)/(version)
# pypi2 : https://files.pythonhosted.org/packages/source/(alphabet)/(oss_name)/(oss_name)-(version).tar.gz
# Maven: https://mvnrepository.com/artifact/(group)/(artifact)/(version)
# pub: https://pub.dev/packages/(package)/versions/(version)
# Cocoapods : https://cocoapods.org/(package)
# go : https://pkg.go.dev/(package_name_with_slash)@(version)
PKG_PATTERN = {
"pypi": r'https?:\/\/pypi\.org\/project\/([^\/]+)[\/]?([^\/]*)',
"pypi2": r'https?:\/\/files\.pythonhosted\.org\/packages\/source\/[\w]\/([^\/]+)\/[\S]+-([^\-]+)\.tar\.gz',
"maven": r'https?:\/\/mvnrepository\.com\/artifact\/([^\/]+)\/([^\/]+)\/?([^\/]*)',
"npm": r'https?:\/\/www\.npmjs\.com\/package\/([^\/\@]+)(?:\/v\/)?([^\/]*)',
"npm2": r'https?:\/\/www\.npmjs\.com\/package\/(\@[^\/]+\/[^\/]+)(?:\/v\/)?([^\/]*)',
"pub": r'https?:\/\/pub\.dev\/packages\/([^\/]+)(?:\/versions\/)?([^\/]*)',
"cocoapods": r'https?:\/\/cocoapods\.org\/pods\/([^\/]+)',
"go": r'https?:\/\/pkg.go.dev\/([^\@]+)\@?v?([^\/]*)'
}