Exemplo n.º 1
0
def devserver_install_flask():
    """
    Install a Flask devserver
    
    The task will look for the template ``rundevserver.py.tpl``, render it and
    write it to ``bin/rundevserver.py``.
    
    To start the Flask development server, run::
    
      (venv)$ rundevserver.py
    
    .. note::
    
       ``rundevserver.py`` only works with Flask based versions of Invenio.
    """
    puts(cyan(">>> Configuring Flask devserver..." % env))

    local_file = 'rundevserver.py.tpl'
    local_remote = os.path.join(env.CFG_INVENIO_PREFIX, 'bin/rundevserver.py')

    puts(">>> Writing rundevserver.py to %s ..." % local_remote)
    try:
        write_template(local_remote, env, tpl_file=local_file)
        local("chmod a+x %s" % local_remote)
    except TemplateNotFound:
        warn(red("Could not find template %s" % local_file))
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
def devserver_install_flask():
    """
    Install a Flask devserver
    
    The task will look for the template ``rundevserver.py.tpl``, render it and
    write it to ``bin/rundevserver.py``.
    
    To start the Flask development server, run::
    
      (venv)$ rundevserver.py
    
    .. note::
    
       ``rundevserver.py`` only works with Flask based versions of Invenio.
    """
    puts(cyan(">>> Configuring Flask devserver..." % env))
    
    local_file = 'rundevserver.py.tpl'
    local_remote = os.path.join(env.CFG_INVENIO_PREFIX, 'bin/rundevserver.py')

    puts(">>> Writing rundevserver.py to %s ..." % local_remote)
    try:
        write_template(local_remote, env, tpl_file=local_file)
        local("chmod a+x %s" % local_remote)
    except TemplateNotFound:
        warn(red("Could not find template %s" % local_file))
Exemplo n.º 4
0
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))
Exemplo n.º 5
0
def apache_conf():
    """ Upload and update Apache configuration """
    puts(cyan(">>> Configuring Apache..." % env))

    conf_files = ['etc/apache/invenio-apache-vhost.conf', 'etc/apache/invenio-apache-vhost-ssl.conf']
    conf_files = [(p, os.path.join(env.CFG_INVENIO_PREFIX, p)) for p in conf_files]

    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, env, 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)
Exemplo n.º 6
0
 def write_template_hook(ctx):
     try:
         write_template(filename % ctx, ctx, tpl_file=tpl_file)
     except TemplateNotFound:
         if warn_only:
             warn(red("Couldn't find template %s" % tpl_file))
         else:
             abort(red("Couldn't find template %s" % tpl_file))
Exemplo n.º 7
0
def sublime_project():
    """ Write sublime project file """
    from fabric.api import env
    from inveniofab.utils import write_template

    prjfile = os.path.join(
        env.CFG_INVENIO_PREFIX,
        '%s.sublime-project' % os.path.basename(env.CFG_INVENIO_PREFIX)
    )
    puts(cyan(">>> Writing Sublime project file to %s..." % prjfile))
    write_template(prjfile, env, tpl_file='sublime-project.tpl')
Exemplo n.º 8
0
def haproxy_conf():
    """ Upload HAProxy conf """
    puts(cyan(">>> Creating and configuring celery init.d script..." % env))

    local = 'haproxy.cfg'
    remote = '/etc/haproxy/haproxy.cfg'

    puts(">>> Writing haproxy.cfg to %s ..." % remote)
    try:
        write_template(remote, env, tpl_file=local, use_sudo=True)
    except TemplateNotFound:
        puts(red("Could not find template %s" % local))
Exemplo n.º 9
0
def celery_initd():
    """ Upload and update celeryd init script """
    puts(cyan(">>> Creating and configuring celery init.d script..." % env))

    local = 'celeryd'
    remote = '/etc/init.d/celeryd'

    puts(">>> Writing celeryd to %s ..." % remote)
    try:
        write_template(remote, env, tpl_file=local, use_sudo=True)
    except TemplateNotFound:
        puts(red("Could not find template %s" % local))

    sudo_local("chmod a+x %s" % remote)
Exemplo n.º 10
0
def mysql_conf_type(conf='', name=''):
    """ Upload and update MySQL configuration """
    puts(cyan(">>> Configuring MySQL (%s)..." % name))

    conf_files = [(conf, '/etc/my.cnf')]

    ctx = {}
    ctx.update(env)

    for local_file, remote_file in conf_files:
        print local_file
        puts(">>> Writing %s ..." % remote_file)

        try:
            write_template(remote_file, ctx, tpl_file=local_file, use_sudo=True)
        except TemplateNotFound:
            abort(red("Could not find template %s" % local_file))

    if confirm(cyan("Reload MySQL daemon?")):
        sudo_local("service mysqld reload")
Exemplo n.º 11
0
def invenio_conf():
    """ Upload and update Invenio configuration """
    puts(cyan(">>> Configuring Invenio..." % env))

    invenio_local = env.get('CFG_INVENIO_CONF', None)
    invenio_local_remote = os.path.join(env.CFG_INVENIO_PREFIX, 'etc/invenio-local.conf')

    if not invenio_local:
        puts(red(">>> CFG_INVENIO_CONF not specified, using built-in template for invenio-local.conf..."))

    puts(">>> Writing invenio-local.conf to %s ..." % invenio_local_remote)
    if not invenio_local:
        write_template(invenio_local_remote, env, tpl_str=INVENIO_LOCAL_TPL, use_sudo=True)
    else:
        try:
            write_template(invenio_local_remote, env, tpl_file=invenio_local, use_sudo=True)
        except TemplateNotFound:
            puts(red("Could not find template %s" % invenio_local))
            if not confirm("Use built-in template for invenio-local.conf?"):
                abort("User aborted")
            else:
                write_template(invenio_local_remote, env, tpl_str=INVENIO_LOCAL_TPL, use_sudo=True)

    if confirm(cyan("Run config update")):
        inveniomanage("config update")
        inveniomanage("bibfield config load")
Exemplo n.º 12
0
def invenio_conf():
    """ Upload and update Invenio configuration """
    puts(cyan(">>> Configuring Invenio..." % env))

    invenio_local = env.get('CFG_INVENIO_CONF', None)
    invenio_local_remote = os.path.join(env.CFG_INVENIO_PREFIX,
                                        'etc/invenio-local.conf')

    if not invenio_local:
        puts(
            red(">>> CFG_INVENIO_CONF not specified, using built-in template for invenio-local.conf..."
                ))

    puts(">>> Writing invenio-local.conf to %s ..." % invenio_local_remote)
    if not invenio_local:
        write_template(invenio_local_remote, env, tpl_str=INVENIO_LOCAL_TPL)
    else:
        try:
            write_template(invenio_local_remote, env, tpl_file=invenio_local)
        except TemplateNotFound:
            puts(red("Could not find template %s" % invenio_local))
            if not confirm("Use built-in template for invenio-local.conf?"):
                abort("User aborted")
            else:
                write_template(invenio_local_remote,
                               env,
                               tpl_str=INVENIO_LOCAL_TPL)

    inveniocfg("--update-all")
Exemplo n.º 13
0
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)
Exemplo n.º 14
0
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))
Exemplo n.º 15
0
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)
Exemplo n.º 16
0
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)
Exemplo n.º 17
0
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)