From: Jaroslav Kysela Date: Wed, 19 Apr 2017 19:58:56 +0000 (+0200) Subject: doozer: replace curl's post operation with user python script X-Git-Tag: v4.2.1~7 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6daabace3c5614b237f43079848a2295ed35acae;p=thirdparty%2Ftvheadend.git doozer: replace curl's post operation with user python script --- diff --git a/.doozer.json b/.doozer.json index ae2bddffe..e0e115966 100644 --- a/.doozer.json +++ b/.doozer.json @@ -19,8 +19,7 @@ "python", "dvb-apps", "debhelper", - "ccache", - "curl" + "ccache" ], "buildcmd": [ "AUTOBUILD_CONFIGURE_EXTRA=--enable-ccache\\ --disable-libx265_static\\ --disable-libx265\\ --enable-hdhomerun_static ./Autobuild.sh -t ${TARGET} -j ${PARALLEL} -w ${WORKDIR}" @@ -44,8 +43,7 @@ "python", "dvb-apps", "debhelper", - "ccache", - "curl" + "ccache" ], "buildcmd": [ "AUTOBUILD_CONFIGURE_EXTRA=--enable-ccache\\ --disable-libx265_static\\ --disable-libx265\\ --enable-hdhomerun_static ./Autobuild.sh -t ${TARGET} -j ${PARALLEL} -w ${WORKDIR}" @@ -69,8 +67,7 @@ "python", "dvb-apps", "debhelper", - "ccache", - "curl" + "ccache" ], "buildcmd": [ "AUTOBUILD_CONFIGURE_EXTRA=--enable-ccache\\ --enable-ffmpeg_static\\ --enable-hdhomerun_static ./Autobuild.sh -t ${TARGET} -j ${PARALLEL} -w ${WORKDIR}" @@ -94,8 +91,7 @@ "python", "dvb-apps", "debhelper", - "ccache", - "curl" + "ccache" ], "buildcmd": [ "AUTOBUILD_CONFIGURE_EXTRA=--enable-ccache\\ --enable-ffmpeg_static\\ --enable-hdhomerun_static ./Autobuild.sh -t ${TARGET} -j ${PARALLEL} -w ${WORKDIR}" @@ -119,8 +115,7 @@ "python", "dvb-apps", "debhelper", - "ccache", - "curl" + "ccache" ], "buildcmd": [ "AUTOBUILD_CONFIGURE_EXTRA=--enable-ccache\\ --enable-ffmpeg_static\\ --enable-hdhomerun_static ./Autobuild.sh -t ${TARGET} -j ${PARALLEL} -w ${WORKDIR}" @@ -133,7 +128,6 @@ "git", "build-essential", "pkg-config", - "gettext", "libavahi-client-dev", "libssl-dev", "zlib1g-dev", @@ -144,8 +138,7 @@ "python", "dvb-apps", "debhelper", - "ccache", - "curl" + "ccache" ], "buildcmd": [ "AUTOBUILD_CONFIGURE_EXTRA=--enable-ccache\\ --enable-ffmpeg_static\\ --enable-hdhomerun_static ./Autobuild.sh -t ${TARGET} -j ${PARALLEL} -w ${WORKDIR}" @@ -169,8 +162,7 @@ "python", "dvb-apps", "debhelper", - "ccache", - "curl" + "ccache" ], "buildcmd": [ "AUTOBUILD_CONFIGURE_EXTRA=--enable-ccache\\ --enable-ffmpeg_static\\ --enable-hdhomerun_static ./Autobuild.sh -t ${TARGET} -j ${PARALLEL} -w ${WORKDIR}" @@ -194,8 +186,7 @@ "python", "dvb-apps", "debhelper", - "ccache", - "curl" + "ccache" ], "buildcmd": [ "AUTOBUILD_CONFIGURE_EXTRA=--enable-ccache\\ --enable-ffmpeg_static\\ --enable-hdhomerun_static ./Autobuild.sh -t ${TARGET} -j ${PARALLEL} -w ${WORKDIR}" @@ -219,8 +210,7 @@ "python", "dvb-apps", "debhelper", - "ccache", - "curl" + "ccache" ], "buildcmd": [ "AUTOBUILD_CONFIGURE_EXTRA=--enable-ccache\\ --enable-hdhomerun_static\\ --disable-ffmpeg_static ./Autobuild.sh -t ${TARGET} -j ${PARALLEL} -w ${WORKDIR}" @@ -244,8 +234,7 @@ "python", "dvb-apps", "debhelper", - "ccache", - "curl" + "ccache" ], "buildcmd": [ "AUTOBUILD_CONFIGURE_EXTRA=--enable-ccache\\ --enable-hdhomerun_static\\ --disable-ffmpeg_static ./Autobuild.sh -t ${TARGET} -j ${PARALLEL} -w ${WORKDIR}" @@ -270,8 +259,7 @@ "bzip2", "uriparser-devel", "python", - "ccache", - "curl" + "ccache" ], "buildcmd": [ "./configure --disable-dvbscan && make -C rpm build-doozer" @@ -296,8 +284,7 @@ "bzip2", "uriparser-devel", "python", - "ccache", - "curl" + "ccache" ], "buildcmd": [ "./configure --disable-dvbscan && make -C rpm build-doozer" diff --git a/support/bintray.py b/support/bintray.py new file mode 100755 index 000000000..89c250c2a --- /dev/null +++ b/support/bintray.py @@ -0,0 +1,91 @@ +#! /usr/bin/env python + +# +# TVH bintray tool, compatible with both python2 and python3 +# + +import os +import sys +import json +import base64 +try: + # Python 3 + import urllib.request as urllib + from urllib.parse import urlencode +except ImportError: + # Python 2 + import urllib2 as urllib + from urllib import urlencode + +def env(key): + if key in os.environ: return os.environ[key] + return None + +BINTRAY_API='https://bintray.com/api/v1' +BINTRAY_USER=env('BINTRAY_USER') +BINTRAY_PASS=env('BINTRAY_PASS') + +class Response(object): + def __init__(self, response): + self.url = response.geturl() + self.code = response.getcode() + self.reason = response.msg + self.body = response.read() + self.headers = response.info() + +class Bintray(object): + + def __init__(self, path, headers=None): + self._headers = headers or {} + self._path = path or [] + a = '%s:%s' % (BINTRAY_USER, BINTRAY_PASS) + self._auth = b'Basic ' + base64.b64encode(a.encode('utf-8')) + + def put(self, data, binary=None): + content_type = 'application/json' + if binary: content_type = 'application/binary' + opener = urllib.build_opener() + path = self._path + if path[0] != '/': path = '/' + path + request = urllib.Request(BINTRAY_API + path, data=data) + request.add_header('Content-Type', content_type) + request.add_header('Authorization', self._auth) + request.get_method = lambda: 'PUT' + try: + r = Response(opener.open(request)) + except urllib.HTTPError as e: + r = Response(e) + return r + +def error(lvl, msg, *args): + sys.stderr.write(msg % args + '\n') + sys.exit(lvl) + +def do_upload(*args): + if len(args) < 2: + error(1, 'upload [url] [file]') + bpath, file = args[0], args[1] + data = open(file, "br").read() + b = Bintray(bpath) + resp = b.put(data, binary=1) + if resp.code != 200 and resp.code != 201: + error(10, 'HTTP ERROR "%s" %s %s' % (resp.url, resp.code, resp.reason)) + +def do_unknown(*args): + r = 'Please, specify a valid command:\n' + for n in globals(): + if n.startswith('do_') and n != 'do_unknown': + r += ' ' + n[3:] + '\n' + error(1, r[:-1]) + +def main(argv): + if not BINTRAY_USER or not BINTRAY_PASS: + error(2, 'No credentals') + cmd = 'do_' + (len(argv) > 1 and argv[1] or 'unknown') + if cmd in globals(): + globals()[cmd](*argv[2:]) + else: + do_unknown() + +if __name__ == "__main__": + main(sys.argv) diff --git a/support/lib.sh b/support/lib.sh index 62928e30e..9d72bbb24 100755 --- a/support/lib.sh +++ b/support/lib.sh @@ -171,16 +171,9 @@ function upload # Upload N=staticlib/${CODENAME}/${ARCH}/${LIB_NAME}-${LIB_HASH}.tgz - URL="https://api.bintray.com/content/${BINTRAY_REPO}/staticlib/${LIB_NAME}-${LIB_HASH}/${N};publish=1" - echo "UPLOAD ${URL}" - curl -s -T ${P}.tmp -u${BINTRAY_USER}:${BINTRAY_PASS} "${URL}" - R=$? - if [ ${R} -ne 0 ]; then - echo " UPLOAD FAILED! RETRYING..." - sleep 10 - curl -s -T ${P}.tmp -u${BINTRAY_USER}:${BINTRAY_PASS} "${URL}" || return 1 - fi - echo + BPATH="/content/${BINTRAY_REPO}/staticlib/${LIB_NAME}-${LIB_HASH}/${N};publish=1" + echo "UPLOAD ${BPATH}" + ${ROOTDIR}/support/bintray.py upload ${BPATH} ${P}.tmp || return 1 # Done mv ${P}.tmp ${P} || return 1