Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 1 | def create_socket(url, d): |
| 2 | import urllib |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 3 | from bb.utils import export_proxies |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 4 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 5 | export_proxies(d) |
| 6 | return urllib.request.urlopen(url) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 7 | |
| 8 | def get_links_from_url(url, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 9 | "Return all the href links found on the web location" |
| 10 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 11 | from bs4 import BeautifulSoup, SoupStrainer |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 13 | soup = BeautifulSoup(create_socket(url,d), "html.parser", parse_only=SoupStrainer("a")) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 14 | hyperlinks = [] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 15 | for line in soup.find_all('a', href=True): |
| 16 | hyperlinks.append(line['href'].strip('/')) |
| 17 | return hyperlinks |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 18 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 19 | def find_latest_numeric_release(url, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 20 | "Find the latest listed numeric release on the given url" |
| 21 | max=0 |
| 22 | maxstr="" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 23 | for link in get_links_from_url(url, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 25 | # TODO use LooseVersion |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | release = float(link) |
| 27 | except: |
| 28 | release = 0 |
| 29 | if release > max: |
| 30 | max = release |
| 31 | maxstr = link |
| 32 | return maxstr |
| 33 | |
| 34 | def is_src_rpm(name): |
| 35 | "Check if the link is pointing to a src.rpm file" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 36 | return name.endswith(".src.rpm") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 37 | |
| 38 | def package_name_from_srpm(srpm): |
| 39 | "Strip out the package name from the src.rpm filename" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 40 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 41 | # ca-certificates-2016.2.7-1.0.fc24.src.rpm |
| 42 | # ^name ^ver ^release^removed |
| 43 | (name, version, release) = srpm.replace(".src.rpm", "").rsplit("-", 2) |
| 44 | return name |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 45 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 46 | def get_source_package_list_from_url(url, section, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 47 | "Return a sectioned list of package names from a URL list" |
| 48 | |
| 49 | bb.note("Reading %s: %s" % (url, section)) |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 50 | links = get_links_from_url(url, d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 51 | srpms = filter(is_src_rpm, links) |
| 52 | names_list = map(package_name_from_srpm, srpms) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 53 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 54 | new_pkgs = set() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 55 | for pkgs in names_list: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 56 | new_pkgs.add(pkgs + ":" + section) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | return new_pkgs |
| 58 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 59 | def get_source_package_list_from_url_by_letter(url, section, d): |
| 60 | import string |
| 61 | from urllib.error import HTTPError |
| 62 | packages = set() |
| 63 | for letter in (string.ascii_lowercase + string.digits): |
| 64 | # Not all subfolders may exist, so silently handle 404 |
| 65 | try: |
| 66 | packages |= get_source_package_list_from_url(url + "/" + letter, section, d) |
| 67 | except HTTPError as e: |
| 68 | if e.code != 404: raise |
| 69 | return packages |
| 70 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 71 | def get_latest_released_fedora_source_package_list(d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 72 | "Returns list of all the name os packages in the latest fedora distro" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 73 | latest = find_latest_numeric_release("http://archive.fedoraproject.org/pub/fedora/linux/releases/", d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 74 | package_names = get_source_package_list_from_url_by_letter("http://archive.fedoraproject.org/pub/fedora/linux/releases/%s/Everything/source/tree/Packages/" % latest, "main", d) |
| 75 | package_names |= get_source_package_list_from_url_by_letter("http://archive.fedoraproject.org/pub/fedora/linux/updates/%s/SRPMS/" % latest, "updates", d) |
| 76 | return latest, package_names |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 77 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 78 | def get_latest_released_opensuse_source_package_list(d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 79 | "Returns list of all the name os packages in the latest opensuse distro" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 80 | latest = find_latest_numeric_release("http://download.opensuse.org/source/distribution/leap", d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 81 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 82 | package_names = get_source_package_list_from_url("http://download.opensuse.org/source/distribution/leap/%s/repo/oss/suse/src/" % latest, "main", d) |
| 83 | package_names |= get_source_package_list_from_url("http://download.opensuse.org/update/leap/%s/oss/src/" % latest, "updates", d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 84 | return latest, package_names |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 85 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 86 | def get_latest_released_clear_source_package_list(d): |
| 87 | latest = find_latest_numeric_release("https://download.clearlinux.org/releases/", d) |
| 88 | package_names = get_source_package_list_from_url("https://download.clearlinux.org/releases/%s/clear/source/SRPMS/" % latest, "main", d) |
| 89 | return latest, package_names |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 90 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 91 | def find_latest_debian_release(url, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 92 | "Find the latest listed debian release on the given url" |
| 93 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 94 | releases = [link.replace("Debian", "") |
| 95 | for link in get_links_from_url(url, d) |
| 96 | if link.startswith("Debian")] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 97 | releases.sort() |
| 98 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 99 | return releases[-1] |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 100 | except: |
| 101 | return "_NotFound_" |
| 102 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 103 | def get_debian_style_source_package_list(url, section, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 104 | "Return the list of package-names stored in the debian style Sources.gz file" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 105 | import gzip |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 106 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 107 | package_names = set() |
| 108 | for line in gzip.open(create_socket(url, d), mode="rt"): |
| 109 | if line.startswith("Package:"): |
| 110 | pkg = line.split(":", 1)[1].strip() |
| 111 | package_names.add(pkg + ":" + section) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 112 | return package_names |
| 113 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 114 | def get_latest_released_debian_source_package_list(d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 115 | "Returns list of all the name of packages in the latest debian distro" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 116 | latest = find_latest_debian_release("http://ftp.debian.org/debian/dists/", d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 117 | url = "http://ftp.debian.org/debian/dists/stable/main/source/Sources.gz" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 118 | package_names = get_debian_style_source_package_list(url, "main", d) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 119 | url = "http://ftp.debian.org/debian/dists/stable-proposed-updates/main/source/Sources.gz" |
| 120 | package_names |= get_debian_style_source_package_list(url, "updates", d) |
| 121 | return latest, package_names |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 122 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 123 | def find_latest_ubuntu_release(url, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 124 | """ |
| 125 | Find the latest listed Ubuntu release on the given ubuntu/dists/ URL. |
| 126 | |
| 127 | To avoid matching development releases look for distributions that have |
| 128 | updates, so the resulting distro could be any supported release. |
| 129 | """ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 130 | url += "?C=M;O=D" # Descending Sort by Last Modified |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 131 | for link in get_links_from_url(url, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 132 | if "-updates" in link: |
| 133 | distro = link.replace("-updates", "") |
| 134 | return distro |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 135 | return "_NotFound_" |
| 136 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 137 | def get_latest_released_ubuntu_source_package_list(d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 138 | "Returns list of all the name os packages in the latest ubuntu distro" |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 139 | latest = find_latest_ubuntu_release("http://archive.ubuntu.com/ubuntu/dists/", d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 140 | url = "http://archive.ubuntu.com/ubuntu/dists/%s/main/source/Sources.gz" % latest |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 141 | package_names = get_debian_style_source_package_list(url, "main", d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 142 | url = "http://archive.ubuntu.com/ubuntu/dists/%s-updates/main/source/Sources.gz" % latest |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 143 | package_names |= get_debian_style_source_package_list(url, "updates", d) |
| 144 | return latest, package_names |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 145 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 146 | def create_distro_packages_list(distro_check_dir, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 147 | import shutil |
| 148 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 149 | pkglst_dir = os.path.join(distro_check_dir, "package_lists") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 150 | bb.utils.remove(pkglst_dir, True) |
| 151 | bb.utils.mkdirhier(pkglst_dir) |
| 152 | |
| 153 | per_distro_functions = ( |
| 154 | ("Debian", get_latest_released_debian_source_package_list), |
| 155 | ("Ubuntu", get_latest_released_ubuntu_source_package_list), |
| 156 | ("Fedora", get_latest_released_fedora_source_package_list), |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 157 | ("openSUSE", get_latest_released_opensuse_source_package_list), |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 158 | ("Clear", get_latest_released_clear_source_package_list), |
| 159 | ) |
| 160 | |
| 161 | for name, fetcher_func in per_distro_functions: |
| 162 | try: |
| 163 | release, package_list = fetcher_func(d) |
| 164 | except Exception as e: |
| 165 | bb.warn("Cannot fetch packages for %s: %s" % (name, e)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 166 | bb.note("Distro: %s, Latest Release: %s, # src packages: %d" % (name, release, len(package_list))) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 167 | if len(package_list) == 0: |
| 168 | bb.error("Didn't fetch any packages for %s %s" % (name, release)) |
| 169 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 170 | package_list_file = os.path.join(pkglst_dir, name + "-" + release) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 171 | with open(package_list_file, 'w') as f: |
| 172 | for pkg in sorted(package_list): |
| 173 | f.write(pkg + "\n") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 174 | |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 175 | def update_distro_data(distro_check_dir, datetime, d): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 176 | """ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 177 | If distro packages list data is old then rebuild it. |
| 178 | The operations has to be protected by a lock so that |
| 179 | only one thread performes it at a time. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 180 | """ |
| 181 | if not os.path.isdir (distro_check_dir): |
| 182 | try: |
| 183 | bb.note ("Making new directory: %s" % distro_check_dir) |
| 184 | os.makedirs (distro_check_dir) |
| 185 | except OSError: |
| 186 | raise Exception('Unable to create directory %s' % (distro_check_dir)) |
| 187 | |
| 188 | |
| 189 | datetime_file = os.path.join(distro_check_dir, "build_datetime") |
| 190 | saved_datetime = "_invalid_" |
| 191 | import fcntl |
| 192 | try: |
| 193 | if not os.path.exists(datetime_file): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 194 | open(datetime_file, 'w+').close() # touch the file so that the next open won't fail |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 195 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 196 | f = open(datetime_file, "r+") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 197 | fcntl.lockf(f, fcntl.LOCK_EX) |
| 198 | saved_datetime = f.read() |
| 199 | if saved_datetime[0:8] != datetime[0:8]: |
| 200 | bb.note("The build datetime did not match: saved:%s current:%s" % (saved_datetime, datetime)) |
| 201 | bb.note("Regenerating distro package lists") |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 202 | create_distro_packages_list(distro_check_dir, d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 203 | f.seek(0) |
| 204 | f.write(datetime) |
| 205 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 206 | except OSError as e: |
| 207 | raise Exception('Unable to open timestamp: %s' % e) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 208 | finally: |
| 209 | fcntl.lockf(f, fcntl.LOCK_UN) |
| 210 | f.close() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 211 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 212 | def compare_in_distro_packages_list(distro_check_dir, d): |
| 213 | if not os.path.isdir(distro_check_dir): |
| 214 | raise Exception("compare_in_distro_packages_list: invalid distro_check_dir passed") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 215 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 216 | localdata = bb.data.createCopy(d) |
| 217 | pkglst_dir = os.path.join(distro_check_dir, "package_lists") |
| 218 | matching_distros = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 219 | pn = recipe_name = d.getVar('PN') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 220 | bb.note("Checking: %s" % pn) |
| 221 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 222 | if pn.find("-native") != -1: |
| 223 | pnstripped = pn.split("-native") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 224 | localdata.setVar('OVERRIDES', "pn-" + pnstripped[0] + ":" + d.getVar('OVERRIDES')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 225 | recipe_name = pnstripped[0] |
| 226 | |
| 227 | if pn.startswith("nativesdk-"): |
| 228 | pnstripped = pn.split("nativesdk-") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 229 | localdata.setVar('OVERRIDES', "pn-" + pnstripped[1] + ":" + d.getVar('OVERRIDES')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 230 | recipe_name = pnstripped[1] |
| 231 | |
| 232 | if pn.find("-cross") != -1: |
| 233 | pnstripped = pn.split("-cross") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 234 | localdata.setVar('OVERRIDES', "pn-" + pnstripped[0] + ":" + d.getVar('OVERRIDES')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 235 | recipe_name = pnstripped[0] |
| 236 | |
| 237 | if pn.find("-initial") != -1: |
| 238 | pnstripped = pn.split("-initial") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 239 | localdata.setVar('OVERRIDES', "pn-" + pnstripped[0] + ":" + d.getVar('OVERRIDES')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 240 | recipe_name = pnstripped[0] |
| 241 | |
| 242 | bb.note("Recipe: %s" % recipe_name) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 243 | |
| 244 | distro_exceptions = dict({"OE-Core":'OE-Core', "OpenedHand":'OpenedHand', "Intel":'Intel', "Upstream":'Upstream', "Windriver":'Windriver', "OSPDT":'OSPDT Approved', "Poky":'poky'}) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 245 | tmp = localdata.getVar('DISTRO_PN_ALIAS') or "" |
| 246 | for str in tmp.split(): |
| 247 | if str and str.find("=") == -1 and distro_exceptions[str]: |
| 248 | matching_distros.append(str) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 249 | |
| 250 | distro_pn_aliases = {} |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 251 | for str in tmp.split(): |
| 252 | if "=" in str: |
| 253 | (dist, pn_alias) = str.split('=') |
| 254 | distro_pn_aliases[dist.strip().lower()] = pn_alias.strip() |
| 255 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 256 | for file in os.listdir(pkglst_dir): |
| 257 | (distro, distro_release) = file.split("-") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 258 | f = open(os.path.join(pkglst_dir, file), "r") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 259 | for line in f: |
| 260 | (pkg, section) = line.split(":") |
| 261 | if distro.lower() in distro_pn_aliases: |
| 262 | pn = distro_pn_aliases[distro.lower()] |
| 263 | else: |
| 264 | pn = recipe_name |
| 265 | if pn == pkg: |
| 266 | matching_distros.append(distro + "-" + section[:-1]) # strip the \n at the end |
| 267 | f.close() |
| 268 | break |
| 269 | f.close() |
| 270 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 271 | for item in tmp.split(): |
| 272 | matching_distros.append(item) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 273 | bb.note("Matching: %s" % matching_distros) |
| 274 | return matching_distros |
| 275 | |
| 276 | def create_log_file(d, logname): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 277 | logpath = d.getVar('LOG_DIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 278 | bb.utils.mkdirhier(logpath) |
| 279 | logfn, logsuffix = os.path.splitext(logname) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 280 | logfile = os.path.join(logpath, "%s.%s%s" % (logfn, d.getVar('DATETIME'), logsuffix)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 281 | if not os.path.exists(logfile): |
| 282 | slogfile = os.path.join(logpath, logname) |
| 283 | if os.path.exists(slogfile): |
| 284 | os.remove(slogfile) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 285 | open(logfile, 'w+').close() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 286 | os.symlink(logfile, slogfile) |
| 287 | d.setVar('LOG_FILE', logfile) |
| 288 | return logfile |
| 289 | |
| 290 | |
| 291 | def save_distro_check_result(result, datetime, result_file, d): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 292 | pn = d.getVar('PN') |
| 293 | logdir = d.getVar('LOG_DIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 294 | if not logdir: |
| 295 | bb.error("LOG_DIR variable is not defined, can't write the distro_check results") |
| 296 | return |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 297 | bb.utils.mkdirhier(logdir) |
| 298 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 299 | line = pn |
| 300 | for i in result: |
| 301 | line = line + "," + i |
| 302 | f = open(result_file, "a") |
| 303 | import fcntl |
| 304 | fcntl.lockf(f, fcntl.LOCK_EX) |
| 305 | f.seek(0, os.SEEK_END) # seek to the end of file |
| 306 | f.write(line + "\n") |
| 307 | fcntl.lockf(f, fcntl.LOCK_UN) |
| 308 | f.close() |