Commit 898c0feb authored by shadMod's avatar shadMod 💬

added src folder

added costants.json with the list of with the desired distros and relative descriptions

added compile_download to compile downloads.toml in './data/'

Fixes: #14
parent ae454aa7
# Source code of the Ubuntu-it website
# Copyright (C) 2023 shadMod
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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; witout even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Source code of the Ubuntu-it website
# Copyright (C) 2023 shadMod
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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; witout even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
{
"archs": {
"amd64": "64bit",
"arm64": "ARM 64bit",
"ppc64el": "POWER"
},
"mirrors": {
"country": "IT",
"for": [
"ubuntu"
]
},
"distros": {
"desktop": {
"name": "Ubuntu",
"description": "L'originale, con GNOME"
},
"live-server": {
"name": "Ubuntu Server",
"description": "Tutta la potenza di Ubuntu nel tuo server"
},
"kubuntu": {
"name": "Kubuntu",
"description": "L'esperienza Ubuntu con desktop KDE"
},
"lubuntu": {
"name": "Lubuntu",
"description": "La derivata pi\u00f9 leggera, con LXDE"
},
"ubuntu-budgie": {
"name": "Ubuntu Budgie",
"description": "La potenza di Ubuntu e la leggerezza di Budgie"
},
"ubuntukylin": {
"name": "Ubuntu Kylin",
"description": "La derivata di Ubuntu con desktop UKUI"
},
"ubuntu-mate": {
"name": "Ubuntu MATE",
"description": "Ubuntu si unisce a MATE"
},
"ubuntustudio": {
"name": "Ubuntu Studio",
"description": "La derivata di Ubuntu dedicata alla multimedialit\u00e0"
},
"xubuntu": {
"name": "Xubuntu",
"description": "La derivata di Ubuntu leggera ma personalizzabile, con desktop XFCE"
}
}
}
# Source code of the Ubuntu-it website
# Copyright (C) 2023 shadMod
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero 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; witout even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import traceback
import toml
import json
import requests
from urllib.request import urlopen
from urllib.error import HTTPError
class CompileVersion:
"""
:param ARM64: set distro with arm64 architecture
:param PPC64EL: set distro with ppc64el architecture
:param SUPPORT_5: set distro with 5 years support (else are 3 years)
:param INVERT_RELEASES: set if you want invert releases in template render
:param path_url: url to get version list
:param path_out: path where the toml file will be written
:param constants: constants path
:param ignore_interim: list of tags of interim versions to be ignored
:param ignore_lts: list of tags of lts versions to be ignored
N.B.: 'interim' === 'latest'
"""
ARM64 = ["live-server"]
PPC64EL = ["live-server"]
SUPPORT_5 = ["desktop", "live-server"]
INVERT_RELEASES = ["live-server"]
def __init__(
self,
path_url: str = "https://releases.ubuntu.com/?C=M;O=A",
path_out: str = "../../data/downloads.toml",
constants: str = "./assets/costants.json",
ignore_interim: list = None,
ignore_lts: list = None,
):
self.path_url = path_url
self.path_out = path_out
self.constants = constants
self.ignore_interim = ignore_interim if ignore_interim else []
self.ignore_lts = ignore_lts if ignore_lts else []
@property
def data_sources(self) -> list:
return [
(
"releases-ubuntu",
"https://releases.ubuntu.com/{codename}/ubuntu-{version}-{distro}-{arch}.iso",
),
(
"cdimages-ubuntu",
"https://cdimages.ubuntu.com/releases/{codename}/release/ubuntu-{version}-{distro}-{arch}.iso",
),
(
"cdimages-derivatives",
"https://cdimages.ubuntu.com/{distro}/releases/{codename}/release/{distro}-{version}-desktop-{arch}.iso",
),
(
"cdimages-studio",
"https://cdimages.ubuntu.com/{distro}/releases/{codename}/release/{distro}-{version}-dvd-{arch}.iso",
),
]
@property
def ver_lts(self) -> str:
return max(self.ver_lts_list)
@property
def ver_interim(self) -> str:
return max(self.ver_interim_list)
@property
def ver_lts_list(self) -> list:
return self.get_list_version["lts"]
@property
def ver_interim_list(self) -> list:
return self.get_list_version["latest"]
@property
def get_list_version(self) -> dict:
res = requests.get(self.path_url)
status = res.status_code
if status != 200:
raise Exception(f"Error requests - status: {status}")
ver_list = {"latest": [], "lts": []}
table_rows = res.text.split('<img src="/icons/folder.gif" alt="[DIR]"> ')[1:]
for val in table_rows:
row = val.split('/">')
version = row[0].replace('<a href="', "")
if "Ubuntu " in row[1] and "." in version:
_version, name = row[1].split("Ubuntu ")[1].split("(")
name = name.replace(")\n", "")
codename = name.split(" ")[0].lower()
ver, release_type = _version.split(" ")[0:2]
if release_type == "LTS":
if codename not in self.ignore_lts:
ver_list["lts"].append((version, codename, name))
else:
if codename not in self.ignore_interim:
ver_list["latest"].append((version, codename, name))
return ver_list
def compile_download(self) -> None:
# put constants in empty data
with open(self.constants, "r") as fn:
data = json.load(fn)
# write all distros and relative archs
for key in data["distros"]:
data["distros"][key]["lts-only"] = False
data["distros"][key]["releases"] = ["latest", "lts"]
data["distros"][key]["lts-support-years"] = (
5 if key in self.SUPPORT_5 else 3
)
data["distros"][key]["releases"] = (
["latest", "lts"]
if key not in self.INVERT_RELEASES
else ["lts", "latest"]
)
# write all releases
releases = {
"amd64": self.populate_archs_releases(key, "amd64")
}
if key in self.ARM64:
releases["arm64"] = self.populate_archs_releases(key, "arm64")
if key in self.PPC64EL:
releases["ppc64el"] = self.populate_archs_releases(key, "ppc64el")
data["distros"][key]["archs"] = releases
# write sources
data["sources"] = {}
for key, path in self.data_sources:
data["sources"][key] = {"https": path, "torrent": path + ".torrent"}
# write download.toml
with open(self.path_out, "w") as out:
toml.dump(data, out)
def get_releases(self, data: list, distro: str, arch: str, typology: str) -> dict:
"""
:param typology: latest or lts
"""
version, codename, host = None, None, None
for version, codename, name in sorted(data, key=lambda x: x[0], reverse=True):
host = None
for http, path in self.data_sources:
try:
conn = urlopen(
path.format(
distro=distro, codename=codename, version=version, arch=arch
)
)
except HTTPError:
pass
except ValueError:
pass
else:
host = http
conn.close()
break
if host:
return {
"version": version,
"codename": codename,
"host": host,
"lts": False if typology == "latest" else True,
}
if host is None:
raise Exception("No correct host")
def populate_archs_releases(self, distro: str, arch: str) -> dict:
rels = {}
for key, data in self.get_list_version.items():
rels[key] = self.get_releases(data, distro, arch, key)
if not rels:
raise Exception("Empty dict archs releases")
return rels
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