Ejemplo n.º 1
0
    def run(self):
        base_extract_messages.run(self)

        srcdir = get_path([DOCDIR, 'rst'])
        outdir = get_path([DOCDIR, 'rst', 'i18n', 'pot'])
        doctreedir = get_path([DOCDIR, 'doctrees'])
        buildername = 'gettext'

        app = Sphinx(srcdir=srcdir,
                     confdir=srcdir,
                     outdir=outdir,
                     doctreedir=doctreedir,
                     buildername=buildername,
                     confoverrides=None,
                     status=sys.stdout,
                     warning=sys.stderr,
                     freshenv=True,
                     warningiserror=False,
                     tags=None)

        try:
            app.build(force_all=True)
        except Exception as e:
            print e

        try:
            shutil.rmtree(doctreedir)
        except Exception as e:
            print e
Ejemplo n.º 2
0
def get_package_data(path=None, packages=None, data_files=None,
                     exclude_packages=None, exclude_files=None):
    """
    For a list of packages, find the package_data

    This function scans the subdirectories of a package and considers all
    non-submodule subdirectories as resources, including them in
    the package_data

    Returns a dictionary suitable for setup(package_data=<result>)
    """
    assert path is not None
    assert packages is not None
    assert data_files is not None
    path = os.path.normpath(path)
    package_data = {}
    for package in packages:
        package_data[package] = []
        for f in find_files(path=get_path([path, package_to_path(package)]), pattern='*.*'):
            package_data[package].append(f)
            for e in exclude_packages + ['ez_setup', 'distribute_setup']:
                if fnmatch.fnmatch(f, get_path([path, package_to_path(e), '*'])) \
                   and f in package_data[package]:
                    package_data[package].remove(f)
            for x in exclude_files + ['*.py']:
                if fnmatch.fnmatch(f, get_path([path, x])) \
                   and f in package_data[package]:
                    package_data[package].remove(f)
        package_data[package] = list(
            set(package_data[package]) - set(flatten_list(list(zip(*data_files)[1]))))
        for i, j in enumerate(package_data[package]):
            package_data[package][i] = package_data[package][i].replace(path + os.sep + package_to_path(package) + os.sep, '')
    return package_data
Ejemplo n.º 3
0
    def run(self):
        log.debug("[%s.%s] Compressing JS." %
                  (__name__, self.__class__.__name__))

        JSFULL_DIR = get_path(
            [BASEDIR, 'tribus', 'data', 'static', 'js', 'full'])
        JSMIN_DIR = get_path(
            [BASEDIR, 'tribus', 'data', 'static', 'js', 'min'])

        try:
            os.makedirs(JSMIN_DIR)
        except Exception as e:
            print e

        for JS_FILE in find_files(path=JSFULL_DIR, pattern='*.js'):

            JSMIN_FILE = get_path([JSMIN_DIR, os.path.basename(JS_FILE)])

            try:

                with open(JSMIN_FILE, 'w') as _file:
                    _file.write(slimit.minify(open(JS_FILE).read()))
                    _file.close()

            except Exception as e:
                print e

            log.debug("[%s.%s] %s > %s." %
                      (__name__, self.__class__.__name__, JS_FILE, JSMIN_FILE))
Ejemplo n.º 4
0
    def run(self):
        log.debug("[%s.%s] Compressing CSS." %
                  (__name__, self.__class__.__name__))

        CSSFULL_DIR = get_path(
            [BASEDIR, 'tribus', 'data', 'static', 'css', 'full'])
        CSSMIN_DIR = get_path(
            [BASEDIR, 'tribus', 'data', 'static', 'css', 'min'])

        try:
            os.makedirs(CSSMIN_DIR)
        except Exception as e:
            print e

        for CSS_FILE in find_files(path=CSSFULL_DIR, pattern='*.css'):

            CSSMIN_FILE = get_path([CSSMIN_DIR, os.path.basename(CSS_FILE)])

            try:

                with open(CSSMIN_FILE, 'w') as _file:
                    _file.write(cssmin.cssmin(open(CSS_FILE).read()))
                    _file.close()

            except Exception as e:
                print e

            log.debug(
                "[%s.%s] %s > %s." %
                (__name__, self.__class__.__name__, CSS_FILE, CSSMIN_FILE))
Ejemplo n.º 5
0
    def setUp(self):
        from tribus.common.utils import get_path
        from tribus.common.iosync import makedirs, touch, ln, rmtree

        self.tmpdir = get_path(['/', 'tmp', 'test_io'])
        self.tmpdir_1 = get_path([self.tmpdir, '1'])
        self.tmpdir_2 = get_path([self.tmpdir, '2'])
        self.tmpfile_1 = get_path([self.tmpdir_1, '1.txt'])
        self.tmpfile_2 = get_path([self.tmpdir_2, '2.txt'])
        self.tmpfile_3 = get_path([self.tmpdir_2, '3.log'])
        self.tmpfile_4 = get_path([self.tmpdir_2, '4.txt'])
        self.tmpfile_5 = get_path([self.tmpdir, '5.log'])
        self.tmpfile_6 = get_path([self.tmpdir, '6.py'])

        if os.path.isdir(self.tmpdir):
            rmtree(self.tmpdir)

        makedirs(self.tmpdir_1)
        makedirs(self.tmpdir_2)
        touch(self.tmpfile_1)
        touch(self.tmpfile_2)
        touch(self.tmpfile_3)
        touch(self.tmpfile_5)
        touch(self.tmpfile_6)
        ln(self.tmpfile_3, self.tmpfile_4)
Ejemplo n.º 6
0
 def run(self):
     log.debug("[%s.%s] Compiling manual from RST sources." %
               (__name__, self.__class__.__name__))
     pub = Publisher(writer=manpage.Writer())
     pub.set_components(reader_name='standalone',
                        parser_name='restructuredtext',
                        writer_name='pseudoxml')
     pub.publish(argv=[
         u'%s' % get_path([DOCDIR, 'man', 'tribus.rst']),
         u'%s' % get_path([DOCDIR, 'man', 'tribus.1'])
     ])
Ejemplo n.º 7
0
 def run(self):
     for sphnxdir in [
             get_path([DOCDIR, 'html']),
             get_path([DOCDIR, 'doctrees'])
     ]:
         if os.path.isdir(sphnxdir):
             try:
                 shutil.rmtree(sphnxdir)
                 log.debug("[%s.%s] Removing \"%s\"." %
                           (__name__, self.__class__.__name__, sphnxdir))
             except Exception as e:
                 print e
Ejemplo n.º 8
0
    def test_update_paragraph(self):

        from tribus.common.recorder import update_paragraph
        from tribus.config.pkgrecorder import PACKAGE_FIELDS, DETAIL_FIELDS

        old_paragraph = deb822.Packages(open(get_path([SMPLDIR, 'Blender'])))
        new_paragraph = deb822.Packages(open(get_path([SMPLDIR,
                                                       'BlenderNew'])))

        Package.objects.create_auto(old_paragraph, test_dist, 'main')
        update_paragraph(new_paragraph, test_dist, 'main')

        p = Package.objects.get(Name='blender')
        d = Details.objects.get(package=p)
        name, mail = email.Utils.parseaddr(new_paragraph.get('Maintainer'))
        total_relations = 0
        total_labels = 0

        self.assertEqual(p.Maintainer.Name, name)
        self.assertEqual(p.Maintainer.Email, mail)
        self.assertEqual(d.Distribution, test_dist)

        tag_list = new_paragraph['Tag'].replace('\n', '').split(', ')
        clean_list = [tuple(tag.split('::')) for tag in tag_list]

        for label in p.Labels.all():
            total_labels += 1
            self.assertIn((label.Name, label.Tags.Value), clean_list)

        self.assertEqual(total_labels, len(clean_list))

        for field, field_db in PACKAGE_FIELDS.items():
            if new_paragraph.get(field):
                self.assertEqual(str(getattr(p, field_db)),
                                 new_paragraph[field])

        for field, field_db in DETAIL_FIELDS.items():
            if new_paragraph.get(field):
                self.assertEqual(str(getattr(d, field_db)),
                                 new_paragraph[field])

        for _, relations in new_paragraph.relations.items():
            if relations:
                for relation in relations:
                    if len(relation) > 1:
                        for _ in relation:
                            total_relations += 1
                    else:
                        total_relations += 1

        self.assertEqual(d.Relations.all().count(), total_relations)
Ejemplo n.º 9
0
 def get_sphinx_locale_list(self):
     return set(
         filter(
             None,
             list_items(path=get_path([DOCDIR, 'rst', 'i18n']),
                        dirs=True,
                        files=False))) - set(['pot'])
Ejemplo n.º 10
0
def docker_create_service_cluster():
    """
    Crea un cluster de consul para un servicio.

    .. versionadded:: 0.2
    """

    env.port = 22
    env.target_img = "consul:test"
    env.build_dockerfile = get_path([BASEDIR, 'tribus', 'data', 'consul'])

    with hide('warnings', 'stderr', 'running'):
        # Deben agregarse algunas verificaciones previas
        # por ejemplo, debe existir la imagen base para los
        # nodos, de lo contrario debe crearse

        # - Necesito asignar un nombre a la imagen
        # - Necesito especificar de donde se construye la imagen

        # Para no ralentizar mas el desarrollo, generare la imagen a partir
        # de un Dockerfile a pesar de que pueden existir otras tecnicas
        # mas eficientes para generar las imagenes.

        bimage = sudo(
            '%(docker)s build -t %(target_img)s %(build_dockerfile)s' % env)
Ejemplo n.º 11
0
 def run(self):
     man_file = get_path([DOCDIR, 'man', 'tribus.1'])
     if os.path.isfile(man_file):
         try:
             os.unlink(man_file)
             log.debug("[%s.%s] Removing \"%s\"." %
                       (__name__, self.__class__.__name__, man_file))
         except Exception as e:
             print e
Ejemplo n.º 12
0
    def run(self):
        base_update_catalog.run(self)

        for potfile in self.get_sphinx_pot_list():
            self.domain = os.path.splitext(os.path.basename(potfile))[0]
            self.input_file = potfile
            self.output_dir = get_path([DOCDIR, 'rst', 'i18n'])
            base_update_catalog.finalize_options(self)
            base_update_catalog.run(self)
Ejemplo n.º 13
0
 def run(self):
     for dist_dir in ['dist', 'build', 'Tribus.egg-info']:
         dist_subdir = get_path([BASEDIR, dist_dir])
         if os.path.isdir(dist_subdir):
             try:
                 shutil.rmtree(dist_subdir)
                 log.debug("[%s.%s] Removing \"%s\"." %
                           (__name__, self.__class__.__name__, dist_subdir))
             except Exception as e:
                 print e
Ejemplo n.º 14
0
    def run(self):
        base_compile_catalog.run(self)

        for potfile in self.get_sphinx_pot_list():
            base_compile_catalog.initialize_options(self)
            self.domain = os.path.splitext(os.path.basename(potfile))[0]
            self.directory = get_path([DOCDIR, 'rst',
                                       'i18n']).replace(BASEDIR + os.sep, '')
            self.use_fuzzy = True
            base_compile_catalog.run(self)
Ejemplo n.º 15
0
    def get_object_list(self, bundle):

        if hasattr(bundle.request, 'GET'):
            charm_name = bundle.request.GET.get('name', None)

        CHARM = CharmDirectory(get_path([CHARMSDIR, charm_name]))

        return [CharmObject({
            'config': CHARM.config._data,
        })]
Ejemplo n.º 16
0
 def run(self):
     html_dir = get_path([DOCDIR, 'html'])
     if os.path.isdir(html_dir):
         try:
             shutil.rmtree(html_dir)
             log.debug(
                 "[%s.%s] Removing \"%s\"." %
                 (__name__, self.__class__.__name__, html_dir))
         except Exception as e:
             print e
Ejemplo n.º 17
0
 def flake8_report(self):
     """
     Outputs flake8 report.
     """
     log.info("\n\nFlake8 Report:")
     base = get_path([BASEDIR, 'tribus'])
     pys = find_files(path=base, pattern='*.py')
     flake8_style = get_style_guide()
     report = flake8_style.check_files(pys)
     exit_code = print_report(report, flake8_style)
Ejemplo n.º 18
0
    def run(self):
        for locale in self.get_locale_list():
            self.locale = locale
            self.domain = 'django'
            self.output_dir = get_path([BASEDIR, 'tribus', 'data', 'i18n'])
            self.input_file = get_path(
                [BASEDIR, 'tribus', 'data', 'i18n', 'pot', 'django.pot'])
            self.output_file = None
            base_init_catalog.finalize_options(self)
            base_init_catalog.run(self)

            for potfile in self.get_sphinx_pot_list():
                self.locale = locale
                self.domain = os.path.splitext(os.path.basename(potfile))[0]
                self.output_dir = get_path([DOCDIR, 'rst', 'i18n'])
                self.input_file = potfile
                self.output_file = None
                base_init_catalog.finalize_options(self)
                base_init_catalog.run(self)
Ejemplo n.º 19
0
    def run(self):

        CSSMIN_DIR = get_path(
            [BASEDIR, 'tribus', 'data', 'static', 'css', 'min'])

        if os.path.isdir(CSSMIN_DIR):
            try:
                shutil.rmtree(CSSMIN_DIR)
                log.debug("[%s.%s] Removing \"%s\"." %
                          (__name__, self.__class__.__name__, CSSMIN_DIR))
            except Exception as e:
                print e
Ejemplo n.º 20
0
def get_data_files(path=None, patterns=None, exclude_files=None):
    """

    Procesess a list of patterns to get a list of files that should be put in
    a directory. This function helps the Tribus Maintainer to define a list of
    files to be installed in a certain system directory.

    For example, generated documentation (everything under
    ``tribus/data/docs/html`` after executing ``make build_sphinx``) should be
    put in ``/usr/share/doc/tribus/``. The maintainer should add a pattern like
    the following so that everything from ``tribus/data/docs/html`` gets copied
    to ``/usr/share/doc/tribus/`` when the package is installed
    (``python setup.py install``) or a binary distribution is created
    (``python setup.py bdist``).

    :param path: the path where the files reside. Generally the top level
                 directory of the project. Patterns will be expanded in
                 this directory.
    :param patterns: this is a list of strings in the form of::

                         ['relative/path/inside/project *.some.*regex* /dest',
                          'another/path/inside/project *.foo.*regex* /dest2',
                          'path/ *.* dest/']

                     which means, *Put every file from this folder matching the
                     regex inside this other folder*.

    :param exclude_files: this is a list of file patterns to exclude from the
                          results.
    :return: a list of pairs ``('directory', [file-list])`` ready for use
             in ``setup(data_files=...)`` from Setuptools/Distutils.
    :rtype: ``list``

    .. versionadded:: 0.1

    """
    assert path is not None
    assert patterns is not None
    path = os.path.normpath(path)
    d = []
    for l in patterns:
        src, rgx, dest = l.split()
        for subdir in find_dirs(path=get_path([path, src])):
            f = []
            for files in list_files(path=subdir):
                f.append(files)
                for exclude in exclude_files:
                    if fnmatch.fnmatch(files, exclude) and files in f:
                        f.remove(files)
            d.append((dest + subdir.replace(os.path.join(path, src), ''), f))
    return d
Ejemplo n.º 21
0
    def pep257_report(self):
        """
        Outputs flake8 report.
        """
        log.info("\n\nPEP257 Report:")
        base = get_path([BASEDIR, 'tribus'])
        pys = find_files(path=base, pattern='*.py')
        report = pep257.check_files(pys)

        if len(report) > 0:
            for r in report:
                log.info(r)
        else:
            log.info("\nNo errors found!")
Ejemplo n.º 22
0
    def get_object_list(self, bundle):

        if hasattr(bundle.request, 'GET'):
            charm_name = bundle.request.GET.get('name', None)

        SERVICE = RecipeDir(get_path([SERVICEDIR, charm_name]))
        
        return [ServiceObject({
                    'name': SERVICE.metadata.name,
                    'summary': SERVICE.metadata.summary,
                    'maintainer': SERVICE.metadata.maintainer,
                    'description': SERVICE.metadata.description,
                    'components' : SERVICE.metadata.components.items()
                })]
Ejemplo n.º 23
0
    def get_object_list(self, bundle):

        if hasattr(bundle.request, 'GET'):
            charm_name = bundle.request.GET.get('name', None)

        CHARM = CharmDirectory(get_path([CHARMSDIR, charm_name]))

        config = {}

        for k, v in CHARM.config._data.iteritems():
            default = v.get('default', None)
            if default:
                config[k] = default

        return [CharmObject({'config': config})]
Ejemplo n.º 24
0
    def get_object_list(self, bundle):

        if hasattr(bundle.request, 'GET'):
            charm_name = bundle.request.GET.get('name', None)

        CHARM = CharmDirectory(get_path([CHARMSDIR, charm_name]))

        return [
            CharmObject({
                'name': CHARM.metadata.name,
                'summary': CHARM.metadata.summary,
                'maintainer': CHARM.metadata.maintainer,
                'description': CHARM.metadata.description,
            })
        ]
Ejemplo n.º 25
0
env.port = 22222
env.password = '******'
env.warn_only = True
env.output_prefix = False

# Docker config
env.docker = 'docker.io'
env.arch = get_local_arch()
env.docker_maintainer = '%s <%s>' % (AUTHOR, AUTHOR_EMAIL)

env.debian_base_image = 'luisalejandro/debian-%(arch)s:wheezy' % env
env.tribus_base_image = 'luisalejandro/tribus-%(arch)s:wheezy' % env
env.tribus_runtime_image = 'luisalejandro/tribus-run-%(arch)s:wheezy' % env
env.tribus_runtime_container = 'tribus-run-container'

env.debian_base_image_script = get_path(
    [BASEDIR, 'tribus', 'data', 'scripts', 'debian-base-image.sh'])
env.tribus_base_image_script = get_path(
    [BASEDIR, 'tribus', 'data', 'scripts', 'tribus-base-image.sh'])
env.tribus_django_syncdb_script = get_path(
    [BASEDIR, 'tribus', 'data', 'scripts', 'django-syncdb.sh'])
env.tribus_django_runserver_script = get_path(
    [BASEDIR, 'tribus', 'data', 'scripts', 'django-runserver.sh'])
env.tribus_start_container_script = get_path(
    [BASEDIR, 'tribus', 'data', 'scripts', 'start-container.sh'])

waffle_switches = SWITCHES_CONFIGURATION.keys()
mounts = ['%(basedir)s:%(basedir)s:rw' % env, '/tmp:/tmp:rw']
start_services = ['ssh', 'postgresql', 'slapd']
change_passwd = ['root:tribus', 'postgres:tribus', 'openldap:tribus']

env.mounts = ' '.join('--volume %s' % i for i in mounts)
Ejemplo n.º 26
0
These are the tests for the tribus.common.repository module.

'''

import os
import gzip
import email.Utils
from fabric.api import env, lcd, local, settings
from debian import deb822
from django.test import TestCase
from doctest import DocTestSuite
from tribus.__init__ import BASEDIR
from tribus.common.utils import get_path
from tribus.web.cloud.models import Package

SAMPLESDIR = get_path([BASEDIR, "tribus", "testing", "samples"])
FIXTURES = get_path([BASEDIR, "tribus", "testing", "fixtures"])
dist = 'kerepakupai'


class RepositoryFunctions(TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_init_sample_packages(self):
        pass

    def test_select_sample_packages(self):
Ejemplo n.º 27
0
SITE_ID = 1

DEBUG = True
TEMPLATE_DEBUG = DEBUG

ADMINS = ()
MANAGERS = ADMINS

USE_I18N = True
USE_L10N = True
USE_TZ = True
TIME_ZONE = 'America/Caracas'
LANGUAGE_CODE = 'es'
DATABASE_OPTIONS = {'charset': 'utf8'}
DEFAULT_CHARSET = 'utf-8'
LOCALE_PATHS = [get_path([BASEDIR, 'tribus', 'data', 'i18n'])]

SITE_ROOT = get_path([BASEDIR, 'tribus', 'web'])
MEDIA_ROOT = ''
MEDIA_URL = '/media/'
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = [get_path([BASEDIR, 'tribus', 'data', 'static'])]
TEMPLATE_DIRS = [get_path([BASEDIR, 'tribus', 'data', 'templates'])]

DJANGO_STATIC = not DEBUG
DJANGO_STATIC_MEDIA_ROOTS = [get_path([BASEDIR, 'tribus', 'data'])]
DJANGO_STATIC_FILENAME_GENERATOR = 'tribus.common.utils.filename_generator'
DJANGO_STATIC_NAME_MAX_LENGTH = 200

LOGIN_URL = '/login'
Ejemplo n.º 28
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

from tribus import BASEDIR
from tribus.common.utils import get_path
from tribus.config.ldap import AUTH_LDAP_BASE

DEBUG = True

SITE_ROOT = get_path([BASEDIR, 'tribus', 'web'])
MEDIA_ROOT = ''
MEDIA_URL = '/media/'
STATIC_ROOT = ''
STATIC_URL = '/static/'
STATICFILES_DIRS = [get_path([BASEDIR, 'tribus', 'data', 'static'])]
TEMPLATE_DIRS = [get_path([BASEDIR, 'tribus', 'data', 'templates'])]

DATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3'}}

INSTALLED_APPS = (
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django_auth_ldap',
    'django_static',
    'tribus.web.cloud',
    'south',
    'haystack',
    #'waffle',
)

ROOT_URLCONF = 'tribus.web.urls'
Ejemplo n.º 29
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright (C) 2013 Desarrolladores de Tribus
#
# This file is part of Tribus.
#
# Tribus is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Tribus is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
'''

tribus
======


'''

from tribus.common.utils import get_path

BASEDIR = get_path([__file__, '..', '..'])
Ejemplo n.º 30
0
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
from debian import deb822
from email.Utils import parseaddr
from django.test.testcases import TestCase
from tribus.web.cloud.models import (Maintainer, Package, Details, Relation)
from tribus.__init__ import BASEDIR
from tribus.common.utils import get_path

SAMPLESDIR = get_path([BASEDIR, "tribus", "testing", "samples"])
test_dist = "kukenan"
'''
tribus.tests.tribus_web_cloud_models
====================================

These are the tests for the tribus.web.cloud models.

'''


class RegistrationModelTests(TestCase):
    def setUp(self):
        pass

    def tearDown(self):