[debian] Refactor script (#221)
Make the script more readable, mostly by: - using the endoflife.Product class, - a little bit of renaming and documentation.
This commit is contained in:
@@ -1,63 +1,53 @@
|
|||||||
import subprocess
|
from common import dates
|
||||||
from common import endoflife
|
from common import endoflife
|
||||||
from common.git import Git
|
from common.git import Git
|
||||||
|
from subprocess import run
|
||||||
|
|
||||||
"""Fetch Debian versions with their dates from www.debian.org source repository.
|
"""Fetch Debian versions by parsing news in www.debian.org source repository."""
|
||||||
"""
|
|
||||||
|
|
||||||
PRODUCT = "debian"
|
|
||||||
REPO_URL = "https://salsa.debian.org/webmaster-team/webwml.git"
|
|
||||||
|
|
||||||
|
|
||||||
def extract_major_releases(releases, repo_dir):
|
def extract_major_versions(product, repo_dir):
|
||||||
child = subprocess.Popen(
|
child = run(
|
||||||
f"grep -RhE -A 1 '<define-tag pagetitle>Debian [0-9]+.+</q> released' {repo_dir}/english/News "
|
f"grep -RhE -A 1 '<define-tag pagetitle>Debian [0-9]+.+</q> released' {repo_dir}/english/News "
|
||||||
f"| cut -d '<' -f 2 "
|
f"| cut -d '<' -f 2 "
|
||||||
f"| cut -d '>' -f 2 "
|
f"| cut -d '>' -f 2 "
|
||||||
f"| grep -v -- '--'",
|
f"| grep -v -- '--'",
|
||||||
shell=True, stdout=subprocess.PIPE)
|
capture_output=True, timeout=300, check=True, shell=True)
|
||||||
output = child.communicate()[0].decode('utf-8')
|
|
||||||
|
|
||||||
is_release_line = True
|
is_release_line = True
|
||||||
version = None
|
version = None
|
||||||
for line in output.split('\n'):
|
for line in child.stdout.decode("utf-8").strip().split("\n"):
|
||||||
if line:
|
if is_release_line:
|
||||||
if is_release_line:
|
version = line.split(" ")[1]
|
||||||
version = line.split(" ")[1]
|
is_release_line = False
|
||||||
is_release_line = False
|
else:
|
||||||
else:
|
product.declare_version(version, dates.parse_date(line))
|
||||||
date = line
|
is_release_line = True
|
||||||
releases[version] = date
|
|
||||||
print(f"{version}: {date}")
|
|
||||||
is_release_line = True
|
|
||||||
|
|
||||||
|
|
||||||
def extract_point_releases(releases, repo_dir):
|
def extract_point_versions(product, repo_dir):
|
||||||
child = subprocess.Popen(
|
child = run(
|
||||||
f"grep -Rh -B 10 '<define-tag revision>' {repo_dir}/english/News "
|
f"grep -Rh -B 10 '<define-tag revision>' {repo_dir}/english/News "
|
||||||
"| grep -Eo '(release_date>(.*)<|revision>(.*)<)' "
|
"| grep -Eo '(release_date>(.*)<|revision>(.*)<)' "
|
||||||
"| cut -d '>' -f 2,4 "
|
"| cut -d '>' -f 2,4 "
|
||||||
"| tr -d '<' "
|
"| tr -d '<' "
|
||||||
"| sed 's/[[:space:]]+/ /' "
|
"| sed 's/[[:space:]]+/ /' "
|
||||||
"| paste -d ' ' - -",
|
"| paste -d ' ' - -",
|
||||||
shell=True, stdout=subprocess.PIPE)
|
capture_output=True, timeout=300, check=True, shell=True)
|
||||||
output = child.communicate()[0].decode('utf-8')
|
|
||||||
|
|
||||||
for line in output.split('\n'):
|
for line in child.stdout.decode("utf-8").strip().split("\n"):
|
||||||
if line:
|
(date, version) = line.split(' ')
|
||||||
parts = line.split(' ')
|
product.declare_version(version, dates.parse_date(date))
|
||||||
date = parts[0]
|
|
||||||
version = parts[1]
|
|
||||||
print(f"{version}: {date}")
|
|
||||||
releases[version] = date
|
|
||||||
|
|
||||||
print(f"::group::{PRODUCT}")
|
|
||||||
git = Git(REPO_URL)
|
product = endoflife.Product("debian")
|
||||||
|
print(f"::group::{product.name}")
|
||||||
|
git = Git("https://salsa.debian.org/webmaster-team/webwml.git")
|
||||||
git.setup()
|
git.setup()
|
||||||
git.checkout("master", file_list=["english/News"])
|
git.checkout("master", file_list=["english/News"])
|
||||||
|
|
||||||
all_versions = {}
|
extract_major_versions(product, git.repo_dir)
|
||||||
extract_major_releases(all_versions, git.repo_dir)
|
extract_point_versions(product, git.repo_dir)
|
||||||
extract_point_releases(all_versions, git.repo_dir)
|
|
||||||
endoflife.write_releases(PRODUCT, all_versions)
|
product.write()
|
||||||
print("::endgroup::")
|
print("::endgroup::")
|
||||||
|
|||||||
Reference in New Issue
Block a user