Example #1
0
 def get_config_template():
     return {
         'enabled': confuse.TypeTemplate(bool),
         'keywords': confuse.StrSeq(),
         'max_following': confuse.Integer(),
         'multiple': confuse.TypeTemplate(bool)
     }
Example #2
0
 def get_config_template():
     return {
         'enabled': confuse.TypeTemplate(bool),
         'host': confuse.String(),
         'port': confuse.Integer(),
         'tls': confuse.TypeTemplate(bool),
         'username': confuse.String(),
         'password': confuse.String(),
         'recipient': confuse.String()
     }
Example #3
0
    def get_config_template():

        return {
            'enabled': confuse.TypeTemplate(bool),
            'friends': confuse.StrSeq(),
            'tag_keywords': confuse.StrSeq(),
            'friend_keywords': confuse.StrSeq(),
            'number_keywords': NumberKeywordsTemplate()
        }
Example #4
0
 def get_config_template():
     # Fixme: minor hack because StrSeq doesnt support default
     strseq = confuse.StrSeq()
     strseq.default = []
     return {
         'enabled': confuse.TypeTemplate(bool),
         'keywords': strseq,
         'users': strseq,
     }
Example #5
0
 def get_config_template():
     template = {
         'enabled': confuse.TypeTemplate(bool),
         'keywords': confuse.StrSeq()
     }
     return template
Example #6
0
class Config:
    base_template = {
        'twitter': {
            'consumer_key': confuse.String(),
            'consumer_secret': confuse.String(),
            'access_token_key': confuse.String(),
            'access_token_secret': confuse.String(),
            'min_ratelimit_percent': confuse.Integer(),

            'search': {
                'queries': confuse.TypeTemplate(list),
                'max_queue': confuse.Integer(),
                'max_quote_depth': confuse.Integer(),
                'min_quote_similarity': confuse.Number(),
                'skip_retweeted': confuse.TypeTemplate(bool),
                # Is updated on runtime
                'filter': {},
                # Is updated on runtime
                'sort': {},
            },
            # Is updated on runtime
            'actions': {},
            'scheduler': {
                'search_interval': confuse.Integer(),
                'retweet_interval': confuse.Integer(),
                'retweet_random_margin': confuse.Integer(),
                'blocked_users_update_interval': confuse.Integer(),
                'clear_queue_interval': confuse.Integer(),
                'rate_limit_update_interval': confuse.Integer(),
                'check_mentions_interval': confuse.Integer(),
            },
        },
        # Is updated on runtime
        'notifiers': {}
    }

    _valid = None

    @staticmethod
    def get():
        """
        Gets the static config object
        :return:
        """
        if Config._valid is None:
            raise ValueError("Configuration not loaded")
        return Config._valid

    @staticmethod
    def load(filename=None):
        """
        Loads a file and imports the settings
        :param filename: the file to import
        """
        config = confuse.LazyConfig('Yatcobot', __name__)

        # Add default config when in egg (using this way because egg is breaking the default way)
        if len(config.sources) == 0:
            default_config_text = pkg_resources.resource_string("yatcobot.config", "config_default.yaml")
            default_config = confuse.ConfigSource(yaml.load(default_config_text, Loader=confuse.Loader),
                                                  'pkg/config/config_default.yaml',
                                                  True)
            config.add(default_config)

        # Add user specified config
        if filename is not None and os.path.isfile(filename):
            config.set_file(filename)

        logger.info('Loading config files (From highest priority to lowest):')
        config.resolve()
        for i, config_source in enumerate(config.sources):
            logger.info(f'{i}: Path: {config_source.filename}')

        # Update template from plugins
        template = Config.get_template()
        Config._valid = config.get(template)

    @staticmethod
    def get_template():
        """
        Updates the config template dynamically from plugins
        :return: config template
        """
        template = Config.base_template

        # Merge filters templates
        from yatcobot.plugins.filters import FilterABC
        template['twitter']['search']['filter'].update(FilterABC.get_config_template())

        # Merge ratings templates
        from yatcobot.plugins.ratings import RatingABC
        template['twitter']['search']['sort'].update(RatingABC.get_config_template())

        # Merge actions templates
        from yatcobot.plugins.actions import ActionABC
        template['twitter']['actions'].update(ActionABC.get_config_template())

        # Merge notifiers templates
        from yatcobot.plugins.notifiers import NotifierABC
        template['notifiers'].update(NotifierABC.get_config_template())

        return template
Example #7
0
 def test_default_value(self):
     config = _root({})
     valid = config['foo'].get(confuse.TypeTemplate(set, set([1, 2])))
     self.assertEqual(valid, set([1, 2]))
        "skip_all_pick_movements": bool,
        "wait_at_place_egress": int,
        "robot_movement": {
            "global_speed_accel": {
                "speed_override": float,
                "speed_max_tcp": float,
                "accel": float,
                "accel_ramp": float,
            },
            "speed": {
                "pick": float,
                "travel": float,
                "place": float,
            },
            "zone": {
                "pick": ZoneDataTemplate(),
                "place": ZoneDataTemplate(),
                "place_egress": ZoneDataTemplate(),
                "travel": ZoneDataTemplate(),
            },
            "joint_positions": {
                "start": confuse.Sequence([float] * 6),
                "end": confuse.Sequence([float] * 6),
                "travel_trajectory": confuse.TypeTemplate(list, default=None),
            },
        },
    },
}

fab_conf = confuse.LazyConfig("rapid_clay_formations_fab", modname=__name__)
Example #9
0
 def test_incorrect_type(self):
     config = _root({'foo': dict()})
     with self.assertRaises(confuse.ConfigTypeError):
         config['foo'].get(confuse.TypeTemplate(set))
Example #10
0
 def test_missing_required_value(self):
     config = _root({})
     with self.assertRaises(confuse.NotFoundError):
         config['foo'].get(confuse.TypeTemplate(set))
Example #11
0
    Filenames are parsed equivalent to the `Filename` template and then
    converted to `pathlib.Path` objects.
    For Python 2 it returns the original path as returned by the `Filename`
    template.

    From upstream master, commit by Szabolcs on Github.
    https://github.com/beetbox/confuse/commit/6c97e03d125cbbae5ce08040b1207d33ae3ef01c
    """
    def value(self, view, template=None):
        return pathlib.Path(super(Path, self).value(view, template))


ABB_RCF_CONF_TEMPLATE = {
    # Two following is set by command line arguments
    "debug": confuse.TypeTemplate(bool, default=False),
    "verbose": confuse.TypeTemplate(bool, default=False),
    # is_target_real is set either by command line argument, during run or in conf file
    "target": confuse.TypeTemplate(str, default=None),
    "paths": {
        "json_dir": confuse.Filename(default=str(DEFAULT_JSON_DIR)),
        "conf_dir": confuse.Filename(default=str(DEFAULT_JSON_DIR)),
        "log_dir": confuse.Filename(default=str(DEFAULT_LOG_DIR)),
    },
    "wobjs": {
        "picking_wobj_name": str,
        "placing_wobj_name": str
    },
    "tool": {
        "tool_name": str,
        "io_needles_pin": str,
Example #12
0
 def test_correct_type(self):
     config = _root({'foo': set()})
     valid = config['foo'].get(confuse.TypeTemplate(set))
     self.assertEqual(valid, set())
Example #13
0
 def get_config_template():
     return {
         'enabled': confuse.TypeTemplate(bool),
         'number': confuse.Integer()
     }
Example #14
0
class Config:
    template = {
        'twitter': {
            'consumer_key': confuse.String(),
            'consumer_secret': confuse.String(),
            'access_token_key': confuse.String(),
            'access_token_secret': confuse.String(),
            'min_ratelimit_percent': confuse.Integer(),

            'search': {
                'queries': confuse.TypeTemplate(list),
                'max_queue': confuse.Integer(),
                'max_quote_depth': confuse.Integer(),
                'min_quote_similarity': confuse.Number(),
                'skip_retweeted': confuse.TypeTemplate(bool),
                'filter': {
                    'min_retweets': {
                        'enabled': confuse.TypeTemplate(bool),
                        'number': confuse.Integer()
                    }
                },
                'sort': {
                    'by_keywords': {
                        'enabled': confuse.TypeTemplate(bool),
                        'keywords': confuse.StrSeq()
                    },
                    'by_age': {
                        'enabled': confuse.TypeTemplate(bool),
                    },
                    'by_retweets_count': {
                        'enabled': confuse.TypeTemplate(bool),
                    }
                }
            },

            'actions': {
                'follow': {
                    'enabled': confuse.TypeTemplate(bool),
                    'keywords': confuse.StrSeq(),
                    'max_following': confuse.Integer(),
                    'multiple': confuse.TypeTemplate(bool)
                },
                'favorite': {
                    'enabled': confuse.TypeTemplate(bool),
                    'keywords': confuse.StrSeq()
                },
                'tag_friend': {
                    'enabled': confuse.TypeTemplate(bool),
                    'friends': confuse.StrSeq(),
                }
            },

            'scheduler': {
                'search_interval': confuse.Integer(),
                'retweet_interval': confuse.Integer(),
                'retweet_random_margin': confuse.Integer(),
                'blocked_users_update_interval': confuse.Integer(),
                'clear_queue_interval': confuse.Integer(),
                'rate_limit_update_interval': confuse.Integer(),
                'check_mentions_interval': confuse.Integer(),
            },
        },
        'notifiers': {
            'mail': {
                'enabled': confuse.TypeTemplate(bool),
                'host': confuse.String(),
                'port': confuse.Integer(),
                'tls': confuse.TypeTemplate(bool),
                'username': confuse.String(),
                'password': confuse.String(),
                'recipient': confuse.String()
            },
            'pushbullet': {
                'enabled': confuse.TypeTemplate(bool),
                'token': confuse.String()
            }
        }
    }

    _valid = None

    @staticmethod
    def get():
        """
        Gets the static config object
        :return:
        """
        if Config._valid is None:
            raise ValueError("Configuration not loaded")
        return Config._valid

    @staticmethod
    def load(filename=None):
        """
        Loads a file and imports the settings
        :param filename: the file to import
        """
        config = confuse.LazyConfig('Yatcobot', __name__)

        # Add default config when in egg (using this way because egg is breaking the default way)
        if len(config.sources) == 0:
            default_config_text = pkg_resources.resource_string("yatcobot", "config_default.yaml")
            default_config = confuse.ConfigSource(yaml.load(default_config_text, Loader=confuse.Loader),
                                                  'pkg/config_default.yaml',
                                                  True)
            config.add(default_config)

        # Add user specified config
        if filename is not None and os.path.isfile(filename):
            config.set_file(filename)

        logger.info('Loading config files (From highest priority to lowest):')
        for i, config_source in enumerate(config.sources):
            logger.info('{}: Path: {}'.format(i, config_source.filename))
        Config._valid = config.get(Config.template)
Example #15
0
 def get_config_template():
     return {
         'enabled': confuse.TypeTemplate(bool),
         'token': confuse.String()
     }
Example #16
0
            return value
        if value.upper() not in self.ZONE_DICT.keys():
            self.fail(
                "ZoneData must match one of {0}".format(", ".join(
                    self.ZONE_DICT.keys())),
                view,
            )
        return self.ZONE_DICT[value.upper()]


ABB_RCF_CONF_TEMPLATE = {
    "log_dir": confuse.Filename(),
    "pick_conf": confuse.Path(),
    "run_data_path": confuse.Template(),  # Already type checked by argparse
    "publish_tf_xform": bool,
    "edit_sequence": confuse.TypeTemplate(bool, default=False),
    "robot_client": {
        "controller": str,
        "docker": {
            "timeout_ping": float,
            "sleep_after_up": float
        },
        "wobjs": {
            "pick": str,
            "place": str
        },
        "tools": {
            "pick_place": {
                "name": str,
                "io_pin_needles": str,
                "extend_signal": int,
Example #17
0
 def get_config_template():
     return {
         'enabled': confuse.TypeTemplate(bool),
     }