Skip to content

Commit c94bc7d

Browse files
gountharclaude
andcommitted
fix: sync correct Python stdlib implementation from main
Previous commit accidentally synced an older shell-based version. This commit syncs the correct Python stdlib implementation from upstream/main that includes: - Python xml.etree.ElementTree for XML parsing - urllib.request/urllib.error for HTTP with error handling - try-except blocks for HTTP failures - Validation that results were found - ValueError handling for malformed versions Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent ffbb372 commit c94bc7d

1 file changed

Lines changed: 65 additions & 16 deletions

File tree

updatecli/updatecli.d/android.yaml

Lines changed: 65 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,80 @@ scms:
1414
branch: "{{ .github.branch }}"
1515

1616
sources:
17-
# Uses official Google SDK repository XML (not JS-rendered website)
17+
# Uses Python stdlib to parse official Google SDK repository XML
18+
# This is more reliable than shell pipelines with curl/grep/sed
1819
androidCommandLineTools:
1920
kind: shell
2021
spec:
21-
command: >-
22-
curl -sL "https://dl.google.com/android/repository/repository2-3.xml" |
23-
grep 'commandlinetools-linux' |
24-
sed 's/.*commandlinetools-linux-\([0-9]*\).*/\1/' |
25-
sort -n |
26-
tail -1
22+
command: |
23+
python3 -c "
24+
import xml.etree.ElementTree as ET
25+
import urllib.request
26+
import urllib.error
27+
import re
28+
import sys
29+
30+
try:
31+
with urllib.request.urlopen('https://dl.google.com/android/repository/repository2-3.xml') as f:
32+
tree = ET.parse(f)
33+
except (urllib.error.URLError, urllib.error.HTTPError) as e:
34+
print(f'Error fetching SDK repository: {e}', file=sys.stderr)
35+
sys.exit(1)
36+
37+
found = False
38+
for elem in tree.iter():
39+
if elem.tag.endswith('url') and elem.text and 'commandlinetools-linux' in elem.text:
40+
m = re.search(r'commandlinetools-linux-(\d+)_', elem.text)
41+
if m:
42+
print(m.group(1))
43+
found = True
44+
break
45+
46+
if not found:
47+
print('Error: No commandlinetools-linux version found', file=sys.stderr)
48+
sys.exit(1)
49+
"
2750
environments:
2851
- name: PATH
2952

30-
# Uses official Google SDK repository XML to get latest stable build-tools
31-
# Excludes release candidates (-rc versions) and sorts by version number
53+
# Gets latest stable build-tools version (excludes release candidates)
3254
androidBuildTools:
3355
kind: shell
3456
spec:
35-
command: >-
36-
curl -sL "https://dl.google.com/android/repository/repository2-3.xml" |
37-
grep 'remotePackage path="build-tools;' |
38-
grep -v '-rc' |
39-
sed 's/.*build-tools;\([^"]*\)".*/\1/' |
40-
sort -V |
41-
tail -1
57+
command: |
58+
python3 -c "
59+
import xml.etree.ElementTree as ET
60+
import urllib.request
61+
import urllib.error
62+
import sys
63+
64+
try:
65+
with urllib.request.urlopen('https://dl.google.com/android/repository/repository2-3.xml') as f:
66+
tree = ET.parse(f)
67+
except (urllib.error.URLError, urllib.error.HTTPError) as e:
68+
print(f'Error fetching SDK repository: {e}', file=sys.stderr)
69+
sys.exit(1)
70+
71+
versions = []
72+
for elem in tree.iter():
73+
if elem.tag.endswith('remotePackage'):
74+
path = elem.get('path', '')
75+
if path.startswith('build-tools;') and '-rc' not in path:
76+
versions.append(path.replace('build-tools;', ''))
77+
78+
if not versions:
79+
print('Error: No stable build-tools versions found', file=sys.stderr)
80+
sys.exit(1)
81+
82+
def version_key(v):
83+
try:
84+
return tuple(int(x) for x in v.split('.'))
85+
except ValueError:
86+
return (0,) # Invalid versions sort to beginning
87+
88+
versions.sort(key=version_key)
89+
print(versions[-1])
90+
"
4291
environments:
4392
- name: PATH
4493

0 commit comments

Comments
 (0)