示例#1
0
    def test_equal_when_in_section(self):
        """Test option equality for section options."""
        sect1 = Section(name='sect1')
        sect2 = Section(name='sect2')
        opt1 = IntOption()
        opt2 = IntOption()

        self.assertEqual(opt1, opt2)

        opt1.section = sect1
        opt2.section = sect2
        self.assertNotEqual(opt1, opt2)
示例#2
0
        class MySchema(Schema):
            foo = IntOption()

            class one(Section):
                bar = IntOption()

            two = Section()
            two.bam = IntOption()
 def test_django13_logging_config(self):
     schema = schemas.get('1.3')
     section = Section(name='django')
     expected = StringOption(name='logging_config', null=True,
         default='django.utils.log.dictConfig',
         help='The callable to use to configure logging')
     expected.section = section
     self.assertEqual(schema.django.logging_config, expected)
示例#4
0
def ini2schema(fd, p=None):
    """
    Turn a fd that refers to a INI-style schema definition into a
    SchemaConfigParser object

    @param fd: file-like object to read the schema from
    @param p: a parser to use. If not set, uses AttributedConfigParser
    """
    if p is None:
        p = AttributedConfigParser()
    p.readfp(fd)
    p.parse_all()

    parser2option = {'unicode': StringOption,
                     'int': IntOption,
                     'bool': BoolOption,
                     'lines': ListOption}

    class MySchema(Schema):
        pass

    for section_name in p.sections():
        if section_name == '__main__':
            section = MySchema
        else:
            section = Section(name=section_name)
            setattr(MySchema, section_name, section)
        for option_name in p.options(section_name):
            option = p.get(section_name, option_name)

            parser = option.attrs.pop('parser', 'unicode')
            parser_args = option.attrs.pop('parser.args', '').split()
            parser_fun = getattr(parsers, parser, None)
            if parser_fun is None:
                parser_fun = getattr(__builtin__, parser, None)
            if parser_fun is None:
                parser_fun = lambda x: x

            attrs = {'name': option_name}
            option_help = option.attrs.pop('help', None)
            if option_help is not None:
                attrs['help'] = option_help
            if not option.is_empty:
                attrs['default'] = parser_fun(option.value, *parser_args)
            option_action = option.attrs.pop('action', None)
            if option_action is not None:
                attrs['action'] = option_action

            klass = parser2option.get(parser, StringOption)
            if parser == 'lines':
                instance = klass(item=StringOption(), **attrs)
            else:
                instance = klass(**attrs)
            setattr(section, option_name, instance)

    return SchemaConfigParser(MySchema())
示例#5
0
    def test_repr_name(self):
        """Test Option repr with name."""
        opt = self.cls()
        expected = "<{0}>".format(self.cls.__name__)
        self.assertEqual(repr(opt), expected)

        opt = self.cls(name='name')
        expected = "<{0} name>".format(self.cls.__name__)
        self.assertEqual(repr(opt), expected)

        sect = Section(name='sect')
        opt = self.cls(name='name', section=sect)
        expected = "<{0} sect.name>".format(self.cls.__name__)
        self.assertEqual(repr(opt), expected)
示例#6
0
class OpenProximitySchema(Django13Schema):
    ################################################
    # openproximity general settings
    ################################################
    openproximity = Section('openproximity')
    openproximity.aircable_path = StringOption(
        default='/tmp/aircable',
        help=
        'Path were we store the database file (if using sqlite) and storing files for campaigns etc'
    )
    openproximity.op2_debug = BoolOption(
        default=True, help='Disable if you want to hide the "Databrowse" tab')
    openproximity.op2_translate = BoolOption(
        default=True, help='Disable if you want to hide the "Translate" tab')
    openproximity.op2_twitter = BoolOption(
        default=True,
        help='Disable if you want to hide the Twitter news client')
    openproximity.op2_logo = StringOption(
        default='logo.gif', help='Logo to display instead of AIRcable logo')
    openproximity.op2_plugins = DictOption(
        item=BoolOption(),
        help=
        """A list of plugins name with they're enable/disable state overrides plugins defaults)"""
    )
    openproximity.op2_scanners = ListOption(
        item=TupleOption(4),
        help=
        """A list of ([MAC filter], scanner priority) for dongle configuration on initial discovery"""
    )
    openproximity.op2_uploaders = ListOption(
        item=TupleOption(4),
        help=
        """A list of ([MAC filter], max connections) for dongle configuration on initial discovery"""
    )

    ################################################
    # cherrypy settings
    ################################################
    cherrypy = Section('cherrypy')
    cherrypy.cp_host = StringOption(default="localhost",
                                    help='hostname to listen on')
    cherrypy.cp_port = IntOption(default=8088, help='port to listen on')
    cherrypy.cp_server_name = StringOption(
        default="localhost", help="CherryPy's SERVER_NAME environ entry")
    cherrypy.cp_daemonize = BoolOption(default=False,
                                       help='whether to detach from terminal')
    cherrypy.cp_pidfile = StringOption(
        default=None, help="write the spawned process-id to this file")
    cherrypy.cp_workdir = StringOption(
        default=None, help="change to this directory when daemonizing")
    cherrypy.cp_threads = IntOption(default=20,
                                    help='Number of threads for server to use')
    cherrypy.cp_ssl_certificate = StringOption(default=None,
                                               help="SSL certificate filename")
    cherrypy.cp_ssl_private_key = StringOption(default=None,
                                               help="SSL private key filename")
    cherrypy.cp_server_user = StringOption(
        default='www-data', help="user to run daemonized process")
    cherrypy.cp_server_group = StringOption(default='www-data',
                                            help="group to daemonized process")

    ################################################
    # rpyc settings
    ################################################
    rpyc = Section('rpyc')
    rpyc.rpc_host = StringOption(default="localhost",
                                 help='hostname to listen on')
    rpyc.rpc_port = IntOption(default=8010, help='port to listen on')
    rpyc.rpc_daemonize = BoolOption(default=False,
                                    help='whether to detach from terminal')
    rpyc.rpc_threaded = BoolOption(
        default=True, help='run in threaded way instead of forked')
    rpyc.rpc_autoregister = BoolOption(
        default=False, help='try registering the server in name servers')
    rpyc.rpc_pidfile = StringOption(
        default=None, help="write the spawned process-id to this file")
    rpyc.rpc_server_user = StringOption(default='www-data',
                                        help="user to run daemonized process")
    rpyc.rpc_server_group = StringOption(default='www-data',
                                         help="group to daemonized process")

    ################################################
    # debugging settings
    ################################################
    debug = Section('debug')
    debug.debug_console = StringOption(
        default='INFO', help='console debug level, default INFO')
    debug.debug_level = StringOption(default='DEBUG',
                                     help='in file debug level, default DEBUG')
    debug.debug_path = StringOption(
        default='/var/log/openproximity',
        help='default path used for storing log files')
    debug.debug_maxsize = IntOption(default=10,
                                    help='max log file in MB, defaults to 10')
    debug.debug_count = IntOption(
        default=5,
        help='amount of log files to store when rotating, defaults to 2')
    debug.debug_filename = StringOption(
        default=None,
        help='file name used for this debug session, defaults to sys.argv[1]')
    debug.debug_console_format = StringOption(
        default='%(name)s %(module)s:%(funcName)s: %(message)s',
        help='console log formatting')
    debug.debug_format = StringOption(
        default=
        '%(asctime)-12s - %(levelname)5s - %(name)10s - %(funcName)-12s: %(message)s',
        help='file log formatting')
    debug.debug_disables = StringOption(
        default='', help='comma separated list of disable log modules')

    rpc_client = Section("rpc_client")
    rpc_client.client_mode = StringOption()
    rpc_client.client_daemonize = BoolOption(default=False)
    rpc_client.client_pidfile = StringOption(default=None)
    rpc_client.client_host = StringOption(default="localhost")
    rpc_client.client_port = IntOption(default=8010)