Пример #1
0
def load():
    """ Load and return configuration as a ``Bunch``.

        Values are based on ``DEFAULTS``, and metadata from ``setup.py``.
    """
    cfg = Bunch(DEFAULTS)
    # TODO: override with contents of [rituals] section in setup.cfg

    cfg.project_root = get_project_root()
    if not cfg.project_root:
        raise RuntimeError(
            "No tasks module is imported, cannot determine project root")

    cfg.rootjoin = lambda *names: os.path.join(cfg.project_root, *names)
    cfg.srcjoin = lambda *names: cfg.rootjoin(cfg.srcdir, *names)
    cfg.testjoin = lambda *names: cfg.rootjoin(cfg.testdir, *names)
    cfg.cwd = os.getcwd()
    os.chdir(cfg.project_root)

    # this assumes an importable setup.py
    # TODO: maybe call "python setup.py egg_info" for metadata
    if cfg.project_root not in sys.path:
        sys.path.append(cfg.project_root)
    try:
        from setup import project  # pylint: disable=no-name-in-module
    except ImportError:
        from setup import setup_args as project  # pylint: disable=no-name-in-module
    cfg.project = Bunch(project)

    return cfg
Пример #2
0
 def test_get_devpi_url_ignores_ansi_codes(self):
     ctx = Bunch(run=lambda cmd, **_: Bunch(
         stdout=
         "first: line\n\x1b1m   simpleindex: THE-URL/\x1b0m\n other: foobar\n"
     ))
     url = devpi.get_devpi_url(ctx)
     assert url == "THE-URL", "get_devpi_url() extracted the URL"
Пример #3
0
 def test_configuration_dump_with_value(self):
     memo = []
     out = Bunch(write=lambda d: memo.append(d))
     cfg = Configuration('foobarbaz_wont_exist_ever')
     cfg.load().merge(dict(foo='bar'))
     cfg.dump(out)
     assert ''.join(i.decode('ascii') for i in memo) == 'foo = bar\n'
Пример #4
0
    def __init__(self, conn, per_page=30):
        """
        RecurringItemsIterator
        """

        self.conn = conn
        self.items = RecurringItems(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(recurring_id=None, order_by=None)
    def __init__(self, conn, per_page=30):
        """
        CreditNoteItemsIterator
        """

        self.conn = conn
        self.items = CreditNoteItems(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(credit_note_id=None, order_by=None)
Пример #6
0
    def __init__(self, conn, per_page=30):
        """
        InvoiceItemsIterator
        """

        self.conn = conn
        self.items = InvoiceItems(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(invoice_id=None, order_by=None)
Пример #7
0
    def __init__(self, conn, per_page=30):
        """
        ContactsIterator
        """

        self.conn = conn
        self.items = Contacts(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(client_id=None, order_by=None)
Пример #8
0
    def __init__(self, conn, per_page=30):
        """
        ReminderTextsIterator
        """

        self.conn = conn
        self.items = ReminderTexts(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(order_by=None, )
Пример #9
0
    def __init__(self, conn, per_page=30):
        """
        EmailTemplatesIterator
        """

        self.conn = conn
        self.items = EmailTemplates(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(order_by=None, )
Пример #10
0
    def create_dict(self):
        '''
        Create a Bunch class object to store the parameter names for the Nortek
        Aquadopp (aka VELPT), with the data organized hierarchically by the
        data type.
        '''
        bunch = Bunch()
        bunch.header = Bunch()
        bunch.diagnostics = Bunch()
        bunch.velocity = Bunch()

        for name in self._header:
            bunch.header[name] = []

        for name in self._packet:
            bunch.diagnostics[name] = []
            bunch.velocity[name] = []

        return bunch
Пример #11
0
 def test_configuration_from_context_creation_works(self):
     ctx = Bunch(info_name='foobarbaz', obj=None)
     cfg = Configuration.from_context(ctx)
     assert isinstance(cfg,
                       Configuration), "Configuration has expected type"
     assert ctx.obj.cfg is cfg, "Configuration is added to context"
     assert cfg.name == 'foobarbaz'
     assert len(cfg.config_paths) >= 2, "Default config paths are used"
     assert cfg.config_paths[
         0] == '/etc/foobarbaz.conf', "Default config paths are used"
Пример #12
0
    def create_dict(self):
        '''
        Create a Bunch class object to store the parameter names for the data
        files.
        '''
        bunch = Bunch()

        for name in self.parameters:
            bunch[name] = []

        return bunch
Пример #13
0
    def __init__(self, conn, per_page=100):
        """
        ArticleTagsIterator
        """

        self.conn = conn
        self.items = ArticleTags(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(
            article_id=None,
            order_by=None,
        )
Пример #14
0
    def create_dict(self):
        '''
        Create a Bunch class object to store the parameter names for the Nortek
        Vector (aka VEL3D), with the data organized hierarchically by the
        data type.
        '''
        bunch = Bunch()
        bunch.header = Bunch()
        bunch.system = Bunch()
        bunch.velocity = Bunch()

        for name in self._header:
            bunch.header[name] = []

        for name in self._system:
            bunch.system[name] = []

        for name in self._velocity:
            bunch.velocity[name] = []

        return bunch
Пример #15
0
    def __init__(self, conn, per_page=100):
        """
        ReminderTagsIterator
        """

        self.conn = conn
        self.items = ReminderTags(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(
            reminder_id=None,
            order_by=None,
        )
Пример #16
0
    def __init__(self, conn, per_page=100):
        """
        ClientPropertiesIterator
        """

        self.conn = conn
        self.items = ClientProperties(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(
            client_id=None,
            client_property_id=None,
            value=None,
            order_by=None,
        )
Пример #17
0
    def __init__(self, conn, per_page = 100):
        """
        InvoicePaymentsIterator
        """

        self.conn = conn
        self.items = InvoicePayments(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(
            invoice_id = None,
            from_date = None,
            to_date = None,
            type = None,
            user_id = None,
            order_by = None,
        )
Пример #18
0
    def __init__(self, conn, per_page=30):
        """
        ArticlesIterator
        """

        self.conn = conn
        self.items = Articles(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(
            article_number=None,
            title=None,
            description=None,
            currency_code=None,
            unit_id=None,
            tags=None,
            supplier_id=None,
            order_by=None,
        )
Пример #19
0
    def __init__(self, conn, per_page=30):
        """
        RecurringsIterator
        """

        self.conn = conn
        self.items = Recurrings(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(client_id=None,
                                   contact_id=None,
                                   name=None,
                                   payment_type=None,
                                   cycle=None,
                                   label=None,
                                   intro=None,
                                   note=None,
                                   tags=None,
                                   order_by=None)
Пример #20
0
    def __init__(self, conn, per_page=30):
        """
        SuppliersIterator
        """

        self.conn = conn
        self.items = Suppliers(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(name=None,
                                   email=None,
                                   first_name=None,
                                   last_name=None,
                                   country_code=None,
                                   creditor_identifier=None,
                                   note=None,
                                   client_number=None,
                                   incoming_id=None,
                                   tags=None,
                                   order_by=None)
Пример #21
0
    def __init__(self, conn, per_page=30):
        """
        ClientsIterator
        """

        self.conn = conn
        self.items = Clients(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(
            name=None,
            client_number=None,
            email=None,
            first_name=None,
            last_name=None,
            country_code=None,
            note=None,
            invoice_id=None,
            tags=None,
            order_by=None,
        )
Пример #22
0
    def create_dict(self):
        '''
        Create a Bunch class object to store the parameter names for the
        Workhorse ADCP pd0 data files, with the data organized hierarchically
        by the data type.
        '''
        bunch = Bunch()
        bunch.time = []
        bunch.header = Bunch()
        bunch.fixed = Bunch()
        bunch.variable = Bunch()
        bunch.velocity = Bunch()
        bunch.correlation = Bunch()
        bunch.echo = Bunch()
        bunch.percent = Bunch()

        for name in self._header:
            bunch.header[name] = []

        for name in self._fixed:
            bunch.fixed[name] = []

        for name in self._variable:
            bunch.variable[name] = []

        for name in self._velocity:
            bunch.velocity[name] = []

        for name in self._correlation:
            bunch.correlation[name] = []

        for name in self._echo:
            bunch.echo[name] = []

        for name in self._percent:
            bunch.percent[name] = []

        return bunch
Пример #23
0
    def __init__(self, conn, per_page=30):
        """
        InvoicesIterator
        """

        self.conn = conn
        self.items = Invoices(self.conn)
        self.per_page = per_page
        self.search_params = Bunch(
            client_id=None,
            contact_id=None,
            invoice_number=None,
            status=None,
            payment_type=None,
            from_date=None,
            to_date=None,
            label=None,
            intro=None,
            note=None,
            tags=None,
            article_id=None,
            order_by=None,
        )
Пример #24
0
def get_egg_info(cfg, verbose=False):
    """Call 'setup egg_info' and return the parsed meta-data."""
    result = Bunch()
    setup_py = cfg.rootjoin('setup.py')
    if not os.path.exists(setup_py):
        return result

    egg_info = shell.capture("python {} egg_info".format(setup_py),
                             echo=True if verbose else None)
    for info_line in egg_info.splitlines():
        if info_line.endswith('PKG-INFO'):
            pkg_info_file = info_line.split(None, 1)[1]
            result['__file__'] = pkg_info_file
            with io.open(pkg_info_file, encoding='utf-8') as handle:
                lastkey = None
                for line in handle:
                    if line.lstrip() != line:
                        assert lastkey, "Bad continuation in PKG-INFO file '{}': {}".format(
                            pkg_info_file, line)
                        result[lastkey] += '\n' + line
                    else:
                        lastkey, value = line.split(':', 1)
                        lastkey = lastkey.strip().lower().replace('-', '_')
                        value = value.strip()
                        if lastkey in result:
                            try:
                                result[lastkey].append(value)
                            except AttributeError:
                                result[lastkey] = [result[lastkey], value]
                        else:
                            result[lastkey] = value

    for multikey in PKG_INFO_MULTIKEYS:
        if not isinstance(result.get(multikey, []), list):
            result[multikey] = [result[multikey]]

    return result
Пример #25
0
 def test_get_devpi_url_delivers_simpleindex_url(self):
     ctx = Bunch(run=lambda cmd, **_: Bunch(
         stdout="first: line\n   simpleindex: THE-URL/\n other: foobar\n"))
     url = devpi.get_devpi_url(ctx)
     assert url == "THE-URL", "get_devpi_url() extracted the URL"
Пример #26
0
 def get(self, _, **_dummy):
     return Bunch(body={'storage': Bunch(value='foo')})
Пример #27
0
 def __init__(self, taskname):
     Context.__init__(self,
                      config=testing.namespace.configuration(taskname))
     self.memo = Bunch(cmd='')
Пример #28
0
import re
import logging

import click
from munch import Munch as Bunch

from . import config


# Default name of the app, and its app directory
__app_name__ = 'confluencer'
config.APP_NAME = __app_name__

# The `click` custom context settings
CONTEXT_SETTINGS = dict(
    obj=Bunch(cfg=None, quiet=False, verbose=False),  # namespace for custom stuff
    help_option_names=['-h', '--help'],
    auto_envvar_prefix=config.APP_NAME.upper().replace('-', '_'),
)


# `--license` option decorator
def license_option(*param_decls, **attrs):
    """``--license`` option that prints license information and then exits."""
    def decorator(func):
        "decorator inner wrapper"
        def callback(ctx, _dummy, value):
            "click option callback"
            if not value or ctx.resilient_parsing:
                return
Пример #29
0
 def from_context(cls, ctx, config_paths=None, project=None):
     """Create a configuration object, and initialize the Click context with it."""
     if ctx.obj is None:
         ctx.obj = Bunch()
     ctx.obj.cfg = cls(ctx.info_name, config_paths, project=project)
     return ctx.obj.cfg
Пример #30
0
 def test_get_devpi_url_detects_missing_simpleindex_url(self):
     ctx = Bunch(
         run=lambda cmd, **_: Bunch(stdout="   notsosimpleindex: THE-URL/"))
     with pytest.raises(LookupError):
         _ = devpi.get_devpi_url(ctx)