예제 #1
0
파일: libsass.py 프로젝트: cecedille1/Sett
 def default(cls):
     return cls(
         ROOT.joinpath(defaults.SASS_SRC_DIR, 'scss'),
         ROOT.joinpath(defaults.SASS_BUILD_DIR),
         cls.get_default_paths(),
         cls.get_default_functions(),
     )
예제 #2
0
    def supervisordconf():
        ctx = DeployContext()

        includes = []

        daemons_conf_dir = ROOT.joinpath('etc/supervisord/daemons/')
        daemons_conf_dir.makedirs_p()

        for daemon in daemons:
            daemon_conf = daemons_conf_dir.joinpath(daemon.name + '.conf')
            includes.append(daemon_conf)

            info('Writing daemon %s', daemon)
            write_config(daemon_conf, {
                'program:{}'.format(daemon.name): {
                    'command': daemon.command,
                    'environment': ','.join('{}="{}"'.format(key, val) for key, val in daemon.environ.items())
                },
            })

        groups_conf_dir = ROOT.joinpath('etc/supervisord/groups/')
        groups_conf_dir.makedirs_p()

        for group in daemons.groups():
            group_conf = groups_conf_dir.joinpath(group.name + '.conf')
            includes.append(group_conf)

            info('Writing group %s', group)
            write_config(group_conf, {
                'group:{}'.format(group.name): {
                    'programs': ','.join(d.name for d in group),
                }
            })

        supervisorctl_conf = ROOT.joinpath('etc/supervisord/supervisorctl.conf')
        write_config(supervisorctl_conf, {
            'supervisorctl': {
                'serverurl': 'unix://' + SOCKET,
            },
        })

        supervisord_conf = ROOT.joinpath(defaults.SUPERVISORDCONF)
        write_config(supervisord_conf, {
            'rpcinterface:supervisor': {
                'supervisor.rpcinterface_factory': 'supervisor.rpcinterface:make_main_rpcinterface',
            },
            'unix_http_server': {
                'file': SOCKET,
                'chown': '{UID}:{GID}'.format(**ctx),
            },
            'supervisord': {
                'logfile': LOGS.joinpath('supervisord.log'),
                'pidfile': PIDFILE,
            },
            'include': {
                'files': ' '.join(includes),
            }
        })
예제 #3
0
파일: libsass.py 프로젝트: cecedille1/Sett
    def get_default_paths(self):
        sp = defaults.SASS_PATH
        if not sp:
            return []
        if isinstance(sp, string_types):
            return sp.split(':')
        if isinstance(sp, collections.Iterable):
            return [ROOT.joinpath(d) for d in sp]

        bc = ROOT.joinpath('bower_components/'),
        if bc.isdir():
            return [bc]
        return []
예제 #4
0
def uglify(args):
    for name in args:
        input = ROOT.joinpath('scripts/js/', name + '.js')
        output = ROOT.joinpath('static/js/', name + '.js')

        sh([
            which.node,
            which.uglifyjs,
            input, '-o', output,
            '--source-map', output + '.map',
            '--source-map-url', name + '.js.map',
            '--compress', '--mangle',
        ])
예제 #5
0
    def get_builds(self, source, args):
        """
        Returns a list of  ``RJSBuild`` instances for the given modules.
        """
        params = dict(self.params)
        params.pop('appdir', None)

        for name in args:
            out = ROOT.joinpath(self.outdir, name + '.js')
            cache = FilesListComparator(out)
            yield self.build_class(name, source, out, params, cache)
예제 #6
0
def supervisord():
    """Wrapper to control supervisord"""
    supervisord_conf = ROOT.joinpath(defaults.SUPERVISORDCONF)
    try:
        return Daemon(
            [which.supervisord, '-c', supervisord_conf],
            daemonize=lambda pidfile: ['--pidfile', pidfile],
            pid_file=PIDFILE,
        )
    except which.NotInstalled:
        return
예제 #7
0
def virtual_static(args):
    """
    Collect the static in the directory given in argument
    """
    tempdir, = args
    args = ['collectstatic', '--verbosity', '0', '--noinput', '--link']

    from django.conf import settings
    from django.test.utils import override_settings, modify_settings

    with override_settings(STATIC_ROOT=tempdir):
        with modify_settings(STATICFILES_DIRS={
            'append': getattr(settings, 'STATICFILES_DIRS_DEV', []),
            'remove': [
                # Remove with and without trailing /
                ROOT.joinpath(defaults.RJS_BUILD_DIR).normpath().parent,
                ROOT.joinpath(defaults.RJS_BUILD_DIR).normpath().parent.joinpath(''),
            ]
        }):
            call_task('django', args=args)
예제 #8
0
파일: deploy.py 프로젝트: cecedille1/Sett
def make_jinja_instance():
    debug('Creating jinja instance')
    location = path(__file__).dirname().joinpath('templates')
    debug('Loading builtin templates from %s', location)
    loader = jinja2.FileSystemLoader(location)  # Built in templates

    if ROOT.joinpath(defaults.DEPLOY_TEMPLATES_DIR):
        location = ROOT.joinpath(defaults.DEPLOY_TEMPLATES_DIR)
        debug('Loading templates from %s', location)
        # Load users or builtin
        loader = jinja2.ChoiceLoader([
            jinja2.FileSystemLoader(location),
            loader,
            jinja2.PrefixLoader({
                'super': loader,
            })
        ])

    jinja = jinja2.Environment(loader=loader)
    jinja.filters['as_bool'] = lambda x: x if x != 'false' else False
    return jinja
예제 #9
0
파일: deploy.py 프로젝트: cecedille1/Sett
def render_template(template, destination_path, context=tuple()):
    """
    Render a jinja2 template into a file
    """
    destination_path = ROOT.joinpath(destination_path)
    destination_path.dirname().makedirs()

    template = _get_template(template)
    rendered = template.render(DeployContext(context))
    info('Writing %s', destination_path)
    with open(destination_path, 'w') as destination:
        destination.write(rendered)
예제 #10
0
파일: npm.py 프로젝트: cecedille1/Sett
def get_root():
    root = ROOT
    while True:
        if root == '/':
            break
        node_modules = root.joinpath('node_modules')
        if node_modules.isdir():
            break
        root = root.parent
    else:
        node_modules = ROOT.joinpath('node_modules')

    debug('Node modules is %s', node_modules)
    return node_modules
예제 #11
0
파일: pip.py 프로젝트: cecedille1/Sett
def pip_req(args):
    """Install a pip package and add it to the requirements.txt"""
    package = args[0]
    call_task("pip_install", [package])

    requirements = ROOT.joinpath(defaults.REQUIREMENTS)
    with open(requirements, "r+") as req_txt:
        for line in req_txt:
            if line.strip() == package:
                info("%s already present in %s", package, requirements)
                break
        else:
            info("Adding %s to %s", package, requirements)
            req_txt.write("{}\n".format(package))
예제 #12
0
파일: build.py 프로젝트: cecedille1/Sett
def link_latest():
    dist = _get_distribution()
    name = dist.get_name()
    prefix = len(dist.get_fullname()) + 1

    for cmd, x, file in dist.dist_files:
        file = path(file)
        ext = file.basename()[prefix:]
        link = ROOT.joinpath('dist/{}-latest.{}'.format(name, ext))

        if link.islink():
            os.unlink(link)

        info('Link %s to %s', link, file.basename())
        file.basename().symlink(link)
예제 #13
0
def rjs(options):
    """Usage: rjs [-f|--force] [-B|--builder builder_class_path]  [-p APP] [-p APP...]
Build a requirejs app.

Rjs will call the virtual_static class (the default implementation is
sett.requirejs.virtual_static). This task should copy or link in the temp dir
given as the first arg all the static files required for the compilation as if
it was the static root.

Rjs requires npm apps requirejs. It will instanciate a builder class from the
class loaded from builder_class_path (sett.requirejs.RJSBuilder by default) and
launch a build either only of the apps given by the -p flag in the command line
or all autodiscovered apps when no -p is given.

The built files will be created in default.RJS_BUILD_DIR (build/static/js).
Default behavior of rjs is to build autonomous files that contains almond and all
their namespace. This behavior can be configured in a new builder class.
"""
    outdir = ROOT.joinpath(defaults.RJS_BUILD_DIR)
    outdir.makedirs()

    rjs_params = dict(defaults.RJS_PARAMS)

    command_params = getattr(options, 'rjs_params', {})
    if not isinstance(command_params, dict):
        command_params = [x.split('=', 1) for x in command_params]
    rjs_params.update(command_params)

    Builder = _cls(options, 'builder', RJSBuilder)
    BuildClass = _cls(options, 'build_class', AlmondRJSBuild)

    debug('Launching %s (%s)', Builder.__name__, BuildClass.__name__)
    buidler = Builder(
        force=options.get('force', False),
        outdir=outdir,
        build_class=BuildClass,
        params=rjs_params,
    )

    with Tempdir() as tempdir:
        call_task('virtual_static', args=[tempdir])
        buidler(tempdir.joinpath('js'), options.get('paths', []))
예제 #14
0
파일: deploy.py 프로젝트: cecedille1/Sett
 def local_service_path(self):
     return self._local_service_path or ROOT.joinpath('etc/systemd.service')
예제 #15
0
파일: pip.py 프로젝트: cecedille1/Sett
def pip_setup():
    """Install the requirements.txt"""
    requirements = ROOT.joinpath(defaults.REQUIREMENTS)
    call_task("pip_install", args=["-r", requirements])
예제 #16
0
파일: compass.py 프로젝트: cecedille1/Sett
def get_compass_dir():
    return ROOT.joinpath(defaults.COMPASS_DIR)
예제 #17
0
파일: pavement.py 프로젝트: cecedille1/Sett
    setup(
        name='sett',
        version=find_version('sett/__init__.py'),
        packages=setuptools.find_packages(
            include=[
                'sett',
                'sett.*',
            ],
            exclude=[
            ]
        ),
        url='https://github.org/cecedille1/sett',
        author=u'Grégoire ROCHER',
        author_email='*****@*****.**',
        install_requires=parse_requirements('requirements.txt'),
        include_package_data=True,
    )


@task
@FileReplacer(ROOT.joinpath('requirements_minimal.txt'), ROOT.joinpath('requirements.txt'))
def make_minimal():
    call_task('sett.build.make')


try:
    with open(ROOT.joinpath('localpavement.py'), 'r') as localpavement:
        exec_(localpavement.read(), locals(), globals())
except (IOError, ImportError) as e:
    pass
예제 #18
0
파일: daemon.py 프로젝트: cecedille1/Sett
 def pid_file(self):
     return self._pid_file or ROOT.joinpath('var/pid/', self.name + '.pid')
예제 #19
0
def supervisorctl(args):
    """Wrapper to launch supervisorctl"""
    sh([
        which.supervisorctl,
        '-c', ROOT.joinpath('etc/supervisord/supervisorctl.conf'),
    ] + args)
예제 #20
0
파일: gem.py 프로젝트: cecedille1/Sett
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import subprocess

from paver.easy import task, consume_args, call_task, debug, sh, might_call, path, info

from sett import defaults, which, ROOT
from sett.bin import DirectorySearcher
from sett.utils import BaseInstalledPackages


gem_home = os.environ.get('GEM_HOME')
if gem_home is None:
    GEM_HOME = ROOT.joinpath(defaults.GEM_HOME)
else:
    GEM_HOME = ROOT.joinpath(gem_home)


class InstalledGems(BaseInstalledPackages):
    def __contains__(self, gem):
        if ':' in gem:
            gem, version = gem.split(':', 1)
        return super(InstalledGems, self).__contains__(gem)

    def evaluate(self):
        if not GEM_HOME.exists():
            return []

        env = dict(os.environ)
예제 #21
0
파일: uwsgi.py 프로젝트: cecedille1/Sett
import sys
from xml.etree import ElementTree as ET

from paver.easy import task, info, path, debug
from paver.deps.six import text_type

from sett import which, ROOT, defaults, optional_import
from sett.daemon import Daemon, daemon_task
from sett.paths import LOGS
from sett.pip import VENV_DIR
from sett.deploy_context import DeployContext


yaml = optional_import('yaml')

UWSGI_PATH = ROOT.joinpath('var')

CONFIG_ROOT = ROOT.joinpath('parts/uwsgi/')


@DeployContext.register_default
def uwsgi_context():
    return {
        'uwsgi': {
            'config': get_uwsgi_output().config_path,
        },
        'ctl': '{} daemon'.format(path(sys.argv[0]).abspath()),
    }


@DeployContext.register_default
예제 #22
0
# -*- coding: utf-8 -*-

import functools

from sett import ROOT, DeployContext, which, defaults
from paver.easy import task, debug, consume_args, sh, info

from sett.daemon import daemon_task, Daemon
from sett.paths import LOGS


SOCKET = ROOT.joinpath('var/run/supervisor.sock')
PIDFILE = ROOT.joinpath('var/run/supervisor.pid')


@task
@consume_args
def supervisorctl(args):
    """Wrapper to launch supervisorctl"""
    sh([
        which.supervisorctl,
        '-c', ROOT.joinpath('etc/supervisord/supervisorctl.conf'),
    ] + args)


@daemon_task
def supervisord():
    """Wrapper to control supervisord"""
    supervisord_conf = ROOT.joinpath(defaults.SUPERVISORDCONF)
    try:
        return Daemon(