def install(self): """Installer""" binaries = self.get_binaries() if 'phantomjs' not in binaries: url = self.options.get('phantomjs-url', None) if not url: version = self.options.get('phantomjs-version', '1.7.0') if sys.platform == 'linux2': url = ('https://phantomjs.googlecode.com/' 'files/phantomjs-%s-linux-i686.tar.bz2') % version elif sys.platform == 'darwin': url = ('https://phantomjs.googlecode.com/' 'files/phantomjs-%s-macosx.zip') % version else: raise RuntimeError('Please specify a phantomjs-url') self.download(url) if 'casperjs' not in binaries: self.download( self.options.get( 'casperjs-url', 'https://github.com/n1k0/casperjs/tarball/1.0.0-RC4')) binaries = self.get_binaries() for f in binaries.values(): os.chmod(f, 0777) self.options['arguments'] = repr(binaries) self.options['eggs'] = 'gp.recipe.phantomjs' self.options['entry-points'] = '\n'.join( ['%s=gp.recipe.phantomjs.script:main' % s for s in binaries]) from zc.recipe.egg import Scripts rscripts = Scripts(self.buildout, self.name, self.options) return rscripts.install()
def install(self): """Installer""" binaries = self.get_binaries() if 'phantomjs' not in binaries: if self.options.get('phantomjs-url', None): url = self.options.get('phantomjs-url') elif self.options.get('phantomjs-url-base', None): url = self._get_url_from_base() else: url = self._get_url_from_template() self.download(url) if 'casperjs' not in binaries: url = self.options.get( 'casperjs-url', 'https://github.com/n1k0/casperjs/tarball/1.0.3') if url: self.download(url) binaries = self.get_binaries() for f in binaries.values(): os.chmod(f, 0o777) if self.relative_paths: self.options['arguments'] = \ self._get_relative_binary_dict(binaries) else: self.options['arguments'] = repr(binaries) self.options['eggs'] = 'gp.recipe.phantomjs' self.options['entry-points'] = '\n'.join( ['%s=gp.recipe.phantomjs.script:main' % s for s in binaries]) from zc.recipe.egg import Scripts rscripts = Scripts(self.buildout, self.name, self.options) return rscripts.install()
def install(self): """Installer""" binaries = self.get_binaries() if 'phantomjs' not in binaries: if self.options.get('phantomjs-url', None): url = self.options.get('phantomjs-url') elif self.options.get('phantomjs-url-base', None): url = self._get_url_from_base() else: url = self._get_url_from_template() self.download(url) if 'casperjs' not in binaries: url = self.options.get( 'casperjs-url', 'https://github.com/n1k0/casperjs/tarball/1.0.3') if url: self.download(url) binaries = self.get_binaries() for f in binaries.values(): os.chmod(f, 0o777) if self.relative_paths: self.options['arguments'] = \ self._get_relative_binary_dict(binaries) else: self.options['arguments'] = repr(binaries) self.options['eggs'] = 'gp.recipe.phantomjs' self.options['entry-points'] = '\n'.join([ '%s=gp.recipe.phantomjs.script:main' % s for s in binaries ]) from zc.recipe.egg import Scripts rscripts = Scripts(self.buildout, self.name, self.options) return rscripts.install()
def write_appcfg_script(self, bin): """Generates the app configuration script in bin.""" options = self.options.copy() options['eggs'] = '' run_file = self.options['appserver-run-file'] options['entry-points'] = 'appcfg=appcfg:%s' % run_file options['arguments'] = '%r, locals()' % bin options = Options(self.buildout, self.name, options) scripts = Scripts(self.buildout, self.name, options) scripts.install()
def install(self): """Installer""" options = self.options path = [p for p in sys.path if 'parts' not in p] del sys.modules['site'] sys.path[:] = path env = os.environ.copy() env['PYTHONPATH'] = ':'.join(path) key = 'tox-install-dir' if key in self.buildout['buildout']: install_dir = self.buildout['buildout'][key] elif key in self.options: install_dir = self.options[key] else: install_dir = join(self.buildout['buildout']['parts-directory'], self.name) bin_bir = join(install_dir, 'bin') tox = join(bin_bir, 'tox') if not os.path.isfile(tox): if sys.version_info[:2] >= (3,4): import venv venv.create(install_dir, with_pip=True) del env['PYTHONPATH'] subprocess.call([join(bin_bir, 'pip'), 'install', 'tox'], env=env) else: import virtualenv subprocess.call([sys.executable, virtualenv.__file__[:-1], '-q', '--distribute', install_dir], env=env) del env['PYTHONPATH'] subprocess.call([join(bin_bir, 'easy_install'), 'tox'], env=env) from zc.recipe.egg import Scripts options['eggs'] = 'virtualenv' options['scripts'] = 'tox' options['entry-points'] = 'tox=os:execve' options['arguments'] = ( '%(tox)r, [%(tox)r] + sys.argv[1:], os.environ' ) % dict(tox=tox) options['initialization'] = '\n'.join([ 'import os', "os.environ['PYTHONPATH'] = ''", ]) script = Scripts(self.buildout, self.name, self.options) script.install() return tuple()
def install(self): """Installer""" binaries = self.get_binaries() if 'phantomjs' not in binaries: url = self.options.get('phantomjs-url', None) if not url: version = self.options.get('phantomjs-version', '1.7.0') if sys.platform.startswith('linux'): arch = 'x86_64' in os.uname() and 'x86_64' or 'i686' url = ( 'https://phantomjs.googlecode.com/' 'files/phantomjs-%s-linux-%s.tar.bz2' ) % (version, arch) elif sys.platform == 'darwin': url = ( 'https://phantomjs.googlecode.com/' 'files/phantomjs-%s-macosx.zip' ) % version elif sys.platform.startswith('win'): url = ( 'https://phantomjs.googlecode.com/' 'files/phantomjs-%s-windows.zip' ) % version else: raise RuntimeError('Please specify a phantomjs-url') self.download(url) if 'casperjs' not in binaries: url = self.options.get( 'casperjs-url', 'https://github.com/n1k0/casperjs/tarball/1.0.0-RC4') if url: self.download(url) binaries = self.get_binaries() for f in binaries.values(): os.chmod(f, 0o777) self.options['arguments'] = repr(binaries) self.options['eggs'] = 'gp.recipe.phantomjs' self.options['entry-points'] = '\n'.join([ '%s=gp.recipe.phantomjs.script:main' % s for s in binaries ]) from zc.recipe.egg import Scripts rscripts = Scripts(self.buildout, self.name, self.options) return rscripts.install()
def __init__(self, buildout, name, options): self.name = name self.options = options options['part_path'] = os.path.join( buildout['buildout']['parts-directory'], name ) options['buildout_path'] = buildout['buildout']['directory'] self.scripts = Scripts(buildout, 'buildout-tox', options)
def write_server_script(self, name, bin): """Generates bin script with given name.""" var = os.path.join(self.buildout['buildout']['parts-directory'], '%s_var' % self.name) if not os.path.isdir(var): os.makedirs(var) script_name = self.get_appserver_script_name().partition('.')[0] options = self.options.copy() options['eggs'] = '' run_file = '_' + self.options['appserver-run-file'] options['entry-points'] = '%s=%s:%s' % (name, script_name, run_file) options['initialization'] = dev_appserver_initialization % dict(var=var, script_name=script_name) options['initialization'] += '\n' + self.options.get('initialization', '') options['arguments'] = '%r, locals()' % bin options = Options(self.buildout, self.name, options) scripts = Scripts(self.buildout, self.name, options) scripts.install()
def write_server_script(self, name, bin): """Generates bin script with given name.""" var = os.path.join(self.buildout['buildout']['parts-directory'], '%s_var' % self.name) if not os.path.isdir(var): os.makedirs(var) script_name = self.get_appserver_script_name().partition('.')[0] options = self.options.copy() options['eggs'] = '' run_file = self.options['appserver-run-file'] options['entry-points'] = '%s=%s:%s' % (name, script_name, run_file) options['initialization'] = dev_appserver_initialization % dict(var=var, script_name=script_name) options['initialization'] += '\n' + self.options.get('initialization', '') options['arguments'] = '%r, locals()' % bin options = Options(self.buildout, self.name, options) scripts = Scripts(self.buildout, self.name, options) scripts.install()
def install(self): """Installer""" binaries = self.get_binaries() if 'phantomjs' not in binaries: url = self.options.get('phantomjs-url', None) if not url: if sys.platform == 'linux2': url = ( 'https://phantomjs.googlecode.com/' 'files/phantomjs-1.7.0-linux-i686.tar.bz2' ) elif sys.platform == 'darwin': url = ( 'https://phantomjs.googlecode.com/' 'files/phantomjs-1.7.0-macosx.zip' ) else: raise RuntimeError('Please specify a phantomjs-url') self.download(url) if 'casperjs' not in binaries: self.download( self.options.get( 'casperjs-url', 'https://github.com/n1k0/casperjs/tarball/1.0.0-RC4' ) ) binaries = self.get_binaries() for f in binaries.values(): os.chmod(f, 0777) self.options['arguments'] = repr(binaries) self.options['eggs'] = 'gp.recipe.phantomjs' self.options['entry-points'] = '\n'.join([ '%s=gp.recipe.phantomjs.script:main' % s for s in binaries ]) from zc.recipe.egg import Scripts rscripts = Scripts(self.buildout, self.name, self.options) return rscripts.install()
class TestRunner(object): """zc.buildout recipe""" def __init__(self, buildout, name, options): self.buildout, self.name, self.options = buildout, name, options self.test_url = self.options.get('url') if not self.test_url: raise KeyError, "You must specify an address to test" default_location = os.path.join(self.buildout['buildout'].get('directory'),'var','funkload','data') default_report_destination = os.path.join(self.buildout['buildout'].get('directory'),'var','funkload','reports') default_record_output = os.path.join(self.buildout['buildout'].get('directory'),'var','funkload','records') self.location = self.options.get('location',default_location) self.report_destination = self.options.get('report_destination',default_report_destination) self.record_output = self.options.get('record_output',default_record_output) self.record_test_name = self.options.get('record_test_name', 'SimpleRecord') self.record_proxy_port = self.options.get('record_proxy_port', 8090) eggs = self.options.get('eggs', 'funkload\ncollective.funkload\ncollective.recipe.funkload' ) required_eggs = ['funkload', 'collective.funkload', 'collective.recipe.funkload'] for egg in required_eggs: if egg not in eggs: eggs = '\n'.join([eggs, egg]) options_funkload = {'eggs': eggs, 'scripts':'funkload', 'arguments':'url="%s",buildout_dir="%s",report_destination="%s",data_destination="%s",record_output="%s",record_test_name="%s",record_proxy_port="%s"' \ % (self.test_url, self.buildout['buildout'].get('directory'), self.report_destination, self.location, self.record_output, self.record_test_name, self.record_proxy_port, )} if 'python' in options: options_funkload.update({'python':options['python']}) self._recipe = Scripts(buildout,name,options_funkload) def install(self): """Installer""" if not os.path.exists(self.location): os.makedirs(self.location) return self._recipe.install()
def install(self): """creates the initial structure for a addon documentation """ # directory structure sourcesdir = os.path.join(self.docsdir, 'source') if not os.path.exists(self.docsdir): os.mkdir(self.docsdir) if not os.path.exists(sourcesdir): os.mkdir(sourcesdir) # create directory 'source/_images' sourceimagedir = os.path.join(self.docsdir, 'source', '_images') if not os.path.exists(sourceimagedir): os.mkdir(sourceimagedir) # create directory '_static_' sourcestaticdir = os.path.join(self.docsdir, 'source', '_static') if not os.path.exists(sourcestaticdir): os.mkdir(sourcestaticdir) # copy templates (conf, rst) for tplname, tplsubdir, override in TPLS: target = os.path.join(self.docsdir, tplsubdir, tplname) if not override and os.path.exists(target): continue with open(os.path.join(TPL_DIR, tplname)) as tpl_file: tpl = tpl_file.read() tpl = self._render(tpl) with open(target, 'w') as target_file: target_file.write(tpl) # install sphinx options = {'eggs': self.eggs + '\nSphinx'} scripts = Scripts(self.buildout, self.name, options) scripts.install() # install script for make docs in bin-directory return []
def write_extra_scripts(self): options = self.options.copy() options['eggs'] = '' options = Options(self.buildout, self.name, options) scripts = Scripts(self.buildout, self.name, options) scripts.install()
class Recipe(object): def __init__(self, buildout, name, options): self.name = name self.options = options options['part_path'] = os.path.join( buildout['buildout']['parts-directory'], name ) options['buildout_path'] = buildout['buildout']['directory'] self.scripts = Scripts(buildout, 'buildout-tox', options) def install(self): tox_path = self.options['part_path'] default_python = sys.executable buildout_path = self.options['buildout_path'] if os.path.exists(tox_path): rmtree(tox_path) os.mkdir(tox_path) self.options.created(tox_path) tox_config = RawConfigParser() tox_config.add_section('tox') # build command build = self.options.get('build') if build: build = os.path.abspath(os.path.join(buildout_path, build)) else: build = 'bin/buildout setup setup.py sdist' tox_config.set('tox', 'build', build) # environments for env in self.options['environments'].split(): env_path = os.path.join(self.options['part_path'], env) os.mkdir(env_path) tox_config.add_section(env) # path tox_config.set(env, 'path', env_path) # python tox_config.set(env, 'python', default_python) # test command tox_config.set(env, 'test', 'bin/test') # bootstrap.py with nested( open(os.path.join(os.path.dirname(__file__), 'bootstrap.py'), 'rb'), open(os.path.join(env_path, 'bootstrap.py'), 'wb') ) as (source, destination): destination.write(source.read()) # build.cfg with file(os.path.join(env_path, 'build.cfg'), 'w') as conf_file: conf_file.write(self.options['config']+'\n') # develop.cfg with file(os.path.join(env_path, 'develop.cfg'), 'w') as conf_file: conf_file.write(""" [buildout] extends = build.cfg develop = ../../.. """) with open(os.path.join(tox_path, 'tox.cfg'), 'w') as outfile: tox_config.write(outfile) # install tox script created = self.scripts.install() self.options.created(*created) return self.options.created() update = install
def install(self): """Installer""" options = self.options parts = self.buildout['buildout']['parts-directory'] name = options['url'].split('/')[-1].replace('.tar.gz', '') node_dir = os.path.join(parts, self.name) if not os.path.isdir(node_dir): os.makedirs(node_dir) node_binary = options.get('binary', os.path.join(parts, name, 'bin', 'node')) node_bin = os.path.dirname(node_binary) if not os.path.isfile(node_binary): from zc.recipe.cmmi import Recipe as Cmmi options['environment'] = 'PYTHONPATH=tools:deps/v8/tools' node = Cmmi(self.buildout, name, options) node.install() options['on_install'] = 'true' options['on_update'] = 'true' if not os.path.isfile(os.path.join(node_bin, 'npm')): p = subprocess.Popen(( 'curl -sk https://npmjs.org/install.sh > install.sh&&' 'PATH=%s:$PATH ' 'clean=yes sh install.sh&&rm install.sh' ) % (node_bin,), shell=True) p.wait() scripts = [script.strip() for script in options['scripts'].split() \ if script.strip()] npms = options.get('npms', '') if npms: npms = ' '.join([npm.strip() for npm in npms.split() \ if npm.strip()]) p = subprocess.Popen(('export HOME=%(node_dir)s;' 'export PATH=%(node_bin)s:$PATH;' 'echo "prefix=$HOME" > $HOME/.npmrc;' '%(node_bin)s/npm install -g %(npms)s' ) % locals(), shell=True) p.wait() for script in scripts: if script in ['node']: continue filename = os.path.join(node_bin, script) if os.path.isfile(filename): fd = open(filename) data = fd.read() fd.close() fd = open(filename, 'w') fd.seek(0) data = data.split('\n') data[0] = '#!%s' % node_binary fd.write('\n'.join(data)) fd.close() if 'node' not in scripts: scripts.append('node') node_path = options.get('node-path', '').split() node_path.insert(0, os.path.join(node_dir, 'lib', 'node_modules')) node_path = ':'.join(node_path) options['initialization'] = \ 'import os;\nos.environ["NODE_PATH"] = %r' % node_path options['eggs'] = 'gp.recipe.node' options['arguments'] = '%r, (%r, %r), sys.argv[0]' % ( node_binary, os.path.join(node_dir, 'bin'), node_bin, ) options['entry-points'] = '\n'.join([ '%s=gp.recipe.node.script:main' % s for s in scripts ]) from zc.recipe.egg import Scripts rscripts = Scripts(self.buildout, self.name, options) return rscripts.install()
def install(self): """Installer""" logger = logging.getLogger(self.name) options = self.options parts = self.buildout['buildout']['parts-directory'] name = 'buildout-node' node_dir = os.path.join(parts, self.name) if not os.path.isdir(node_dir): os.makedirs(node_dir) node_binary = self.get_binary(options) if node_binary is None: args = {} if 'url' not in options: args = dict( v=self.get_version(options), a='x86_64' in os.uname() and 'x64' or 'x86', ) if sys.platform.startswith('linux'): args['p'] = 'linux' elif sys.platform == 'darwin': args['p'] = 'darwin' if 'p' in args: options['url'] = url = self.binary_format.format(**args) logger.info('Using binary distribution at %s', url) from zc.buildout.download import Download from archive import extract # Use the buildout download infrastructure manager = Download(options=self.buildout['buildout']) # The buildout download utility expects us to know whether or # not we have a download cache, which causes fun errors. This # is probably a bug, but this test should be safe regardless. if manager.download_cache: filename = manager.download_cached(url)[0] else: filename = manager.download(url)[0] destination = os.path.join( self.buildout['buildout']['parts-directory'], name) # Finally, extract the archive. The binary distribution urls # are defined in this file, so we can safely assume they're # gzipped tarballs. This prevents an error when downloaded # into a temporary file. extract(filename,destination,ext=".tar.gz") else: if 'url' not in options: options['url'] = url = self.source_format.format(**args) logger.info('Using source distribution at %s', options['url']) import hexagonit.recipe.cmmi options['environment'] = ( 'PYTHONPATH=tools:deps/v8/tools:../../deps/v8/tools' ) node = hexagonit.recipe.cmmi.Recipe(self.buildout, name, options) node.install() node_binary = self.get_binary(options) node_bin = os.path.dirname(node_binary) scripts = options.get('scripts', '').split() scripts = [script.strip() for script in scripts if script.strip()] npms = options.get('npms', '') if npms: npms = ' '.join([npm.strip() for npm in npms.split() if npm.strip()]) p = subprocess.Popen(( 'export HOME=%(node_dir)s;' 'export PATH=%(node_bin)s:$PATH;' 'echo "prefix=$HOME\n" > $HOME/.npmrc;' '%(node_bin)s/npm set color false;' '%(node_bin)s/npm set unicode false;' '%(node_bin)s/npm install -sg %(npms)s') % {'node_dir':shell_quote(node_dir), 'node_bin':shell_quote(node_bin), 'npms':npms}, shell=True) p.wait() for script in scripts: if script in ['node']: continue filename = os.path.join(node_bin, script) if os.path.isfile(filename): fd = open(filename) data = fd.read() fd.close() fd = open(filename, 'w') fd.seek(0) data = data.split('\n') data[0] = '#!%s' % node_binary fd.write('\n'.join(data)) fd.close() for script in ('node', 'npm'): if script not in scripts: scripts.append(script) node_path = options.get('node-path', '').split() node_path.insert(0, os.path.join(node_dir, 'lib', 'node_modules')) node_path = ':'.join(node_path) options['initialization'] = ( 'import os;\nos.environ["NODE_PATH"] = %r' % node_path ) paths = [os.path.join(node_dir, 'bin'), node_bin] all_scripts = [] for p in paths: if os.path.isdir(p): all_scripts.extend(os.listdir(p)) typos = [] for script in scripts: if script not in all_scripts: typos.append(script) if typos: import zc.buildout typos = ', '.join([repr(s) for s in typos]) all_scripts = [repr(s) for s in all_scripts] all_scripts = ', '.join(sorted(all_scripts)) raise zc.buildout.UserError(( 'Script(s) {0} not found in {1[0]};{1[1]}.\n' 'You may have a typo in your buildout config.\n' 'Available scripts are: {2}' ).format(typos, paths, all_scripts)) options['eggs'] = 'gp.recipe.node' options['arguments'] = '%r, (%r, %r), sys.argv[0]' % ( node_binary, os.path.join(node_dir, 'bin'), node_bin, ) options['scripts'] = '\n'.join(scripts) options['entry-points'] = '\n'.join([ '%s=gp.recipe.node.script:main' % s for s in scripts ]) from zc.recipe.egg import Scripts rscripts = Scripts(self.buildout, self.name, options) return rscripts.install()
def install(self): if self.buildout['buildout']['offline'] == 'true': return () return Scripts.install(self)
def install(self): """Installer""" logger = logging.getLogger(self.name) options = self.options parts = self.buildout['buildout']['parts-directory'] name = 'buildout-node' node_dir = os.path.join(parts, self.name) if not os.path.isdir(node_dir): os.makedirs(node_dir) node_binary = self.get_binary(options) if node_binary is None: args = {} if 'url' not in options: args = dict( v=self.get_version(options), a='x86_64' in os.uname() and 'x64' or 'x86', ) if sys.platform.startswith('linux'): args['p'] = 'linux' elif sys.platform == 'darwin': args['p'] = 'darwin' if 'p' in args: options['url'] = url = self.binary_format.format(**args) logger.info('Using binary distribution at %s', url) import hexagonit.recipe.download options['destination'] = os.path.join( self.buildout['buildout']['parts-directory'], name) node = hexagonit.recipe.download.Recipe(self.buildout, name, options) node.install() else: if 'url' not in options: options['url'] = url = self.source_format.format(**args) logger.info('Using source distribution at %s', options['url']) import zc.recipe.cmmi options['environment'] = ( 'PYTHONPATH=tools:deps/v8/tools:../../deps/v8/tools' ) # patch cmmi to set a correct PYTHONPATH system_orig = zc.recipe.cmmi.system def system(c): os.environ['PYTHONPATH'] = ( '{0}/tools:{0}/deps/v8/tools' ).format(os.getcwd()) system_orig(c) zc.recipe.cmmi.system = system node = zc.recipe.cmmi.Recipe(self.buildout, name, options) node.install() # restore cmmi zc.recipe.cmmi.system = system_orig node_binary = self.get_binary(options) node_bin = os.path.dirname(node_binary) scripts = [script.strip() for script in options['scripts'].split() if script.strip()] npms = options.get('npms', '') if npms: npms = ' '.join([npm.strip() for npm in npms.split() if npm.strip()]) p = subprocess.Popen(( 'export HOME=%(node_dir)s;' 'export PATH=%(node_bin)s:$PATH;' 'echo "prefix=$HOME\n" > $HOME/.npmrc;' '%(node_bin)s/npm set color false;' '%(node_bin)s/npm set unicode false;' '%(node_bin)s/npm install -sg %(npms)s') % locals(), shell=True) p.wait() for script in scripts: if script in ['node']: continue filename = os.path.join(node_bin, script) if os.path.isfile(filename): fd = open(filename) data = fd.read() fd.close() fd = open(filename, 'w') fd.seek(0) data = data.split('\n') data[0] = '#!%s' % node_binary fd.write('\n'.join(data)) fd.close() for script in ('node', 'npm'): if script not in scripts: scripts.append(script) node_path = options.get('node-path', '').split() node_path.insert(0, os.path.join(node_dir, 'lib', 'node_modules')) node_path = ':'.join(node_path) options['initialization'] = ( 'import os;\nos.environ["NODE_PATH"] = %r' % node_path ) paths = [os.path.join(node_dir, 'bin'), node_bin] all_scripts = [] for p in paths: all_scripts.extend(os.listdir(p)) typos = [] for script in scripts: if script not in all_scripts: typos.append(script) if typos: import zc.buildout typos = ', '.join([repr(s) for s in typos]) all_scripts = [repr(s) for s in all_scripts] all_scripts = ', '.join(sorted(all_scripts)) raise zc.buildout.UserError(( 'Script(s) {0} not found in {1[0]};{1[1]}.\n' 'You may have a typo in your buildout config.\n' 'Available scripts are: {2}' ).format(typos, paths, all_scripts)) options['eggs'] = 'gp.recipe.node' options['arguments'] = '%r, (%r, %r), sys.argv[0]' % ( node_binary, os.path.join(node_dir, 'bin'), node_bin, ) options['scripts'] = '\n'.join(scripts) options['entry-points'] = '\n'.join([ '%s=gp.recipe.node.script:main' % s for s in scripts ]) from zc.recipe.egg import Scripts rscripts = Scripts(self.buildout, self.name, options) return rscripts.install()
def install_scripts(self): options = self.options node_binary = self.get_binary(options) parts = self.buildout['buildout']['parts-directory'] node_dir = os.path.join(parts, self.name) node_bin = os.path.dirname(node_binary) scripts = options.get('scripts', '').split() scripts = [script.strip() for script in scripts if script.strip()] if not scripts and os.path.isdir(os.path.join(node_dir, 'bin')): scripts = os.listdir(os.path.join(node_dir, 'bin')) for script in scripts: if script in ['node']: continue filename = os.path.join(node_bin, script) if os.path.isfile(filename): fd = open(filename) data = fd.read() fd.close() fd = open(filename, 'w') fd.seek(0) data = data.split('\n') data[0] = '#!%s' % node_binary fd.write('\n'.join(data)) fd.close() for script in ('node', 'npm'): if script not in scripts: scripts.append(script) node_path = options.get('node-path', '').split() node_path.insert(0, os.path.join(node_dir, 'lib', 'node_modules')) node_path = [self._get_path(pth) for pth in node_path] options['initialization'] = INITIALIZE % { 'node_path': ', '.join(node_path), 'node_dir_bin': self._get_path(os.path.join(node_dir, 'bin')), 'node_bin': self._get_path(node_bin), } paths = [os.path.join(node_dir, 'bin'), node_bin] all_scripts = [] for p in paths: if os.path.isdir(p): all_scripts.extend(os.listdir(p)) typos = [] for script in scripts: if script not in all_scripts: typos.append(script) if typos: import zc.buildout typos = ', '.join([repr(s) for s in typos]) all_scripts = [repr(s) for s in all_scripts] all_scripts = ', '.join(sorted(all_scripts)) raise zc.buildout.UserError(( 'Script(s) {0} not found in {1[0]};{1[1]}.\n' 'You may have a typo in your buildout config.\n' 'Available scripts are: {2}' ).format(typos, paths, all_scripts)) options['eggs'] = 'gp.recipe.node' node_dir_bin = os.path.join(node_dir, 'bin') options['arguments'] = '%s, (%s, %s), sys.argv[0]' % ( self._get_path(node_binary), self._get_path(node_dir_bin), self._get_path(node_bin), ) options['scripts'] = '\n'.join(scripts) options['entry-points'] = '\n'.join([ '%s=gp.recipe.node.script:main' % s for s in scripts ]) from zc.recipe.egg import Scripts rscripts = Scripts(self.buildout, self.name, options) return rscripts.install()
def install(self): """Installer""" logger = logging.getLogger(self.name) options = self.options parts = self.buildout["buildout"]["parts-directory"] name = "buildout-node" node_dir = os.path.join(parts, self.name) if not os.path.isdir(node_dir): os.makedirs(node_dir) node_binary = self.get_binary(options) if node_binary is None: args = {} if "url" not in options: args = dict(v=self.get_version(options), a="x86_64" in os.uname() and "x64" or "x86") if sys.platform.startswith("linux"): args["p"] = "linux" elif sys.platform == "darwin": args["p"] = "darwin" if "p" in args: options["url"] = url = self.binary_format.format(**args) logger.info("Using binary distribution at %s", url) import hexagonit.recipe.download options["destination"] = os.path.join(self.buildout["buildout"]["parts-directory"], name) node = hexagonit.recipe.download.Recipe(self.buildout, name, options) node.install() else: if "url" not in options: options["url"] = url = self.source_format.format(**args) logger.info("Using source distribution at %s", options["url"]) import zc.recipe.cmmi options["environment"] = "PYTHONPATH=tools:deps/v8/tools:../../deps/v8/tools" # patch cmmi to set a correct PYTHONPATH system_orig = zc.recipe.cmmi.system def system(c): os.environ["PYTHONPATH"] = ("{0}/tools:{0}/deps/v8/tools").format(os.getcwd()) system_orig(c) zc.recipe.cmmi.system = system node = zc.recipe.cmmi.Recipe(self.buildout, name, options) node.install() # restore cmmi zc.recipe.cmmi.system = system_orig node_binary = self.get_binary(options) node_bin = os.path.dirname(node_binary) scripts = options.get("scripts", "").split() scripts = [script.strip() for script in scripts if script.strip()] npms = options.get("npms", "") if npms: npms = " ".join([npm.strip() for npm in npms.split() if npm.strip()]) p = subprocess.Popen( ( "export HOME=%(node_dir)s;" "export PATH=%(node_bin)s:$PATH;" 'echo "prefix=$HOME\n" > $HOME/.npmrc;' "%(node_bin)s/npm set color false;" "%(node_bin)s/npm set unicode false;" "%(node_bin)s/npm install -sg %(npms)s" ) % locals(), shell=True, ) p.wait() for script in scripts: if script in ["node"]: continue filename = os.path.join(node_bin, script) if os.path.isfile(filename): fd = open(filename) data = fd.read() fd.close() fd = open(filename, "w") fd.seek(0) data = data.split("\n") data[0] = "#!%s" % node_binary fd.write("\n".join(data)) fd.close() for script in ("node", "npm"): if script not in scripts: scripts.append(script) node_path = options.get("node-path", "").split() node_path.insert(0, os.path.join(node_dir, "lib", "node_modules")) node_path = ":".join(node_path) options["initialization"] = 'import os;\nos.environ["NODE_PATH"] = %r' % node_path paths = [os.path.join(node_dir, "bin"), node_bin] all_scripts = [] for p in paths: if os.path.isdir(p): all_scripts.extend(os.listdir(p)) typos = [] for script in scripts: if script not in all_scripts: typos.append(script) if typos: import zc.buildout typos = ", ".join([repr(s) for s in typos]) all_scripts = [repr(s) for s in all_scripts] all_scripts = ", ".join(sorted(all_scripts)) raise zc.buildout.UserError( ( "Script(s) {0} not found in {1[0]};{1[1]}.\n" "You may have a typo in your buildout config.\n" "Available scripts are: {2}" ).format(typos, paths, all_scripts) ) options["eggs"] = "gp.recipe.node" options["arguments"] = "%r, (%r, %r), sys.argv[0]" % (node_binary, os.path.join(node_dir, "bin"), node_bin) options["scripts"] = "\n".join(scripts) options["entry-points"] = "\n".join(["%s=gp.recipe.node.script:main" % s for s in scripts]) from zc.recipe.egg import Scripts rscripts = Scripts(self.buildout, self.name, options) return rscripts.install()