Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No curl or tar #116

Merged
merged 2 commits into from
Mar 3, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ For nodeenv

* python (>= 2.6)
* make
* curl
* tail
* tar

For node.js
^^^^^^^^^^^
Expand Down
2 changes: 0 additions & 2 deletions README.ru.rst
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,7 @@ Nodeenv можно установить с помощью `easy_install`_::
^^^^^^^^^^^

* make
* curl
* tail
* tar

Для node.js
^^^^^^^^^^^
Expand Down
77 changes: 38 additions & 39 deletions nodeenv.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
:license: BSD, see LICENSE for more details.
"""

import contextlib
import io
import sys
import os
import re
Expand All @@ -18,6 +20,7 @@
import operator
import optparse
import subprocess
import tarfile
import pipes

try: # pragma: no cover (py2 only)
Expand Down Expand Up @@ -443,33 +446,24 @@ def get_node_src_url(version, postfix=''):
return node_url


@contextlib.contextmanager
def tarfile_open(*args, **kwargs):
"""Compatibility layer because py26."""
tf = tarfile.open(*args, **kwargs)
try:
yield tf
finally:
tf.close()


def download_node(node_url, src_dir, env_dir, opt):
"""
Download source code
"""
cmd = []
cmd.append('curl')
cmd.append('--silent')
cmd.append('-L')
cmd.append(node_url)
cmd.append('|')
cmd.append('tar')
cmd.append('xzf')
cmd.append('-')
cmd.append('-C')
cmd.append(pipes.quote(src_dir))
cmd.extend(['--exclude', 'ChangeLog'])
cmd.extend(['--exclude', 'LICENSE'])
cmd.extend(['--exclude', 'README.md'])
try:
callit(cmd, opt.verbose, True, env_dir)
logger.info(') ', extra=dict(continued=True))
except OSError:
postfix = '-RC1'
logger.info('%s) ' % postfix, extra=dict(continued=True))
new_node_url = get_node_src_url(opt.node, postfix)
cmd[cmd.index(node_url)] = new_node_url
callit(cmd, opt.verbose, True, env_dir)
tar_contents = io.BytesIO(urlopen(node_url).read())
with tarfile_open(fileobj=tar_contents) as tarfile_obj:
tarfile_obj.extractall(src_dir)
logger.info(')', extra=dict(continued=True))


def get_node_src_url_postfix(opt):
Expand Down Expand Up @@ -589,16 +583,27 @@ def install_npm(env_dir, src_dir, opt):
"""
logger.info(' * Install npm.js (%s) ... ' % opt.npm,
extra=dict(continued=True))
cmd = [
'. %s && curl --location --silent %s | '
'clean=%s npm_install=%s bash && deactivate_node' % (
pipes.quote(join(env_dir, 'bin', 'activate')),
'https://www.npmjs.org/install.sh',
'no' if opt.no_npm_clean else 'yes',
opt.npm
)
]
callit(cmd, opt.verbose, True)
npm_contents = urlopen('https://www.npmjs.org/install.sh').read()
env = dict(
os.environ,
clean='no' if opt.no_npm_clean else 'yes',
npm_install=opt.npm,
)
proc = subprocess.Popen(
(
'bash', '-c',
'. {0} && exec bash'.format(
pipes.quote(join(env_dir, 'bin', 'activate')),
)
),
env=env,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
)
out, _ = proc.communicate(npm_contents)
if opt.verbose:
logger.info(out)
logger.info('done.')


Expand Down Expand Up @@ -799,12 +804,6 @@ def main():
Config._dump()
return

for exe in ('curl', 'tar'):
if not is_installed(exe):
print('Error: "%s" not installed.' % exe)
print('Please, install it via apt/yum/etc and try again.')
return sys.exit(1)

opt, args = parse_args(check=False)
Config._load(opt.config_file, opt.verbose)

Expand Down