-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathftp_version.py
35 lines (30 loc) · 1.47 KB
/
ftp_version.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import requests
import urllib.request as request
from re import findall
# Parse version in tuple of numbers
parse = lambda x: [x[:],tuple(list(map(int, x.split('.'))))]
# function get_info
# Creates a file <name> whith the highest version found of a version
# (string) within the given path. If not found, writes '0'
# Parameters:
# path - URL where to look for the info
# regex - Pattern of what to look for in the path to locate the info
# name - Name of the text file to be written with the info
# cut - funtion indicating what to keep from the regex pattern
def get_info(path, regex, name, cut=(lambda x : x)):
html = str(request.urlopen(path).read())
vers = [x[1:] if x[0]=='v' else x for x in findall(regex, html)]
latest = max(list(map(parse, vers)), key=lambda x: x[1])[0]
file = open(name+'.txt', 'w')
file.writelines(latest)
file.close()
return(latest)
# Define the FTP URL for downloading and uploading packages
ftp_path = 'https://oplab9.parqtec.unicamp.br/pub/ppc64el/docker'
#cli_path = 'https://github.com/docker/cli/releases/latest'
git_path = 'https://github.com/moby/moby/releases/latest'
# find and save the current Github release
#cli_ver = get_info(cli_path, 'v\d\d\.\d\d\.\d+', 'cli_version', cut=(lambda x : x[1:]))
git_ver = get_info(git_path, 'v\d\d\.\d\d\.\d+', 'github_version', cut=(lambda x : x[1:]))
# find and save the current Docker version on FTP server
ftp_ver = get_info(ftp_path, '\d\d\.\d\d\.\d+', 'ftp_version')