Ejemplo n.º 1
0
    def show_package_schema(self):
        # IDatasetForm
        schema = super(MetametaPlugin, self).show_package_schema()

        # Don't show vocab tags mixed in with normal 'free' tags
        # (e.g. on dataset pages, or on the search page)
        schema['tags']['__extras'].append(tk.get_converter('free_tags_only'))

        #retrieve metameta data
        org_id = h.get_organization_id()
        records = h.select_metametadata_for_org(org_id,
                                                metameta_id=None,
                                                active_only=True,
                                                withPrefix=True)

        for record in records:
            validator = record['validator']
            if h.is_metameta_validator(record['validator']):
                validator = h.get_validator(validator)
            else:
                validator = tk.get_validator(validator)

            # convert_from_extras instead of convert_from_tags.
            schema.update({
                record['key']:
                [tk.get_converter('convert_from_extras'), validator]
            })

        return schema
Ejemplo n.º 2
0
    def show_package_schema(self):
        # IDatasetForm
        schema = super(MetametaPlugin, self).show_package_schema()

        # Don't show vocab tags mixed in with normal 'free' tags
        # (e.g. on dataset pages, or on the search page)
        schema['tags']['__extras'].append(tk.get_converter('free_tags_only'))

        #retrieve metameta data
        org_id = h.get_organization_id()
        records = h.select_metametadata_for_org(org_id, metameta_id=None, active_only=True, withPrefix=True)

        for record in records:
            validator = record['validator']
            if h.is_metameta_validator(record['validator']):
               validator = h.get_validator(validator)
            else:
               validator = tk.get_validator(validator)

            # convert_from_extras instead of convert_from_tags.
            schema.update({
                record['key']: [
                    tk.get_converter('convert_from_extras'),
                    validator]
                })


        return schema
Ejemplo n.º 3
0
def handle_add_node(update, context):
    """
    Process what the user's input
    """

    address = update.message.text
    try:
        node = get_validator(address=address)
    except ConnectionError:
        context.user_data['expected'] = None
        update.message.reply_text(
            '⛔️ I cannot reach the LCD server!⛔\nPlease try again later.')
        return show_my_nodes_paginated(context=context,
                                       chat_id=update.effective_chat.id)

    if node is None:
        context.user_data['expected'] = 'add_node'
        return update.message.reply_text(
            '⛔️ I have not found a Node with this address! ⛔\n'
            'Please try another one. (enter /cancel to return to the menu)')

    add_node_to_user_data(context.user_data, address, node)
    context.bot.send_message(update.effective_chat.id, 'Got it! 👌')
    return show_my_nodes_paginated(context=context,
                                   chat_id=update.effective_chat.id)
Ejemplo n.º 4
0
 def is_valid(self, instance):
     """
     Validates a data.json entry against the DCAT_US JSON schema.
     Log a warning message on validation error
     """
     error = best_match(
         get_validator(
             schema_type=DataJsonPlugin.schema_type).iter_errors(instance))
     if error:
         logger.warn(
             "===================================================\r\n" +
             "Validation failed, best guess of error:\r\n %s\r\nFor this dataset:\r\n",
             error)
         return False
     return True
Ejemplo n.º 5
0
    def _modify_package_schema(self, schema):

        #retrieve metameta data
        org_id = h.get_organization_id()
        records = h.select_metametadata_for_org(org_id, metameta_id=None, active_only=True, withPrefix=True)

        for record in records:
            validator = record['validator']
            if h.is_metameta_validator(record['validator']):
               validator = h.get_validator(validator)
            else:
               validator = tk.get_validator(validator)

            # convert_to_extras instead of convert_to_tags.
            schema.update({
                    record['key']: [
                        validator,
                        tk.get_converter('convert_to_extras')]
                    })

        return schema
Ejemplo n.º 6
0
    def _modify_package_schema(self, schema):

        #retrieve metameta data
        org_id = h.get_organization_id()
        records = h.select_metametadata_for_org(org_id,
                                                metameta_id=None,
                                                active_only=True,
                                                withPrefix=True)

        for record in records:
            validator = record['validator']
            if h.is_metameta_validator(record['validator']):
                validator = h.get_validator(validator)
            else:
                validator = tk.get_validator(validator)

            # convert_to_extras instead of convert_to_tags.
            schema.update({
                record['key']:
                [validator, tk.get_converter('convert_to_extras')]
            })

        return schema
Ejemplo n.º 7
0
import sys

import ckan.lib.dictization.model_dictize as model_dictize
import ckan.model as model
import ckan.plugins as p
import os
import re
from ckan.lib.base import BaseController, render, c
from jsonschema.exceptions import best_match
from pylons import request, response

from helpers import get_export_map_json, detect_publisher, get_validator
from package2pod import Package2Pod

logger = logging.getLogger(__name__)
draft4validator = get_validator()

try:
    from collections import OrderedDict  # 2.7
except ImportError:
    from sqlalchemy.util import OrderedDict


class DataJsonPlugin(p.SingletonPlugin):
    p.implements(p.interfaces.IConfigurer)
    p.implements(p.ITemplateHelpers)
    p.implements(p.interfaces.IRoutes, inherit=True)

    def update_config(self, config):
        # Must use IConfigurer rather than IConfigurable because only IConfigurer
        # is called before after_map, in which we need the configuration directives
Ejemplo n.º 8
0
import ckan.plugins as p
from ckan.lib.base import BaseController, render, c
from pylons import request, response
import re
import ckan.model as model
import os
import ckan.lib.dictization.model_dictize as model_dictize

from jsonschema.exceptions import best_match

from helpers import get_export_map_json, detect_publisher, get_validator
from package2pod import Package2Pod

logger = logging.getLogger('datajson')
draft4validator = get_validator()

try:
    from collections import OrderedDict  # 2.7
except ImportError:
    from sqlalchemy.util import OrderedDict


class DataJsonPlugin(p.SingletonPlugin):
    p.implements(p.interfaces.IConfigurer)
    p.implements(p.interfaces.IRoutes, inherit=True)

    def update_config(self, config):
        # Must use IConfigurer rather than IConfigurable because only IConfigurer
        # is called before after_map, in which we need the configuration directives
        # to know how to set the paths.
Ejemplo n.º 9
0
def check_node_status(context):
    """
    Check all added Terra Nodes for any changes.
    """

    chat_id = context.job.context['chat_id']
    user_data = context.job.context['user_data']

    # List to delete entries after loop
    delete_addresses = []

    # Iterate through all keys
    for address in user_data.get('nodes', {}).keys():
        try:
            remote_node = get_validator(address=address)
        except ConnectionError:
            continue

        local_node = user_data['nodes'][address]

        if remote_node is None:
            text = 'Node is not active anymore! 💀' + '\n' + \
                   'Address: ' + address + '\n\n' + \
                   'Please enter another Node address.'

            delete_addresses.append(address)

            # Send message
            try_message_to_all_platforms(context=context,
                                         chat_id=chat_id,
                                         text=text)
            continue

        # Check which node fields have changed
        changed_fields = [
            field for field in ['status', 'jailed', 'delegator_shares']
            if local_node[field] != remote_node[field]
        ]

        # Check if there are any changes
        if len(changed_fields) > 0:
            text = f'Node: *{address}*\n' \
                   f'Status: *{NODE_STATUSES[local_node["status"]]}*'
            if 'status' in changed_fields:
                text += f' ➡️ *{NODE_STATUSES[remote_node["status"]]}*'
            text += f'\nJailed: *{local_node["jailed"]}*'
            if 'jailed' in changed_fields:
                text += f' ➡️ *{remote_node["jailed"]}*'
            local_delegator_shares = int(float(local_node["delegator_shares"]))
            text += f'\nDelegator Shares: *{local_delegator_shares}*'
            if 'delegator_shares' in changed_fields:
                remote_delegator_shares = int(
                    float(remote_node['delegator_shares']))
                delta = remote_delegator_shares - local_delegator_shares
                delta = str(delta) if (delta < 0) else f"+{delta}"
                text += f' ➡️ *{remote_delegator_shares}* (*Δ* {delta})'

            # Update data
            local_node['status'] = remote_node['status']
            local_node['jailed'] = remote_node['jailed']
            local_node['delegator_shares'] = remote_node['delegator_shares']

            # Send message
            try_message_to_all_platforms(context=context,
                                         chat_id=chat_id,
                                         text=text)

    for address in delete_addresses:
        del user_data['nodes'][address]