Commit f42ff621 authored by Thomas Leymonerie's avatar Thomas Leymonerie

slapos/recipe: Create slapos.recipe.egg to extend zc.recipe.egg and create a...

slapos/recipe: Create slapos.recipe.egg to extend zc.recipe.egg and create a script to activate virtual env
parent 3833123f
from setuptools import setup, find_packages
version = '0.54'
version = '0.54+tleymone1'
name = 'slapos.recipe.build'
long_description = open("README.rst").read() + "\n" + \
open("CHANGELOG.rst").read() + "\n"
......@@ -24,6 +24,7 @@ setup(name=name,
install_requires=[
'setuptools', # namespaces
'zc.buildout', # plays with buildout
'zc.recipe.egg', # for slapos.recipe.egg (inheriting)
],
extras_require={
'test' : ['zope.testing'],
......@@ -36,6 +37,7 @@ setup(name=name,
'default = slapos.recipe.build:Script',
'download = slapos.recipe.download:Recipe',
'download-unpacked = slapos.recipe.downloadunpacked:Recipe',
'egg = slapos.recipe.egg:Recipe',
'gitclone = slapos.recipe.gitclone:Recipe',
'npm = slapos.recipe.npm:Npm',
'vm.install-debian = slapos.recipe.vm:InstallDebianRecipe',
......
from zc.buildout.easy_install import working_set
from zc.recipe.egg import Egg
import subprocess
import os
import errno
class Recipe(Egg):
def __init__(self, buildout, name, options):
super(Recipe, self).__init__(buildout, name, options)
self.options = options
self.buildout_section = buildout['buildout']
self.eggs_dir = self.buildout_section['eggs-directory']
self.develop_eggs_dir = self.buildout_section['develop-eggs-directory']
self.eggs = tuple(
egg.strip()
for egg in self.options['eggs'].splitlines()
if egg.strip()
)
def install(self):
super(Recipe, self).install()
self.eggs_set = working_set(
self.eggs,
[self.develop_eggs_dir, self.eggs_dir]
)
python_path = ":".join(tuple(dist.location for dist in self.eggs_set))
self.options['pythonpath'] = python_path
dst = os.path.abspath(self.options['script-path'])
self.makedirs(dst)
file = self.options['script-path']+"/env-script"
with open(file, "w") as f:
#f.write("#!/bin/sh\nexport PATH="+ self.buildout_section['bin-directory'] +":$PATH\nexport PYTHONPATH="+ python_path +":$PYTHONPATH")
f.write("#!/bin/sh\n")
f.write("alias deactivate=\'export PATH=\"$_OLD_VIRTUAL_PATH\" && unset _OLD_VIRTUAL_PATH && export PYTHONPATH=\"$_OLD_VIRTUAL_PYTHON_PATH\" && unset _OLD_VIRTUAL_PYTHON_PATH && export PS1=\"\\s-\\v\\$ \" && unalias deactivate\'\n")
f.write("export VIRTUAL_ENV="+self.buildout_section['bin-directory']+"\n_OLD_VIRTUAL_PATH=\"$PATH\"\nexport PATH=\"$VIRTUAL_ENV:$PATH\"\n")
f.write("export VIRTUAL_PYTHON_PATH="+python_path+"\n_OLD_VIRTUAL_PYTHON_PATH=\"$PYTHONPATH\"\nexport PYTHONPATH=\"$VIRTUAL_PYTHON_PATH:$PYTHONPATH\"\n")
f.write("export PS1=\"("+ self.eggs[0]+") $PS1\"\n")
print("/\/\/\ "+file+" /\/\/\ ")
def makedirs(self, path):
try:
os.makedirs(path)
except OSError as e:
if e.errno != errno.EEXIST:
raise
update = install
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment