def venv_requirements(): """ Install Python packages The task will install Python packages defined in PIP requirements file. """ requirements = [] for repo, info in env.CFG_INVENIO_REPOS: requirements.extend([(repo, x) for x in info.get('requirements', [])]) if not requirements: puts(cyan(">>> No requirements defined...")) return puts(cyan(">>> Installing requirements..." % env)) pyver = python_version() for repo, reqfile in requirements: reqfile = reqfile % env reqpath = os.path.join(env.CFG_INVENIO_PREFIX, "%s_%s" % (repo, os.path.basename(reqfile))) ctx = {'reqpath': reqpath, 'reqfile': reqfile, 'pyver': pyver} ctx.update(env) puts(">>> Writing requirements to %(reqpath)s ..." % ctx) write_template(reqpath, ctx, tpl_file=reqfile) puts(">>> Installing requirements from %(reqpath)s ..." % ctx) cmds = [env.ACTIVATE] if env.WITH_VIRTUALENV else [] cmds.append("pip install -r %(reqpath)s") local(" && ".join(cmds) % ctx)
def devserver_conf(): """ Render and update invenio-devserver configuration The task will look for the template ``config_local.py.tpl``, and render and write it to ``config_local.py`` in the virtual environments site-packages. The invenio-devserver install two commands: * ``serve`` - Invenio development server based on Werkzeug. * ``mailserve`` - Debug mail server which will print all emails to the console. .. note:: The invenio-devserver works with the non-Flask based versions of Invenio. Also, the invenio-devserver is only installed if ``env.WITH_DEVSERVER`` is ``True``. .. seealso:: See also invenio-devserver for further information on the content of ``config_local.py.tpl``: https://bitbucket.org/osso/invenio-devserver """ puts(cyan(">>> Configuring invenio-devserver..." % env)) pyver = python_version() local_file = 'config_local.py.tpl' local_remote = os.path.join(env.CFG_INVENIO_PREFIX, 'lib/python%s/site-packages/config_local.py' % pyver) puts(">>> Writing config_local.py to %s ..." % local_remote) try: write_template(local_remote, env, tpl_file=local_file) except TemplateNotFound: warn(red("Could not find template %s" % local_file))
def venv_pyuno_install(): """ Install Python OpenOffice binding The task will try to locate ``uno.py`` and ``unohelper.py`` in ``/usr/``, and copy it to your virtualenv's site-packages. .. warning:: The Python OpenOffice bindings from your system is specific to your system's Python interpreter, hence if your system Python is 2.7 and you are installing the bindings into virtualenv with Python 2.4, the bindings will not work. """ pyver = python_version() ctx = {'pyver': pyver} ctx.update(env) sudo_local("cp `find /usr/ -name uno.py 2>/dev/null | head -n 1` %(CFG_INVENIO_PREFIX)s/lib/python%(pyver)s/site-packages/" % ctx, user=env.CFG_INVENIO_USER) sudo_local("cp `find /usr/ -name unohelper.py 2>/dev/null | head -n 1` %(CFG_INVENIO_PREFIX)s/lib/python%(pyver)s/site-packages/" % ctx, user=env.CFG_INVENIO_USER)
def venv_requirements(): """ Install Python packages The task will install Python packages defined in PIP requirements file. """ requirements = [] for repo, info in env.CFG_INVENIO_REPOS: requirements.extend([(repo, x) for x in info.get('requirements', [])]) if not requirements: puts(cyan(">>> No requirements defined...")) return puts(cyan(">>> Installing requirements..." % env)) pyver = python_version() reqpaths = [] for repo, reqfile in requirements: reqfile = reqfile % env reqpath = os.path.join(env.CFG_INVENIO_PREFIX, "%s_%s" % (repo, os.path.basename(reqfile))) ctx = {'reqpath': reqpath, 'reqfile': reqfile, 'pyver': pyver} ctx.update(env) puts(">>> Writing requirements to %(reqpath)s ..." % ctx) write_template(reqpath, ctx, remote_tpl_file=reqfile, use_sudo=True) reqpaths.append(reqpath) for reqpath in reqpaths: puts(">>> Installing requirements from %(reqpath)s ..." % ctx) ctx = {'reqpath': reqpath, 'pyver': pyver} ctx.update(env) cmds = [env.ACTIVATE] if env.WITH_VIRTUALENV else [] cmds.append("pip install -r %(reqpath)s") sudo_local(" && ".join(cmds) % ctx, user=env.CFG_INVENIO_USER)
def devserver_conf(): """ Render and update invenio-devserver configuration The task will look for the template ``config_local.py.tpl``, and render and write it to ``config_local.py`` in the virtual environments site-packages. The invenio-devserver install two commands: * ``serve`` - Invenio development server based on Werkzeug. * ``mailserve`` - Debug mail server which will print all emails to the console. .. note:: The invenio-devserver works with the non-Flask based versions of Invenio. Also, the invenio-devserver is only installed if ``env.WITH_DEVSERVER`` is ``True``. .. seealso:: See also invenio-devserver for further information on the content of ``config_local.py.tpl``: https://bitbucket.org/osso/invenio-devserver """ puts(cyan(">>> Configuring invenio-devserver..." % env)) pyver = python_version() local_file = 'config_local.py.tpl' local_remote = os.path.join( env.CFG_INVENIO_PREFIX, 'lib/python%s/site-packages/config_local.py' % pyver) puts(">>> Writing config_local.py to %s ..." % local_remote) try: write_template(local_remote, env, tpl_file=local_file) except TemplateNotFound: warn(red("Could not find template %s" % local_file))
def _apache_conf(files, with_python=True): puts(cyan(">>> Configuring Apache..." % env)) conf_files = files conf_files = [(p, os.path.join(env.CFG_INVENIO_PREFIX, p)) for p in conf_files] if with_python: pyver = python_version() ctx = {'PYVER': pyver} else: ctx = {} ctx.update(env) for local_file, remote_file in conf_files: puts(">>> Writing %s ..." % remote_file) try: if not exists_local(os.path.dirname(remote_file)): sudo_local("mkdir -p %s" % os.path.dirname(remote_file), user=env.CFG_INVENIO_USER) write_template(remote_file, ctx, tpl_file=local_file, use_sudo=True) except TemplateNotFound: abort(red("Could not find template %s" % local_file)) apache_conf = env.get('CFG_APACHE_CONF', '/etc/httpd/conf/httpd.conf') if confirm("Include created files in %s?" % apache_conf): if exists_local(apache_conf, use_sudo=True): lines = ["Include %s" % r for (l, r) in conf_files] if is_local(): with settings(host_string="localhost"): append(apache_conf, lines, use_sudo=True) else: append(apache_conf, lines, use_sudo=True) else: warn(red("File %s does not exists" % apache_conf)) sudo_local("%(CFG_INVENIO_APACHECTL)s configtest" % env)
def venv_pyuno_install(): """ Install Python OpenOffice binding The tassk will try to locate ``uno.py`` and ``unohelper.py`` in ``/usr/``, and copy it to your virtualenv's site-packages. .. warning:: The Python OpenOffice bindings from your system is specific to your system's Python interpreter, hence if your system Python is 2.7 and you are installing the bindings into virtualenv with Python 2.4, the bindings will not work. """ pyver = python_version() ctx = {'pyver': pyver} ctx.update(env) local( "cp `find /usr/ -name uno.py 2>/dev/null | head -n 1` %(CFG_INVENIO_PREFIX)s/lib/python%(pyver)s/site-packages/" % ctx) local( "cp `find /usr/ -name unohelper.py 2>/dev/null | head -n 1` %(CFG_INVENIO_PREFIX)s/lib/python%(pyver)s/site-packages/" % ctx)
def venv_create(): """ Create virtualenv environment The virtualenv is created in ``env.CFG_INVENIO_PREFIX``, and will also create ``lib/python/invenio/`` and symlink it the virtualenv's site-packages, as well as ``var/tmp/ooffice-tmp-files`` (via sudo). If ``env.WITH_DEVSCRIPTS`` is ``True``, invenio-devscripts will be installed. If ``env.WITH_WORKDIR`` is ``True`` git-new-workdir will be installed. Lastly, it will append render the template ``activate-profile.tpl`` and append it to ``bin/activate``. The script will setup common needed environment variables that e.g. invenio-devscripts depend on. If an existing environment already exists, the user will be asked for confirmation to remove the directory (using sudo, due to the directory ``var/tmp/ooffice-tmp-files`` which is created using sudo). """ # Checks if 'CFG_INVENIO_PREFIX' not in env: abort(red("CFG_INVENIO_PREFIX is not specified in env.") % env) puts(cyan(">>> Creating virtualenv in %(CFG_INVENIO_PREFIX)s..." % env)) # Remove previous installation if exists_local(env.CFG_INVENIO_PREFIX): res = confirm("Remove installation in %(CFG_INVENIO_PREFIX)s ?" % env) if not res: abort(red("Cannot continue") % env) else: sudo_local("rm -Rf %(CFG_INVENIO_PREFIX)s" % env) # Create virtual environment dirname = os.path.dirname(env.CFG_INVENIO_PREFIX) basename = os.path.basename(env.CFG_INVENIO_PREFIX) sudo_local("mkdir -p %s" % dirname, user=env.CFG_INVENIO_USER) sudo_local("cd %s && virtualenv -p %s %s" % (dirname, env.PYTHON, basename), user=env.CFG_INVENIO_USER) # Create needed symboic links pyver = python_version() sudo_local("mkdir -p %(CFG_INVENIO_PREFIX)s/lib/python/invenio" % env, user=env.CFG_INVENIO_USER) sudo_local(("mkdir -p %(CFG_INVENIO_PREFIX)s/lib/python" + pyver + "/site-packages") % env, user=env.CFG_INVENIO_USER) sudo_local(("ln -s %(CFG_INVENIO_PREFIX)s/lib/python/invenio %(CFG_INVENIO_PREFIX)s/lib/python" + pyver + "/site-packages/invenio") % env, user=env.CFG_INVENIO_USER) # Write extras into the activate script write_template(os.path.join(env.CFG_INVENIO_PREFIX, 'bin/activate'), env, tpl_file='activate-profile.tpl', append=True, mark="ACTIVATE_PROFILE", use_sudo=True) # Install devscripts if env.WITH_DEVSCRIPTS: puts(">>> Installing invenio-devscripts...") sudo_local("cd %(CFG_INVENIO_PREFIX)s && git clone https://github.com/tiborsimko/invenio-devscripts.git" % env, user=env.CFG_INVENIO_USER) sudo_local("cd %(CFG_INVENIO_PREFIX)s && mv invenio-devscripts/* bin/" % env, user=env.CFG_INVENIO_USER) if env.WITH_WORKDIR: puts(">>> Installing git-new-workdir...") sudo_local('wget -O %(CFG_INVENIO_PREFIX)s/bin/git-new-workdir "http://repo.or.cz/w/git.git/blob_plain/HEAD:/contrib/workdir/git-new-workdir"' % env, user=env.CFG_INVENIO_USER) sudo_local("chmod +x %(CFG_INVENIO_PREFIX)s/bin/git-new-workdir" % env, user=env.CFG_INVENIO_USER) # OpenOffice temporary directory sudo_local("mkdir -p %(CFG_INVENIO_PREFIX)s/var/tmp/ooffice-tmp-files" % env, user=env.CFG_INVENIO_USER) sudo_local("sudo chown -R nobody %(CFG_INVENIO_PREFIX)s/var/tmp/ooffice-tmp-files" % env) sudo_local("sudo chmod -R 755 %(CFG_INVENIO_PREFIX)s/var/tmp/ooffice-tmp-files" % env)
def venv_create(): """ Create virtualenv environment The virtualenv is created in ``env.CFG_INVENIO_PREFIX``, and will also create ``lib/python/invenio/`` and symlink it the virtualenv's site-packages, as well as ``var/tmp/ooffice-tmp-files`` (via sudo). If ``env.WITH_DEVSCRIPTS`` is ``True``, invenio-devscripts will be installed. If ``env.WITH_WORKDIR`` is ``True`` git-new-workdir will be installed. Lastly, it will append render the template ``activate-profile.tpl`` and append it to ``bin/activate``. The script will setup common needed environment variables that e.g. invenio-devscripts depend on. If an existing environment already exists, the user will be asked for confirmation to remove the directory (using sudo, due to the directory ``var/tmp/ooffice-tmp-files`` which is created using sudo). """ # Checks if 'CFG_INVENIO_PREFIX' not in env: abort(red("CFG_INVENIO_PREFIX is not specified in env.") % env) puts(cyan(">>> Creating virtualenv in %(CFG_INVENIO_PREFIX)s..." % env)) # Remove previous installation if os.path.exists(env.CFG_INVENIO_PREFIX): res = confirm("Remove installation in %(CFG_INVENIO_PREFIX)s ?" % env) if not res: abort(red("Cannot continue") % env) else: local("sudo rm -Rf %(CFG_INVENIO_PREFIX)s" % env) # Create virtual environment dirname = os.path.dirname(env.CFG_INVENIO_PREFIX) basename = os.path.basename(env.CFG_INVENIO_PREFIX) local("mkdir -p %s" % dirname) local("cd %s && virtualenv -p %s %s" % (dirname, env.PYTHON, basename)) # Create needed symboic links pyver = python_version() local("mkdir -p %(CFG_INVENIO_PREFIX)s/lib/python/invenio" % env) local(("mkdir -p %(CFG_INVENIO_PREFIX)s/lib/python" + pyver + "/site-packages") % env) local(( "ln -s %(CFG_INVENIO_PREFIX)s/lib/python/invenio %(CFG_INVENIO_PREFIX)s/lib/python" + pyver + "/site-packages/invenio") % env) # Write extras into the activate script write_template(os.path.join(env.CFG_INVENIO_PREFIX, 'bin/activate'), env, tpl_file='activate-profile.tpl', append=True, mark="ACTIVATE_PROFILE") # Install devscripts if env.WITH_DEVSCRIPTS: puts(">>> Installing invenio-devscripts...") local( "cd %(CFG_INVENIO_PREFIX)s && git clone https://github.com/tiborsimko/invenio-devscripts.git" % env) local("cd %(CFG_INVENIO_PREFIX)s && mv invenio-devscripts/* bin/" % env) if env.WITH_WORKDIR: puts(">>> Installing git-new-workdir...") local( 'wget -O %(CFG_INVENIO_PREFIX)s/bin/git-new-workdir "http://repo.or.cz/w/git.git/blob_plain/HEAD:/contrib/workdir/git-new-workdir"' % env) local("chmod +x %(CFG_INVENIO_PREFIX)s/bin/git-new-workdir" % env) # OpenOffice temporary directory local("mkdir -p %(CFG_INVENIO_PREFIX)s/var/tmp/ooffice-tmp-files" % env) local( "sudo chown -R nobody %(CFG_INVENIO_PREFIX)s/var/tmp/ooffice-tmp-files" % env) local( "sudo chmod -R 755 %(CFG_INVENIO_PREFIX)s/var/tmp/ooffice-tmp-files" % env)