diff options
author | Alex Xu <alex_y_xu@yahoo.ca> | 2014-04-01 18:37:58 -0400 |
---|---|---|
committer | Alex Xu <alex_y_xu@yahoo.ca> | 2014-04-01 18:37:58 -0400 |
commit | cd5f7ffd5f608e1515b306aabac534490e33be24 (patch) | |
tree | 88ea217f5ab62be7a465f25e7dc472d8faf9e665 | |
parent | cfa401046d2ee1872bfbd16851f010abd837b82e (diff) | |
download | html5ks-cd5f7ffd5f608e1515b306aabac534490e33be24.tar.xz html5ks-cd5f7ffd5f608e1515b306aabac534490e33be24.zip |
configure.py -> configure
-rwxr-xr-x | configure | 146 | ||||
-rwxr-xr-x | configure.py | 77 |
2 files changed, 68 insertions, 155 deletions
@@ -1,87 +1,77 @@ -#!/bin/bash +#!/usr/bin/env python3 -checking() { - printf "checking %s... " "$1" >&2 -} +import os +import re +import shlex +import shutil +import subprocess +from sys import stderr -check() { - checking "for $1" - var="${VAR:-${1^^}}" - cmd="${!var}" - : ${cmd:=${1}} - shift - varflags="${var}FLAGS" - varflags="$@ ${!varflags}" - get=$(command -v "${cmd}") - e=$? - if [[ -n "$get" ]]; then - declare -g "$var=$get" - echo ${get} - if [[ -z "$NO_RUN" ]]; then - checking "${get} usability" - ${get} -h >/dev/null 2>&1 - e=$? - if (( $e )); then - echo unusable, returned $e - return $e - else - echo yes - fi - fi - # intentionally stripping whitespace - echo ${var} := ${get} ${varflags} >> "${OUT}" || exit 1 - else - echo no - fi - return $e -} +cmds = {} -rcheck() { - check "$@" || exit -} +class CheckError(Exception): + pass -fcheck() { - for f in $3; do - checking "for $f $1 support in ffmpeg" - if grep -Eq "^ $2 $f " <<< "$4"; then - echo yes - else - echo no - exit 1 - fi - done -} +def checking(thing): + stderr.write("checking %s... " % thing) + stderr.flush() -echeck() { - checking "for $2" - if [ "$1" "$2" ]; then - echo found - else - echo "$2 is missing; make sure you have $3" >&2 - exit 1 - fi -} +def check(name, flags=[], optional=False, var=None, run=True): + checking("for %s" % name) + var = var or name.upper() + split = shlex.split(os.getenv(var) or name) + exe = shutil.which(split[0]) + if not exe: + stderr.write("not found\n") + if not optional: + raise CheckError() + stderr.write("%s\n" % exe) + cmd = [exe] + split[1:] + flags + shlex.split(os.getenv(var + "FLAGS") or "") + if run: + checking("%s usability" % exe) + try: + subprocess.check_call(cmd + ["-h"], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) + stderr.write("yes\n") + except subprocess.CalledProcessError as e: + raise CheckError() from e -echeck -f ast2json/script-a1-monday.rpyc "copied the rpyc files" -echeck -d www/dump "you have extracted the rpa" + cmds[var] = cmd + return cmd -OUT=Makefile.inc -> "${OUT}" || exit 1 +def run_ffmpeg(arg): + return subprocess.check_output(ffmpeg + [arg], stderr=subprocess.STDOUT).decode('utf-8') -VAR=GZIP check zopfli || rcheck gzip -9 -NO_RUN=1 rcheck apngasm -rcheck convert -rcheck cwebp -quiet -alpha_cleanup -m 6 -rcheck ffmpeg -v warning -y -F=$($FFMPEG -formats 2>&1) -fcheck demuxing "D." "matroska,webm ogg wav yuv4mpegpipe" "$F" -fcheck muxing ".E" "ipod mp4 ogg wav webm yuv4mpegpipe" "$F" -fcheck decoding ".{6}" "mpeg4 rawvideo pcm_s16le vorbis" "$($FFMPEG -decoders 2>&1)" -fcheck encoding ".{6}" "libx264 rawvideo libtheora libvpx libvpx-vp9 libfdk_aac libopus pcm_s16le" "$($FFMPEG -encoders 2>&1)" -rcheck npm --quiet -rcheck webpmux -NO_RUN=1 check defluff -check pngquant -check zopflipng +def ffmpeg_check(name, regex, checks, output): + for check in checks: + checking("if %s supports %s %s" % (ffmpeg[0], name, check)) -exit 0 + if re.search("\n %s %s " % (regex, check), output): + stderr.write("yes\n") + else: + stderr.write("no\n") + raise CheckError() + +try: + check("zopfli", var="GZIP") +except CheckError: + check("gzip", ["-9"]) + +check("apngasm", run=False) +check("convert") +check("cwebp", ["-quiet", "-alpha_cleanup", "-m", "6"]) +ffmpeg = check("ffmpeg", ["-v", "warning", "-y"], run=False) +ffmpeg_formats = run_ffmpeg("-formats") +ffmpeg_check("demuxing", "D.", ["matroska,webm", "ogg", "wav", "yuv4mpegpipe"], ffmpeg_formats) +ffmpeg_check("muxing", ".E", ["ipod", "mp4", "ogg", "wav", "webm", "yuv4mpegpipe"], ffmpeg_formats) +ffmpeg_check("decoding", ".{6}", ["mpeg4", "rawvideo", "pcm_s16le", "vorbis"], run_ffmpeg("-decoders")) +ffmpeg_check("encoding", ".{6}", ["libx264", "rawvideo", "libtheora", "libvpx", "libvpx-vp9", "libfdk_aac", "libopus", "pcm_s16le"], run_ffmpeg("-encoders")) +check("npm", ["--quiet"]) +check("webpmux") +check("defluff", optional=True, run=False) +check("pngquant", optional=True) +check("zopflipng", optional=True) + +stderr.write("creating Makefile.inc\n") + +with open("Makefile.inc", "w") as f: + f.write(''.join('%s := %s\n' % (k, subprocess.list2cmdline(cmds[k])) for k in cmds)) diff --git a/configure.py b/configure.py deleted file mode 100755 index 291ce68..0000000 --- a/configure.py +++ /dev/null @@ -1,77 +0,0 @@ -#!/usr/bin/env python3 - -import os -import re -import shlex -import shutil -import subprocess -from sys import stderr - -cmds = {} - -class CheckError(Exception): - pass - -def checking(thing): - stderr.write("checking %s... " % thing) - stderr.flush() - -def check(name, flags=[], optional=False, var=None, run=True): - checking("for %s" % name) - var = var or name.upper() - split = shlex.split(os.getenv(var) or name) - exe = shutil.which(split[0]) - if not exe: - stderr.write("not found\n") - if not optional: - raise CheckError() - stderr.write("%s\n" % exe) - cmd = [exe] + split[1:] + flags + shlex.split(os.getenv(var + "FLAGS") or "") - if run: - checking("%s usability" % exe) - try: - subprocess.check_call(cmd + ["-h"], stdout=subprocess.DEVNULL, stderr=subprocess.STDOUT) - stderr.write("yes\n") - except subprocess.CalledProcessError as e: - raise CheckError() from e - - cmds[var] = cmd - return cmd - -def run_ffmpeg(arg): - return subprocess.check_output(ffmpeg + [arg], stderr=subprocess.STDOUT).decode('utf-8') - -def ffmpeg_check(name, regex, checks, output): - for check in checks: - checking("if %s supports %s %s" % (ffmpeg[0], name, check)) - - if re.search("\n %s %s " % (regex, check), output): - stderr.write("yes\n") - else: - stderr.write("no\n") - raise CheckError() - -try: - check("zopfli", var="GZIP") -except CheckError: - check("gzip", ["-9"]) - -check("apngasm", run=False) -check("convert") -check("cwebp", ["-quiet", "-alpha_cleanup", "-m", "6"]) -ffmpeg = check("ffmpeg", ["-v", "warning", "-y"], run=False) -ffmpeg_formats = run_ffmpeg("-formats") -ffmpeg_check("demuxing", "D.", ["matroska,webm", "ogg", "wav", "yuv4mpegpipe"], ffmpeg_formats) -ffmpeg_check("muxing", ".E", ["ipod", "mp4", "ogg", "wav", "webm", "yuv4mpegpipe"], ffmpeg_formats) -ffmpeg_check("decoding", ".{6}", ["mpeg4", "rawvideo", "pcm_s16le", "vorbis"], run_ffmpeg("-decoders")) -ffmpeg_check("encoding", ".{6}", ["libx264", "rawvideo", "libtheora", "libvpx", "libvpx-vp9", "libfdk_aac", "libopus", "pcm_s16le"], run_ffmpeg("-encoders")) -check("npm", ["--quiet"]) -check("webpmux") -check("defluff", optional=True, run=False) -check("pngquant", optional=True) -check("zopflipng", optional=True) - -stderr.write("creating Makefile.inc\n") - -with open("Makefile.inc", "w") as f: - f.write(''.join('%s := %s\n' % (k, subprocess.list2cmdline(cmds[k])) for k in cmds)) |