Skip to content

Commit

Permalink
Doing a head in package url version. fix #1
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielVenturini committed May 25, 2019
1 parent 9ec5d37 commit 0f8bcdf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
12 changes: 11 additions & 1 deletion network.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
interface:
get(package_name)
'''
# index 0 is the package_name; index 1 is the version
default_url = 'https://registry.npmjs.org/{0}/-/{0}-{1}.tgz'

def get(package_name):

Expand All @@ -17,4 +19,12 @@ def get(package_name):
print(Fore.RED + 'package `{0}´ not found.'.format(package_name))
raise Exception()
else:
return response.json()
return response.json()

def exists(package_name, resolved_version):
url_package = default_url.format(package_name, resolved_version)
response = requests.head(url_package)
if response.status_code == 404:
return False
else:
return True
18 changes: 10 additions & 8 deletions worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ def get_times(time, date):


# get the resolved version and verify if exists
def get_version(versions, svr):
def get_version(dependency, versions, svr):
if not len(versions):
return None

resolved_version = svr.best_satisfies(versions)
# verify if resolved_version exists
# if ntw.exists(resolved_version):
# return resolved_versions
# else:
# versions.remove(resolved_version)
# return get_version(versions, svr)
return resolved_version
if ntw.exists(dependency, resolved_version):
return resolved_version
else:
versions.remove(str(resolved_version))
return get_version(dependency, versions, svr)


# get only the versions that is major
Expand All @@ -60,7 +62,7 @@ def resolve_version(dependency, version, date):
nvrp = NodeVersionRangeParser()
svr = nvrp.parse(version)
# get the best satisfies range
new_version = get_version(versions, svr)
new_version = get_version(dependency, versions, svr)

# if one version satisfies
if new_version:
Expand Down

0 comments on commit 0f8bcdf

Please sign in to comment.