Skip to content
This repository has been archived by the owner on May 17, 2019. It is now read-only.

Commit

Permalink
clean some things up
Browse files Browse the repository at this point in the history
  • Loading branch information
eeue56 committed May 4, 2016
1 parent ca2d1fb commit 5d67d0a
Showing 1 changed file with 57 additions and 9 deletions.
66 changes: 57 additions & 9 deletions elm_deps_upgrade.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,23 @@
import struct
import argparse

def load_all_packages(elm_version):
payload = requests.get("http://package.elm-lang.org/all-packages?elm-package-version={elm_version}".format(
def load_all_packages(elm_version, url=None):
if url is None:
url = "http://package.elm-lang.org/all-packages?elm-package-version="

payload = requests.get("{url}{elm_version}".format(
url=url,
elm_version=elm_version
))

return { item['name'] : item for item in payload.json() }

def load_versions(package_name):
payload = requests.get("http://package.elm-lang.org/versions?name={package_name}".format(
def load_versions(package_name, url=None):
if url is None:
url = "http://package.elm-lang.org/versions?name="

payload = requests.get("{url}{package_name}".format(
url=url,
package_name=package_name
))

Expand All @@ -27,13 +35,30 @@ def load_local_packages(elm_package):
return json.load(f)['dependencies']

def top_range(field):
print(field)
only_end = field[field.index('v'):]

if '=' in only_end:
return only_end.split('=')[-1].strip()
if '<' in only_end:
return only_end.split('<')[-1].strip()

number = only_end.split('<')[-1].strip()

if patch(number) == 0:
if minor(number) == 0:
return '{maj}.{min}.{pat}'.format(
maj = major(number) - 1,
min = 9999999,
pat = 0 )
return '{maj}.{min}.{pat}'.format(
maj = major(number) - 1,
min = minor(number) - 1,
pat = 0 )
return '{maj}.{min}.{pat}'.format(
maj = major(number) - 1,
min = minor(number) - 1,
pat = patch(number) - 1 )



def major(version):
return int(version.split('.')[0])
Expand Down Expand Up @@ -63,16 +88,39 @@ def get_patch_upgrades(top, versions):
return [ version for version in versions
if major(version) == major_top and minor_top == minor(version) and patch_top > patch(version) ]

def print_newer_versions(local_deps, remote_deps):

upgrade_suggestions = []
def find_newer_versions(local_deps, remote_deps):
upgrade_suggestions = {}

for (dep, version) in local_deps.items():
current_version = top_range(version)
patches = get_patch_upgrades(current_version, remote_deps[dep]['versions'])
minors = get_minor_upgrades(current_version, remote_deps[dep]['versions'])
majors = get_major_upgrades(current_version, remote_deps[dep]['versions'])

upgrade_suggestions[dep] = {
'patches': patches,
'minors': minors,
'majors': majors
}

return upgrade_suggestions

def newest_version(suggestions):
if suggestions['majors']:
return suggestions['majors'][-1]
elif suggestions['minors']:
return suggestions['majors'][-1]
else:
return suggestions['patches'][-1]

def print_newer_versions(local_deps, remote_deps):
upgrade_suggestions = []

for (dep, suggestions) in find_newer_versions(local_deps, remote_deps).items():
patches = suggestions['patches']
minors = suggestions['minors']
majors = suggestions['majors']

if len(patches) > 0:
upgrade_suggestions.append(
'Patches available for {dep}: [{patches}]'.format(dep=dep, patches=', '.join(patches))
Expand Down

0 comments on commit 5d67d0a

Please sign in to comment.