summaryrefslogtreecommitdiff
path: root/auto/pypi.sh
blob: d78ba138a3e1f255a477728f02fd37d6e491c6c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/sh

[ -f /usr/lib/colors.sh ] && . /usr/lib/colors.sh

if [ $# = 0 ]; then
    printf "Name of package: python-"
    read name
else
    name=$1
fi

json_url=https://pypi.org/pypi/$name/json

if [ "$(curl -s -o /dev/null -w "%{http_code}" $json_url)" != 200 ] ; then
   echo "Failed to find $name" 
   exit 1
fi

json=$(curl -SsL $json_url)
version=$(echo $json | jq -r '.info.version')
desc=$(echo $json | jq -r '.info.summary')
url=$(echo $json | jq -r '.urls[] | select((.version="1.0.3")) | .url' | grep -v "whl" | sed "s/$version/\$PKG_VER/g")
deps=$(echo $json | jq -r '.info.requires_dist | .[]' | cut -d' ' -f1 | tr '\n' ' ')
if [ ${#deps} != 0 ]; then
    package_deps=$(echo $deps | sed 's/\(\w*\)/python-\1/g')
    echo $package_deps
fi

echo PKG_VER: $version
echo DESC: $desc
echo SOURCE: $url
echo DEPS: $package_deps

file=repo/python-$name.xibuild

inp=templates/pypi.xibuild
if [ -f $file ]; then
    inp=$file
    echo "replacing existing"
fi

tmp=/tmp/python-$name.xibuild
rm -f $tmp
cat $inp > $tmp

sed -i "s@^SOURCE=.*@SOURCE=$url@g" $tmp
sed -i "s@^PKG_VER=.*@PKG_VER=$version@g" $tmp
sed -i "s@^DESC=.*@DESC=\"$desc\"@g" $tmp

if [ ${#deps} != 0 ]; then
    printf "${LIGHT_BLUE}Please ensure the following exist: ${BLUE}${deps}${RESET}\n"
    sed -i "s/^DEPS=.*/DEPS=\"$package_deps\"/g" $tmp
fi

mv $tmp $file

printf "${GREEN}Written to $file${RESET}\n"