Last active
February 17, 2019 06:50
-
-
Save garlandcrow/0b7674cb1126db5fdb96ee7e01198f6c to your computer and use it in GitHub Desktop.
checks rust nightly for rls support or finds the last version for you
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import urllib.request | |
import sys | |
from datetime import datetime, timedelta | |
from urllib.error import HTTPError | |
import pytoml as toml | |
def is_rls_availble_on_nightly(day, month, year, target='x86_64-apple-darwin', do_print=False): | |
url = 'https://static.rust-lang.org/dist/{}-{:02d}-{:02d}/channel-rust-nightly.toml'.format( | |
year, | |
month, | |
day, | |
) | |
print("Checking nightly-{}-{:02d}-{:02d}".format(year, month, day)) | |
try: | |
response = urllib.request.urlopen(url) | |
data = response.read() | |
rust_info = toml.loads(data) | |
is_available = rust_info['pkg']['rls-preview']['target'][target]['available'] | |
if do_print: | |
print("\tHas rls-preview? %s" % ("Yes" if is_available else "No")) | |
return is_available | |
except HTTPError: | |
print('\tNo nighly exists.') | |
return None | |
except KeyError: | |
print('\tNo "rls-preview" section exists for target=%s.' % target) | |
return None | |
def find_last_version_with_rls(): | |
LAST_X_DAYS = 60 | |
now = datetime.now() | |
for day_delta in range(LAST_X_DAYS): | |
test_date = now - timedelta(days=day_delta) | |
did_find = is_rls_availble_on_nightly( | |
day=test_date.day, | |
month=test_date.month, | |
year=test_date.year, | |
do_print=True, | |
) | |
if did_find: | |
return True | |
return False | |
def parse_date_arg(date_arg): | |
[y, m, d] = [int(n) for n in date_arg.split('-')] | |
if m < 1 or m > 12 or d < 1 or d > 31: | |
raise ValueError | |
return (y, m, d) | |
if __name__ == "__main__": | |
try: | |
if len(sys.argv) > 1: | |
if sys.argv[1] == '--find': | |
find_last_version_with_rls() | |
sys.exit() | |
else: | |
(y, m, d) = parse_date_arg(sys.argv[1]) | |
else: | |
now = datetime.now() | |
(y, m, d) = (now.year, now.month, now.day) | |
is_rls_availble_on_nightly( | |
day=d, | |
month=m, | |
year=y, | |
do_print=True, | |
) | |
except ValueError: | |
print('You must pass valid date as "YYYY-MM-DD"') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment