# -*- coding: utf-8 -*-
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2019 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENSE.TXT
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
import os
import re
from clselect.clselectexcept import ClSelectExcept
class Interpreter(object):
def __init__(self, prefix, versions_info=None):
"""
:param prefix: mandatory prefix for nodejs root
:param versions_info: optional precomputed dict with handy info
about versions
"""
if versions_info is None:
from clselect.clselectnodejs import scan_node_versions
versions_info = scan_node_versions()
self.prefix = prefix
# Guess two things at once:
self.is_venv = self._guess_version_by_prefix()
# Our NodeJS interpreters is always in usr/bin on both CL6/CL7, but
# this code is also called for virtual environments that use
# different path
if self.is_venv:
folder_ = 'bin'
else:
folder_ = 'usr/bin'
self.binary = os.path.join(self.prefix, folder_, 'node')
if not os.path.isfile(self.binary):
raise ClSelectExcept.InterpreterError(
'Cannot find node binary: %s' % self.binary)
self.version_full = versions_info[self.version]['full_version']
def _guess_version_by_prefix(self):
# Example prefixes:
# /opt/alt/alt-nodejs6/root
# /home/