]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
doozer: replace curl's post operation with user python script
authorJaroslav Kysela <perex@perex.cz>
Wed, 19 Apr 2017 19:58:56 +0000 (21:58 +0200)
committerJaroslav Kysela <perex@perex.cz>
Wed, 19 Apr 2017 19:58:56 +0000 (21:58 +0200)
.doozer.json
support/bintray.py [new file with mode: 0755]
support/lib.sh

index ae2bddffe714278ea2b30f56d7920107ccf9c29d..e0e115966ce4e4b8852f2ab3b2e2c66ef4483565 100644 (file)
@@ -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}"
         "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}"
         "git",
         "build-essential",
         "pkg-config",
-        "gettext",
         "libavahi-client-dev",
         "libssl-dev",
         "zlib1g-dev",
         "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}"
         "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}"
         "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}"
         "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}"
         "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}"
         "bzip2",
         "uriparser-devel",
         "python",
-        "ccache",
-        "curl"
+        "ccache"
       ],
       "buildcmd": [
         "./configure --disable-dvbscan && make -C rpm build-doozer"
         "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 (executable)
index 0000000..89c250c
--- /dev/null
@@ -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)
index 62928e30e9c4ae3070a865da02ed86701b664b68..9d72bbb244d5a3e1a2e4acd63208da7e82ad56f8 100755 (executable)
@@ -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