Commit f8b133e5 authored by Pietro Albini's avatar Pietro Albini

Added md5s.py script

parent d91bf1c4
## Ubuntu-it website scripts ## Ubuntu-it website scripts
A collection of scripts used by the ubuntu-it website team. A collection of scripts used by the ubuntu-it website team.
### MD5 list generator
* Author: Pietro Albini (pietro98-albini)
* Language: Python 3
* File: `md5s.py`
This script generates the list of all md5s, which can be used to update the "Check the footprint" box in the download page.
If you specific only some releases with parameters, only that releases will be included in the output.
#### Basic usage
```
python3 md5s.py --latest <latest_release_number> --lts <latest_lts_codename> --ita <latest_lts_codename> --derivatives --render-as php
```
#### Accepted options
* `--latest`: The latest release number (example: 13.10)
* `--lts`: The latest lts release number (example: 12.04.4)
* `--ita`: The latest italian remix codename (example: precise)
* `--derivatives`: If passed, get footprints also of all the derivatives
* `--render-as`: Set the render format; Available formats:
* `php`: Format used by our script in the "Check the footprint" box
* `moin`: Format used in our wiki, useful for update the md5s list
#!/usr/bin/python3
# Script that generate a list of all Ubuntu MD5s
# Copyright (C) 2014 Pietro Albini
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import argparse
import urllib.request
import re
DEFAULT = {'ubuntu': {'parser': 'official', 'releases': ['desktop', 'server'], 'versions': ['latest', 'lts'], 'archs': ['i386', 'amd64']},
'ita': {'parser': 'ita', 'releases': ['desktop'], 'versions': ['ita'], 'archs': ['i386', 'amd64']}
}
DERIVATIVES = {'kubuntu': {'parser': 'derivatives', 'releases': ['desktop'], 'versions': ['latest'], 'archs': ['i386', 'amd64']},
'xubuntu': {'parser': 'derivatives', 'releases': ['desktop'], 'versions': ['latest'], 'archs': ['i386', 'amd64']},
'lubuntu': {'parser': 'derivatives', 'releases': ['desktop'], 'versions': ['latest'], 'archs': ['i386', 'amd64']},
'edubuntu': {'parser': 'derivatives', 'releases': ['dvd'], 'versions': ['latest'], 'archs': ['i386', 'amd64']},
'ubuntustudio': {'parser': 'derivatives', 'releases': ['dvd'], 'versions': ['latest'], 'archs': ['i386', 'amd64']},
'mythbuntu': {'parser': 'derivatives', 'releases': ['desktop'], 'versions': ['lts'], 'archs': ['i386', 'amd64']}
}
def get_base_md5_dict(releases, archs):
""" Build the base md5s dict """
result = {}
for release in releases:
sub = {}
for arch in archs:
sub[arch] = None
result[release] = sub
return result
def official_md5_list(distro, version, releases, archs):
web = urllib.request.urlopen('http://releases.ubuntu.com/'+version+'/MD5SUMS')
lines = web.read().decode('utf-8').split('\n')
md5s = get_base_md5_dict(releases, archs)
for line in lines:
try:
info = re.sub(r'(.*) \*ubuntu-'+version+r'-(.*)-(.*)\.iso', r'\1|\2|\3', line).split('|') # Parse the line
if info[1] in md5s and info[2] in md5s[ info[1] ]:
md5s[ info[1] ][ info[2] ] = {'md5': info[0], 'filename': 'ubuntu-'+version+'-'+info[1]+'-'+info[2]+'.iso'}
except IndexError:
pass
return md5s
def derivatives_md5_list(distro, version, releases, archs):
web = urllib.request.urlopen('http://cdimage.ubuntu.com/'+distro+'/releases/'+version+'/release/MD5SUMS')
lines = web.read().decode('utf-8').split('\n')
md5s = get_base_md5_dict(releases, archs)
for line in lines:
try:
info = re.sub(r'(.*) \*'+distro+'-'+version+r'-(.*)-(.*)\.iso', r'\1|\2|\3', line).split('|') # Parse the line
if info[1] in md5s and info[2] in md5s[ info[1] ]:
md5s[ info[1] ][ info[2] ] = {'md5': info[0], 'filename': distro+'-'+version+'-'+info[1]+'-'+info[2]+'.iso'}
except IndexError:
pass
return md5s
def italian_md5_list(distro, version, releases, archs):
md5s = get_base_md5_dict(releases, archs)
for arch in archs:
for release in releases:
web = urllib.request.urlopen('http://release.ubuntu-it.org/'+version+'-it-'+arch+'/'+version+'-'+release+'-'+arch+'.iso.md5')
lines = web.read().decode('utf-8').split('\n')
for line in lines:
try:
info = re.sub(r'(.*) (.*)-(.*)-(.*)\.iso', r'\1|\2|\3|\4', line).split('|')
md5s[ info[2] ][ info[3] ] = {'md5': info[0], 'filename': info[1]+'-'+info[2]+'-'+info[3]+'.iso'}
except IndexError:
pass
return md5s
def get(distro, info):
""" Get md5s of a specific distro """
getters = {'official': official_md5_list, 'derivatives': derivatives_md5_list, 'ita': italian_md5_list}
versions = set( info['versions'] ) & available # available versions
result = {}
for version in versions:
output = getters[ info['parser'] ]( distro, getattr(args, version), info['releases'], info['archs'] )
if distro == 'ita':
version = 'lts_ita'
result[version] = output
return result
def render_php(md5s):
for distro, versions in md5s.items():
for version, releases in versions.items():
for release, archs in releases.items():
for arch, md5 in archs.items():
if md5:
if distro == 'ita':
distro = 'ubuntu'
print("$md5s['"+distro+"']['"+version+"']['"+release+"']['"+arch+"'] = '"+md5['md5']+"';")
def render_moin(md5s):
for distro, versions in md5s.items():
for version, releases in versions.items():
for release, archs in releases.items():
for arch, md5 in archs.items():
if md5:
if distro == 'ita':
distro = 'ubuntu'
print("|| "+md5['md5']+" || "+md5['filename']+" ||")
print()
if __name__ == '__main__':
# Setup argparse
parser = argparse.ArgumentParser()
parser.add_argument("--latest", help="Set which version is the latest")
parser.add_argument("--lts", help="Set which version is the LTS")
parser.add_argument("--ita", help="Set which version is the italian remix")
parser.add_argument("--derivatives", help="Choose if include derivatives", action="store_true")
parser.add_argument("--render-as", help="Set how render the result", default='php', choices=('php', 'moin'))
args = parser.parse_args() # Get arguments
# Get available versions
available = set()
if args.latest:
available.add('latest')
if args.lts:
available.add('lts')
if args.ita:
available.add('ita')
total = {}
total['ubuntu'] = get('ubuntu', DEFAULT['ubuntu'])
if args.ita:
total['ita'] = get('ita', DEFAULT['ita'])
if args.derivatives:
for which in DERIVATIVES:
total[which] = get(which, DERIVATIVES[which])
if args.render_as == 'php':
render_php(total)
elif args.render_as == 'moin':
render_moin(total)
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment