]> TLD Linux GIT Repositories - tld-builder.git/blobdiff - client/make-request.sh
- show full time and date in HTML queue, drop filtering by requester
[tld-builder.git] / client / make-request.sh
index aebc5dd2736e13127ae0181e3f49ca075b4e8980..06e3445cba934b297c435ac715a9bfb697597d8e 100755 (executable)
@@ -21,11 +21,11 @@ pkgrevision=no
 requester_override=
 relup=no
 
-if [ -x /usr/bin/python ]; then
+if [ -x /usr/bin/python3 ]; then
        send_mode="python"
 else
-       echo "No python present, using mail mode"
-       send_mode="mail"
+       echo "No python3 present, aborting"
+       exit 1
 fi
 
 if [ -n "$HOME_ETC" ]; then
@@ -42,10 +42,9 @@ requester=deviloper@tld-linux.org
 default_key=deviloper@tld-linux.org
 send_mode="$send_mode"
 url="$url"
-mailer="/usr/lib/sendmail -t"
 gpg_opts=""
 dist=ti
-url="https://src.tld-linux.org:1241/"
+url="https://giant.tld-linux.org:1241/"
 
 # defaults:
 f_upgrade=yes
@@ -63,7 +62,6 @@ fi
 
 # internal options, not to be overriden
 specs=
-df_fetch=no
 upgrade_macros=no
 upgrade_scripts=no
 cr=$(printf "\r")
@@ -85,24 +83,16 @@ die() {
 }
 
 send_request() {
-       # switch to mail mode, if no url set
-       [ -z "$url" ] && send_mode="mail"
-
        if [ -n "$wait" ]; then
                msg "Waiting $wait seconds before sending request"
                sleep $wait
                msg "Wait has ended, proceeding!"
        fi
 
-       case "$send_mode" in
-       "mail")
-               msg "Sending using mail mode"
-               cat - | $mailer
-               ;;
-       *)
-               msg "Sending using HTTP mode to $url"
-               cat - | python -c '
-import sys, socket, urllib2, ssl
+       msg "Sending using HTTP mode to $url"
+       cat - | python3 -c '
+import sys, socket, ssl
+from urllib import request
 
 try:
     _create_unverified_https_context = ssl._create_unverified_context
@@ -112,69 +102,23 @@ else:
     ssl._create_default_https_context = _create_unverified_https_context
 
 try:
-        data = sys.stdin.read()
+        data = sys.stdin.read().encode("utf-8")
         url = sys.argv[1]
         socket.setdefaulttimeout(30)
-        req = urllib2.Request(url, data)
-        f = urllib2.urlopen(req)
+        req = request.Request(url, data=data)
+        f = request.urlopen(req)
         f.close()
-except Exception, e:
-        print >> sys.stderr, "Problem while sending request via HTTP: %s: %s" % (url, e)
+except Exception as e:
+        print("Problem while sending request via HTTP: %s: %s" % (url, e), file=sys.stderr)
         sys.exit(1)
-print >> sys.stdout, "Request queued via HTTP."
+print("Request queued via HTTP.", file=sys.stdout)
 ' "$url"
-               ;;
-       esac
 }
 
 # htmlspecialchars: escape <, > and &
 hsc() {
        local input=$1
-       echo -E "$input" | sed -e 's,&,\&amp;,g;s,<,\&lt;,g;s,>,\&gt;,g'
-}
-
-# simple df_fetcher, based on packages/fetchsrc_request
-# TODO: tcp (smtp) mode
-# TODO: adjust for ~/.requestrc config
-df_fetch() {
-       local specs="$@"
-
-       # Sending by
-       local MAILER='/usr/lib/sendmail'
-       # MAILER='/usr/bin/msmtp'
-       # Sending via
-       local VIA="SENDMAIL"
-       #VIA="localhost"
-       local VIA_ARGS=""
-       #VIA_ARGS="some additional flags"
-       # e.g. for msmtp:
-       # VIA_ARGS='-a gmail'
-       #
-       # DISTFILES EMAIL
-       local DMAIL="df@tld-linux.org"
-
-       local HOST=$(hostname -f)
-       local LOGIN=${requester%@*}
-
-       local SPEC BRANCH
-       for spec in $specs; do
-               SPEC=$(echo "$spec" | sed -e 's|:.*||')
-               SPEC=${SPEC%.spec}
-               BRANCH=$(echo "$spec" | sed -e 's|.*:||')
-               echo >&2 "Distfiles Request: $SPEC:$BRANCH via $MAILER ${VIA_ARGS:+ ($VIA_ARGS)}"
-               cat <<-EOF | "$MAILER" -t -i $VIA_ARGS
-                       To: $DMAIL
-                       From: $LOGIN <$LOGIN@$HOST>
-                       Subject: fetchsrc_request notify
-                       X-distfiles-request: yes
-                       X-Login: $LOGIN
-                       X-Package: $SPEC
-                       X-Branch: $BRANCH
-                       X-Flags: force-reply
-
-                       .
-                       EOF
-       done
+       printf "%s\n" "$input" | sed -e 's,&,\&amp;,g;s,<,\&lt;,g;s,>,\&gt;,g'
 }
 
 # get package revision for specs
@@ -490,10 +434,6 @@ while [ $# -gt 0 ]; do
                        upgrade_scripts='yes'
                        ;;
 
-               -df | --distfiles-fetch | --distfiles-fetch-request)
-                       df_fetch=yes
-                       ;;
-
                --gpg-opts | -g)
                        gpg_opts="$2"
                        shift
@@ -521,15 +461,13 @@ done
 
 case "$dist" in
 ti)
-       builder_email="builderti@src.tld-linux.org"
        default_builders="ti-*"
-       url="https://src.tld-linux.org:1241/"
+       url="https://giant.tld-linux.org:1241/"
        control_url="http://src.tld-linux.org/~builderti"
        ;;
 ti-dev)
-       builder_email="buildertidev@src.tld-linux.org"
        default_builders="ti-dev-*"
-       url="https://src.tld-linux.org:1242/"
+       url="https://giant.tld-linux.org:1242/"
        control_url="http://src.tld-linux.org/~buildertidev"
        ;;
 *)
@@ -539,36 +477,36 @@ esac
 
 # need to do this after dist selection
 if [ "$skip" ]; then
-       skip=$(skip="$skip" control_url="$control_url" python -c '
-import urllib2
+       skip=$(skip="$skip" control_url="$control_url" python3 -c '
 import sys
-import StringIO
 import gzip
 import re
 import os
 import string
+from urllib import request
+from io import BytesIO
 from xml.dom import minidom
 
 skip = os.environ.get("skip").split(",");
 control_url = os.environ.get("control_url")
 
-print >> sys.stderr, "* Check queue_id-s against %s" % control_url
+print("* Check queue_id-s against %s" % control_url, file=sys.stderr)
 
 try:
        headers = { "Cache-Control": "no-cache", "Pragma": "no-cache" }
-       req = urllib2.Request(url=control_url + "/queue.gz", headers=headers)
-       f = urllib2.urlopen(req)
-except Exception, e:
-       print >> sys.stderr, "Fetch error %s: %s" % (control_url + "/queue.gz", e)
+       req = request.Request(url=control_url + "/queue.gz", headers=headers)
+       f = request.urlopen(req)
+except Exception as e:
+       print("Fetch error %s: %s" % (control_url + "/queue.gz", e), file=sys.stderr)
        sys.exit(1)
 
-sio = StringIO.StringIO()
+sio = BytesIO()
 sio.write(f.read())
 f.close()
 sio.seek(0)
 f = gzip.GzipFile(fileobj = sio)
 
-xml = re.compile("(<queue>.*?</queue>)", re.DOTALL).match(f.read()).group(1)
+xml = re.compile("(<queue>.*?</queue>)", re.DOTALL).match(f.read().decode("utf-8")).group(1)
 d = minidom.parseString(xml)
 
 q = []
@@ -580,13 +518,13 @@ for c in d.documentElement.childNodes:
 err = 0
 for s in skip:
        if s not in q:
-               print >> sys.stderr, "- Check %s: ERROR: Not valid queue-id" % s
+               print("- Check %s: ERROR: Not valid queue-id" % s, file=sys.stderr)
                err = 1
        else:
-               print >> sys.stderr, "- Check %s: OK" % s
+               print("- Check %s: OK" % s, file=sys.stderr)
 if err == 1:
        sys.exit(1)
-print string.join(skip, ",")
+print(",".join(skip))
 ') || exit $?
        f_upgrade=no
        build_mode=test
@@ -624,11 +562,6 @@ if [ "$pkgrevision" = "yes" ]; then
        specs=$(get_pkgrevision $specs)
 fi
 
-if [ "$df_fetch" = "yes" ]; then
-       df_fetch $specs
-       exit 0
-fi
-
 if [ "$upgrade_macros" = "yes" ]; then
        command="poldek --up; poldek -uv rpm-build-macros"
        builders="$dist-src"
@@ -689,11 +622,7 @@ gen_req() {
                msg "Using jobs $jobs"
                echo "  <maxjobs>$jobs</maxjobs>"
        fi
-       if [ -z "$url" ]; then
-               msg "Using email $builder_email"
-       else
-               msg "Using URL $url"
-       fi
+       msg "Using URL $url"
 
        if [ "$build_mode" = "ready" ]; then
                msg "Build mode: $(tput setaf 2)$build_mode$c_norm"
@@ -720,7 +649,7 @@ gen_req() {
 
        if [ "$command" ]; then
                bid=$(uuidgen)
-               echo -E >&2 "* Command: $command"
+               printf "%s\n" "* Command: $command" >&2
                echo "  <batch id='$bid' depends-on=''>"
                echo "           <command flags='$command_flags'>"
                hsc "$command"
@@ -787,7 +716,7 @@ gen_req() {
                if [ "$no_depend" = yes ]; then
                        depend=
                fi
-               echo -E >&2 "* Post-Command: $post_command"
+               printf "%s\n" "* Post-Command: $post_command" >&2
                echo "  <batch id='$bid' depends-on='$depend'>"
                echo "           <command flags='$command_flags'>"
                hsc "$post_command"