[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[taler-build-common] 13/50: move most of the shell functionality to the
From: |
gnunet |
Subject: |
[taler-build-common] 13/50: move most of the shell functionality to the python script. |
Date: |
Sat, 02 Nov 2019 16:38:32 +0100 |
This is an automated email from the git hooks/post-receive script.
ng0 pushed a commit to branch master
in repository build-common.
commit 5059125bfe5a60aae4e6da79d61d086b4e2e2fce
Author: ng0 <address@hidden>
AuthorDate: Fri Oct 4 15:57:51 2019 +0000
move most of the shell functionality to the python script.
---
configure | 44 +----------------------------------
configure.py | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++++--------
2 files changed, 67 insertions(+), 52 deletions(-)
diff --git a/configure b/configure
index 8f456dd..933d474 100755
--- a/configure
+++ b/configure
@@ -74,52 +74,10 @@ fi
PYTHON=$($python -c 'import sys; print(sys.executable)')
#echo $PYTHON
-if ! existence node; then
- echo 'Error: node executable not found.'
- echo 'If you are using Linux, Ubuntu or Debian, try installing the'
- echo 'node-legacy package or symlink node to nodejs.'
-else
- node_version=$(node --version)
- #echo "Using node ${node_version}"
- if ! node -p 'process.exit(!(/v([0-9]+)/.exec(process.version)[1] >= 4))';
then
- echo 'Your node version is too old, use Node 4.x or newer'
- exit 1
- fi
-fi
-
-if existence yarn; then
- if yarn help 2>&1 | grep "No such file or directory"; then
- echo "ERROR: wrong yarn binary installed, please remove the"
- echo "ERROR: conflicting binary before continuing."
- if existence cmdtest; then
- echo "WARNING: cmdtest is installed, this can lead"
- echo "WARNING: to know issues with yarn."
- fi
- exit 1
- fi
- myyarn="yarn"
-elif existence yarnpkg; then
- myyarn="yarnpkg"
-else
- echo 'ERROR: yarn missing. See https://yarnpkg.com/en/docs/install'
- exit 1
-fi
-
-# for the weird systems and sandboxes, only as a anotice.
-# make will fail anyway.
-if ! existence find; then
- echo "INFO: find(1) is missing"
-fi
-if ! existence xargs; then
- echo "INFO: xargs(1) is missing"
-fi
-if ! existence msgmerge; then
- echo "INFO: msgmerge(1) is missing"
-fi
# Call configure.py, assuming all went well.
# $1 is read by configure.py as the prefix.
# If $1 is empty, the python script checks the
# environment for PREFIX. We might need more
# variables and switches, such as DESTDIR.
-$PYTHON ./configure.py --yarn=$myyarn $@
+$PYTHON ./configure.py $@
diff --git a/configure.py b/configure.py
index 212bd57..8fc6e04 100644
--- a/configure.py
+++ b/configure.py
@@ -22,6 +22,9 @@ import argparse
import os
import sys
import logging
+from distutils.spawn import find_executable
+import subprocess
+from subprocess import Popen
# This script so far generates config.mk.
# The only value it produces is prefix,
@@ -32,6 +35,56 @@ import logging
# TODO: Also respect DESTDIR ($PREFIX/$DESTDIR/rest).
+def _existence(name):
+ return find_executable(name) is not None
+
+
+def _tool_version(name):
+ return subprocess.getstatusoutput(name)[1]
+
+
+def _tool_node():
+ if _existence('node') is None:
+ sys.exit('Error: node executable not found.\nIf you are using Linux,
Ubuntu or Debian, try installing the\nnode-legacy package or symlink node to
nodejs.')
+ else:
+ if subprocess.getstatusoutput("node -p
'process.exit(!(/v([0-9]+)/.exec(process.version)[1] >= 4))'")[1] is '':
+ # and exit(1) here?
+ sys.exit('Your node version is too old, use Node 4.x or newer')
+ else:
+ node_version = _tool_version("node --version")
+ return f"Using Node version {node_version}"
+
+
+def _tool_yarn():
+ if _existence('yarn'):
+ p1 = Popen(['yarn', 'help'], stderr=subprocess.STDOUT,
stdout=subprocess.PIPE)
+ p2 = Popen(['grep', 'No such file or directory'], stdin=p1.stdout,
stdout=subprocess.PIPE)
+ p1.stdout.close() # Allow p1 to receive a SIGPIPE if p2 exits
+ output = p2.communicate()[0]
+ if output is b'':
+ if _existence('cmdtest'):
+ print('WARNING: cmdtest is installed, this can lead\nto know
issues with yarn.')
+ sys.exit('ERROR: wrong yarn binary installed, please remove
the\nconflicting binary before continuing.')
+ return 'yarn'
+ elif _existence('yarnpkg'):
+ return 'yarnpkg'
+ else:
+ sys.exit('ERROR: yarn missing. See
https://yarnpkg.com/en/docs/install\n')
+
+
+def _tool_posix():
+ tool_find = _existence('find')
+ if tool_find is None:
+ msg_find = 'prerequiste find(1) not found.'
+ tool_xargs = _existence('xargs')
+ if tool_xargs is None:
+ msg_xargs = 'prerequiste xargs(1) not found.'
+ tool_msgmerge = _existence('msgmerge')
+ if tool_msgmerge is None:
+ msg_msgmerge = 'prerequiste msgmerge(1) not found.'
+ return [msg_find, msg_xargs, msg_msgmerge]
+
+
def _read_prefix():
logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger(__name__)
@@ -40,16 +93,14 @@ def _read_prefix():
if 'DEBUG' in os.environ:
logger.debug('PREFIX from argv')
parser = argparse.ArgumentParser()
- parser.add_argument("-p",
- "--prefix",
+ parser.add_argument('-p',
+ '--prefix',
type=str,
- default="/usr/local",
- # required=True,
+ default='/usr/local',
help='Directory prefix for installation')
- parser.add_argument("-y",
- "--yarn",
+ parser.add_argument('-y',
+ '--yarn',
type=str,
- required=True,
help='name of yarn executable')
if 'DEBUG' in os.environ:
logger.debug('parser.parse_args step')
@@ -66,14 +117,16 @@ def _read_prefix():
myprefix = p_myprefix
else:
myprefix = args.prefix
- yarnexe = args.yarn
+ if args.yarn is not None:
+ yarnexe = args.yarn
+ else:
+ yarnexe = str(_tool_yarn())
if 'DEBUG' in os.environ:
logger.debug('%s', repr(myprefix))
if args.prefix and os.path.isdir(myprefix) is True:
return [myprefix, yarnexe];
def main():
- # mylist = str(_read_prefix())
mylist = _read_prefix()
myprefix = mylist[0]
yarnexe = mylist[1]
@@ -82,6 +135,10 @@ def main():
f'prefix={myprefix}\n',
f'yarnexe={yarnexe}\n'])
f.close()
+ _tool_node()
+ posixlist = _tool_posix()
+ for x in range(len(posixlist)):
+ print(posixlist[x] + "\n")
main()
--
To stop receiving notification emails like this one, please contact
address@hidden.
- [taler-build-common] 16/50: output, (continued)
- [taler-build-common] 16/50: output, gnunet, 2019/11/02
- [taler-build-common] 09/50: should print debug, gnunet, 2019/11/02
- [taler-build-common] 19/50: fix prefix., gnunet, 2019/11/02
- [taler-build-common] 14/50: fix node version check., gnunet, 2019/11/02
- [taler-build-common] 15/50: fix reference before assignment, gnunet, 2019/11/02
- [taler-build-common] 17/50: print, gnunet, 2019/11/02
- [taler-build-common] 12/50: actually make it f-strings., gnunet, 2019/11/02
- [taler-build-common] 18/50: attempt to fix argparse, gnunet, 2019/11/02
- [taler-build-common] 21/50: prefix, gnunet, 2019/11/02
- [taler-build-common] 07/50: env DEBUG shows log statements., gnunet, 2019/11/02
- [taler-build-common] 13/50: move most of the shell functionality to the python script.,
gnunet <=
- [taler-build-common] 20/50: debug logs., gnunet, 2019/11/02
- [taler-build-common] 23/50: fix conditions, gnunet, 2019/11/02
- [taler-build-common] 24/50: fix output, gnunet, 2019/11/02
- [taler-build-common] 30/50: babel not bable, gnunet, 2019/11/02
- [taler-build-common] 22/50: maybe fix, gnunet, 2019/11/02
- [taler-build-common] 31/50: remove Makefile, gnunet, 2019/11/02
- [taler-build-common] 26/50: Merge branch 'master' of git.taler.net:taler-build-scripts, gnunet, 2019/11/02
- [taler-build-common] 34/50: template should not be executable, gnunet, 2019/11/02
- [taler-build-common] 36/50: allow configure.py to be simpler, gnunet, 2019/11/02
- [taler-build-common] 29/50: drop old imports, gnunet, 2019/11/02