forked from shuup/shuup
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnodejs_verify.py
68 lines (57 loc) · 2.12 KB
/
nodejs_verify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# This file is part of Shuup.
#
# Copyright (c) 2012-2019, Shoop Commerce Ltd. All rights reserved.
#
# This source code is licensed under the OSL-3.0 license found in the
# LICENSE file in the root directory of this source tree.
import subprocess
import sys
PRELUDE = """
Oops! You don't seem to have Node.js installed, or at the very least
it's not called `node`, as we expect it to be.
""".strip()
DEBIAN_ARGH = """
However, you do have a binary called `nodejs` (version %(version)s),
which strongly implies you may be running Debian or a derivative
thereof, where it's necessary to install the `nodejs-legacy` package to
provide a symlink for `/usr/bin/node`.
So, in short, to continue:
Run (or ask your administrator to run) `apt-get install nodejs-legacy`.
""".strip()
NO_NODE_WHATSOEVER = """
You need to install Node.js (version 0.12 or newer) to continue.
Please see
https://github.com/joyent/node/wiki/Installing-Node.js-via-package-manager
for instructions relevant to your system.
""".strip()
NO_NPM = """
We could find Node.js, but NPM, the Node.js Package Manager, is not installed.
This is a strange situation indeed, and we're not quite sure how to resolve it.
However we do need `npm` to continue.
""".strip()
DIVIDER = "\n\n%s\n\n" % ("@" * 80)
def snarf(cmd):
proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
if proc.returncode:
return ""
return stdout.strip().decode("UTF-8", "ignore")
def verify_nodejs():
node_version = snarf("node --version")
if not node_version:
sys.stderr.write(DIVIDER)
sys.stderr.write(PRELUDE)
sys.stderr.write("\n\n")
nodejs_version = snarf("nodejs --version")
if nodejs_version:
sys.stderr.write(DEBIAN_ARGH % {"version": nodejs_version})
else:
sys.stderr.write(NO_NODE_WHATSOEVER)
sys.stderr.write(DIVIDER)
sys.exit(5)
npm_version = snarf("npm --version")
if not npm_version:
sys.stderr.write(DIVIDER)
sys.stderr.write(NO_NPM)
sys.stderr.write(DIVIDER)
sys.exit(6)