Exemple #1
0
def _get_setting(name, default='', section=None, config_object=None):
    """Get a setting from settings.ini for a particular section (or env var)

    If an environment variable of the same name (or ALL CAPS) exists, return it.
    If item is not found in the section, look for it in the 'default' section.
    If item is not found in the default section of settings.ini, return the
    default value

    The value is converted to a bool, None, int, float if it should be.
    If the value contains any of (, ; |), then the value returned will
    be a list of items converted to (bool, None, int, float, or str).
    """
    val = getenv(name, getenv(name.upper()))
    if not val:
        try:
            val = config_object[section][name]
        except KeyError:
            try:
                val = config_object['default'][name]
            except KeyError:
                return default
            else:
                val = ih.from_string(val)
        else:
            val = ih.from_string(val)
    else:
        val = ih.from_string(val)

    if type(val) == str:
        val = val.replace('\\n', '\n').replace('\\t', '\t')
        if (',' in val or ';' in val or '|' in val):
            val = ih.string_to_converted_list(val)
    return val
Exemple #2
0
 def go(self, *args):
     """Move to a specific location"""
     x = None
     y = None
     if len(args) == 2:
         x, y = args
         x = ih.from_string(x)
         y = ih.from_string(y)
         CharacterController.go(self._character_name, x, y)
     else:
         logger.error(
             'You must specify an x and y coordinate, not {}'.format(
                 repr(args)))
Exemple #3
0
def get_all_settings(module_name):
    """Return a dict containing all settings from settings.ini"""
    config_object = _get_config_object(module_name)
    sections = set(config_object.sections())
    base = {}
    results = {}
    names = set()
    if 'default' in sections:
        base = dict(config_object['default'])
        sections.discard('default')
        names.update(list(base.keys()))
    for section in sections:
        results[section] = base.copy()
        results[section].update(dict(config_object[section]))
        names.update(list(results[section].keys()))
    env = {name: getenv(name, getenv(name.upper())) for name in names}
    for name, value in env.items():
        for section in sections:
            if name in results[section]:
                if value is not None:
                    results[section][name] = value
                if separator_rx.match(results[section][name]):
                    results[section][name] = ih.string_to_converted_list(
                        results[section][name])
                else:
                    results[section][name] = ih.from_string(
                        results[section][name])
    return results
Exemple #4
0
def dt_to_float_string(dt, fmt=FLOAT_STRING_FMT):
    """Return string representation of a utc_float from given dt object"""
    s = dt.strftime(fmt)
    result = ih.from_string(s)
    if type(result) != str:
        result = repr(result)
    return result
Exemple #5
0
 def history(self, *args):
     """Print/return successful colon commands used (default 10)"""
     if args:
         limit = ih.from_string(args[0])
     else:
         limit = 10
     print('\n'.join(self._collection.find(
         'status:ok',
         item_format='{_ts} -> cmd={cmd} status={status}',
         admin_fmt=True,
         limit=limit
     )))
Exemple #6
0
 def errors(self, *args):
     """Print/return any colon commands that raised exceptions (w/ traceback)"""
     if args:
         limit = ih.from_string(args[0])
     else:
         limit = 10
     print('\n'.join(self._collection.find(
         'status:error',
         item_format='{_ts} -> cmd={cmd} error_value={error_value}\n{traceback_string}\n',
         admin_fmt=True,
         limit=limit
     )))
Exemple #7
0
 def down(self, n):
     """Move down n units"""
     CharacterController.move_down(self._character_name,
                                   ih.from_string(n))
Exemple #8
0
 def up(self, n):
     """Move up n units"""
     CharacterController.move_up(self._character_name,
                                 ih.from_string(n))
Exemple #9
0
 def right(self, n):
     """Move right n units"""
     CharacterController.move_right(self._character_name,
                                    ih.from_string(n))
Exemple #10
0
 def left(self, n):
     """Move left n units"""
     CharacterController.move_left(self._character_name,
                                   ih.from_string(n))