Skip to content

Commit 00e24b8

Browse files
authored
Merge pull request #1 from armbian/base-files
Add JSON for generating base-files info
2 parents 70be800 + fb853e6 commit 00e24b8

File tree

2 files changed

+94
-0
lines changed

2 files changed

+94
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
name: Update base-files pacakge info
2+
# Trigger this workflow on a manual dispatch or a scheduled time
3+
on:
4+
workflow_dispatch: # Manually triggered via GitHub Actions UI
5+
schedule:
6+
- cron: '0 * * * *' # Run every hour
7+
jobs:
8+
run-script:
9+
runs-on: ubuntu-latest
10+
steps:
11+
# Step 1: Checkout the repository
12+
- name: Checkout repository
13+
uses: actions/checkout@v4
14+
# Step 2: Set up Python environment
15+
- name: Set up Python
16+
uses: actions/setup-python@v4
17+
with:
18+
python-version: 3.x
19+
# Step 3: Install dependencies (if you have any)
20+
- name: Install dependencies
21+
run: |
22+
sudo apt install -y python3-requests python3-lxml
23+
# Step 4: Run the Python script
24+
- name: Run parser script
25+
run: scripts/package-info-parser.py base-files
26+
# Step 5: Commit changes if any
27+
- name: Commit changes if any
28+
run: |
29+
git checkout www
30+
git config --global user.name "github-actions"
31+
git config --global user.email "[email protected]"
32+
git add base-files.json
33+
git diff --cached --quiet || git commit -m "Update base-files package info"
34+
git push
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/python3
2+
import requests
3+
from lxml import etree
4+
import json
5+
import sys
6+
def get_package_info_from_upstream(distro, pacakge_name):
7+
if distro == 'debian':
8+
distro_url = "https://packages.debian.org/search?keywords=" + pacakge_name + "&searchon=names&suite=all&section=all"
9+
elif distro == 'ubuntu':
10+
distro_url = "https://packages.ubuntu.com/search?keywords=" + pacakge_name + "&searchon=names&suite=all&section=all"
11+
else:
12+
print("invalid distro %s, quit" % distro)
13+
sys.exit(1)
14+
# Step 1: Fetch HTML content from the URL
15+
response = requests.get(distro_url)
16+
html_content = response.content # Use .content for lxml to handle byte data
17+
# Step 2: Parse HTML with lxml
18+
parser = etree.HTMLParser()
19+
tree = etree.fromstring(html_content, parser)
20+
# Step 3: Extract data
21+
for h3 in tree.xpath('//h3'):
22+
section_title = h3.text
23+
ul = h3.xpath('./following-sibling::ul[1]')
24+
debian_all_package_info = {}
25+
if ul:
26+
list_items = ul[0].xpath('.//li')
27+
for li in list_items:
28+
debian_package_info = {}
29+
item_text = li.xpath('.//text()[not(parent::a)]')
30+
item_class = li.get("class")
31+
package_file_release = item_class
32+
package_file_version = item_text[1].split(":")[0]
33+
if "arm64" in item_text[1].split(":")[1]:
34+
package_file_arm64_full_name = pacakge_name + "_" + package_file_version + "_arm64.deb"
35+
debian_package_info["arm64"] = package_file_arm64_full_name
36+
if "armhf" in item_text[1].split(":")[1]:
37+
package_file_armhf_full_name = pacakge_name + "_" + package_file_version + "_armhf.deb"
38+
debian_package_info["armhf"] = package_file_armhf_full_name
39+
if "amd64" in item_text[1].split(":")[1]:
40+
package_file_amd64_full_name = pacakge_name + "_" + package_file_version + "_amd64.deb"
41+
debian_package_info["amd64"] = package_file_amd64_full_name
42+
if "riscv64" in item_text[1].split(":")[1]:
43+
package_file_riscv64_full_name = pacakge_name + "_" + package_file_version + "_riscv64.deb"
44+
debian_package_info["riscv64"] = package_file_riscv64_full_name
45+
debian_all_package_info[item_class] = debian_package_info
46+
return debian_all_package_info
47+
if len(sys.argv) < 2:
48+
print("Usage: python parse.py <pacakge_name>")
49+
sys.exit(1)
50+
package_name = sys.argv[1]
51+
debian_info = get_package_info_from_upstream("debian", package_name)
52+
ubuntu_info = get_package_info_from_upstream("ubuntu", package_name)
53+
if debian_info and ubuntu_info:
54+
all_info_result = {**debian_info, **ubuntu_info}
55+
json_file_name = package_name + ".json"
56+
with open(json_file_name, "w") as outfile:
57+
json.dump(all_info_result, outfile)
58+
else:
59+
print("failed to get package info")
60+
sys.exit(1)

0 commit comments

Comments
 (0)