| 1 |
|
| 2 |
|
| 3 |
> |
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
import json |
| 19 |
import os |
| 20 |
import re |
| 21 |
import shutil |
| 22 |
import subprocess |
| 23 |
import sys |
| 24 |
import urllib.request |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
package_data = {} |
| 29 |
if os.path.exists("downloads/packages.json"): |
| 30 |
with open("downloads/packages.json") as input_file: |
| 31 |
package_data = json.loads(input_file.read()) |
| 32 |
|
| 33 |
|
| 34 |
page_buffer = {} |
| 35 |
with open("packages.txt") as input_file: |
| 36 |
for line in input_file: |
| 37 |
package = line.strip() |
| 38 |
first_letter = package[0].lower() |
| 39 |
|
| 40 |
|
| 41 |
print("Checking package '{}' ... ".format(package), end="") |
| 42 |
|
| 43 |
if not first_letter in page_buffer: |
| 44 |
download_page = urllib.request.urlopen( |
| 45 |
"https://ftp.fau.de/fedora/linux/development/rawhide/Everything/x86_64/os/Packages/{}".format( |
| 46 |
first_letter |
| 47 |
) |
| 48 |
) |
| 49 |
page_buffer[first_letter] = download_page.read().decode() |
| 50 |
download_page.close() |
| 51 |
contents = page_buffer[first_letter] |
| 52 |
|
| 53 |
package_url = re.findall(r"\"({}-[0-9].*?\.rpm)\"".format(package), contents) |
| 54 |
if len(package_url) != 1: |
| 55 |
|
| 56 |
|
| 57 |
found_64 = False |
| 58 |
for item in package_url: |
| 59 |
if "x86_64" in item: |
| 60 |
package_url = item |
| 61 |
found_64 = True |
| 62 |
break |
| 63 |
if not found_64: |
| 64 |
print() |
| 65 |
print( |
| 66 |
"Error: Could not find URL for '{}'.".format(package), |
| 67 |
file=sys.stderr, |
| 68 |
) |
| 69 |
print( |
| 70 |
"If this is a permanent error, please remove the package from the file packages.txt.", |
| 71 |
file=sys.stderr, |
| 72 |
) |
| 73 |
continue |
| 74 |
else: |
| 75 |
package_url = package_url[0] |
| 76 |
|
| 77 |
package_url = "https://ftp.fau.de/fedora/linux/development/rawhide/Everything/x86_64/os/Packages/{}/{}".format( |
| 78 |
first_letter, package_url |
| 79 |
) |
| 80 |
package_filename = re.split(r"/", package_url)[-1] |
| 81 |
|
| 82 |
|
| 83 |
if package in package_data: |
| 84 |
if package_data[package]["filename"] == package_filename: |
| 85 |
print("current.") |
| 86 |
continue |
| 87 |
|
| 88 |
|
| 89 |
package_data[package] = { |
| 90 |
"filename": package_filename, |
| 91 |
"needs_templates": True, |
| 92 |
"needs_update": True, |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
package_dir = "downloads/{}".format(package) |
| 97 |
local_filename = "downloads/{}/{}".format(package, package_filename) |
| 98 |
|
| 99 |
|
| 100 |
os.makedirs(package_dir, exist_ok=True) |
| 101 |
shutil.rmtree(package_dir) |
| 102 |
os.makedirs(package_dir, exist_ok=True) |
| 103 |
|
| 104 |
|
| 105 |
urllib.request.urlretrieve(package_url, local_filename) |
| 106 |
print("downloaded.") |
| 107 |
|
| 108 |
|
| 109 |
os.makedirs("{}/tmp".format(package_dir), exist_ok=True) |
| 110 |
|
| 111 |
|
| 112 |
with open("{}/tmp/tmpcpio".format(package_dir), "w") as outfile: |
| 113 |
subprocess.run(["rpm2cpio", local_filename], stdout=outfile) |
| 114 |
with open("{}/tmp/tmpcpio".format(package_dir), "r") as infile: |
| 115 |
subprocess.run( |
| 116 |
["bsdcpio", "--quiet", "-i", "--make-directories"], |
| 117 |
cwd="{}/tmp".format(package_dir), |
| 118 |
stdin=infile, |
| 119 |
) |
| 120 |
|
| 121 |
|
| 122 |
manpath = "{}/tmp/usr/share/man".format(package_dir) |
| 123 |
for mandir in os.listdir(manpath): |
| 124 |
if not mandir.startswith("man"): |
| 125 |
continue |
| 126 |
|
| 127 |
os.makedirs(mandir, exist_ok=True) |
| 128 |
shutil.move("{}/{}".format(manpath, mandir), "{}".format(package_dir)) |
| 129 |
|
| 130 |
|
| 131 |
shutil.rmtree("downloads/{}/tmp".format(package)) |
| 132 |
os.remove(local_filename) |
| 133 |
|
| 134 |
|
| 135 |
with open("downloads/packages.json", "w") as output_file: |
| 136 |
output_file.write(json.dumps(package_data, sort_keys=True, indent=4)) |