Example #1
0
    def test_config_file_sectionless_getandset(self):
        conf = config_file(self.CONFIG_FILES['sectionless'])
        conf.use_sections(False)
        self.assertFalse(conf._use_sections)

        conf['first'] = 'hello'
        conf['second'] = 150
        conf['third'] = True

        self.assertEqual(conf['first'], 'hello')
        self.assertEqual(conf['second'], '150')
        self.assertEqual(conf['third'], 'True')

        self.assertEqual(conf['first':], 'hello')
        self.assertEqual(conf['first'::], 'hello')

        with self.assertRaises(TypeError):
            conf[::]
        with self.assertRaises(KeyError):
            conf['doesnotexist']
        with self.assertRaises(SyntaxError):
            conf['first':'second']
        with self.assertRaises(SyntaxError):
            conf['first':'second':]
        with self.assertRaises(SyntaxError):
            conf['first':'second']
        with self.assertRaises(SyntaxError):
            conf['first':'second':]
        with self.assertRaises(SyntaxError):
            conf['first':'second':'third']

        self.assertEqual(conf['doesnotexist'::5], 5)
        self.assertEqual(conf['doesnotexist'::'default'], 'default')

        self.assertIsInstance(conf[:], dict)
        self.assertEqual(conf[:], {
            'first': 'hello',
            'second': '150',
            'third': 'True'
        })

        with self.assertRaises(TypeError):
            conf[5] = 12
        with self.assertRaises(TypeError):
            conf[None] = 12
        with self.assertRaises(TypeError):
            conf[{}] = 12
        with self.assertRaises(TypeError):
            conf[()] = 12

        conf.commit()
        self.assertTrue(os.path.isfile(self.CONFIG_FILES['sectionless']))

        with config_file(self.CONFIG_FILES['sectionless']) as conf:
            pass
Example #2
0
    def test_config_file_sectionless_delitem(self):
        conf = config_file(self.CONFIG_FILES['sectionless'])
        conf.use_sections(False)
        self.assertFalse(conf._use_sections)

        del conf['doesnotexist']
        with self.assertRaises(SyntaxError):
            del conf['doesnotexist':]
        with self.assertRaises(SyntaxError):
            del conf['doesnotexist'::]
        with self.assertRaises(SyntaxError):
            del conf['doesnotexist':'stilldoesnt']
        with self.assertRaises(SyntaxError):
            del conf['doesnotexist':'stilldoesnt':]
        with self.assertRaises(SyntaxError):
            del conf['doesnotexist':'stilldoesnt':'default']

        with self.assertRaises(TypeError):
            del conf[5]
        with self.assertRaises(SyntaxError):
            del conf[5:]
        with self.assertRaises(SyntaxError):
            del conf[5::]
        with self.assertRaises(SyntaxError):
            del conf[5:5]
        with self.assertRaises(SyntaxError):
            del conf[5:5:]
        with self.assertRaises(SyntaxError):
            del conf[5:5:5]
Example #3
0
    def _create_sp(self, startup_values={}):
        defaults = {
            'server-port': 25565,
            'max-players': 20,
            'level-seed': '',
            'gamemode': 0,
            'difficulty': 1,
            'level-type': 'DEFAULT',
            'level-name': 'world',
            'max-build-height': 256,
            'generate-structures': 'false',
            'generator-settings': '',
            'server-ip': '0.0.0.0',
        }

        sanitize_integers = {
            'server-port', 'max-players', 'gamemode', 'difficulty'
        }

        for option in sanitize_integers:
            try:
                defaults[option] = int(startup_values[option])
            except (KeyError, ValueError):
                continue

        for option, value in startup_values.items():
            if option not in sanitize_integers:
                defaults[option] = value

        self._command_direct('touch %s' % self.env['sp'], self.env['cwd'])
        with config_file(self.env['sp']) as sp:
            sp.use_sections(False)
            for key, value in defaults.items():
                sp[key] = str(value)
Example #4
0
    def _create_sp(self, startup_values={}):
       #Popolamento del Server.properties
        serverProperty = ServerProperty('server-port', int, 25565, 'Server Port', None)
        defaults = {
            'server-port': 25565,
            'max-players': 20,
            'level-seed': '',
            'gamemode': 0,
            'difficulty': 1,
            'level-type': 'DEFAULT',
            'level-name': 'world',
            'max-build-height': 256,
            'generate-structures': 'true',
            'generator-settings': '',
            'server-ip': '0.0.0.0',
            'enable-rcon': 'true',
            'motd': 'Welcome to Mordor!',
            }

        for option, value in startup_values.iteritems():
            defaults[option] = value

       #DA CONTROLLARE SE FUNZIONA
        with config_file(os.path.join(self._file_system.bins, "server.properties")) as sp:
            sp.use_sections(False)
            for key, value in defaults.iteritems():
                sp[key] = str(value)
Example #5
0
    def test_reload_config(self):
        with config_file(self.CONFIG_FILES['sectionless']) as conf:
            conf.use_sections(False)
            conf['server-ip'] = '0.0.0.0'

        conf = config_file(self.CONFIG_FILES['sectionless'])
        self.assertFalse(conf._use_sections)
        self.assertEqual(conf['server-ip'], '0.0.0.0')
        self.assertEqual(conf['server-ip'::'0.0.0.0'], '0.0.0.0')

        with config_file(self.CONFIG_FILES['sectionless']) as conf:
            self.assertFalse(conf._use_sections)
            conf['server-ip'] = '127.0.0.1'

        conf = config_file(self.CONFIG_FILES['sectionless'])
        self.assertFalse(conf._use_sections)
        self.assertEqual(conf['server-ip'], '127.0.0.1')
        self.assertEqual(conf['server-ip'::'0.0.0.0'], '127.0.0.1')
Example #6
0
    def test_reload_config(self):
        with config_file(self.CONFIG_FILES['sectionless']) as conf:
            conf.use_sections(False)
            conf['server-ip'] = '0.0.0.0'

        conf = config_file(self.CONFIG_FILES['sectionless'])
        self.assertFalse(conf._use_sections)
        self.assertEqual(conf['server-ip'], '0.0.0.0')
        self.assertEqual(conf['server-ip'::'0.0.0.0'], '0.0.0.0')

        with config_file(self.CONFIG_FILES['sectionless']) as conf:
            self.assertFalse(conf._use_sections)
            conf['server-ip'] = '127.0.0.1'

        conf = config_file(self.CONFIG_FILES['sectionless'])
        self.assertFalse(conf._use_sections)
        self.assertEqual(conf['server-ip'], '127.0.0.1')
        self.assertEqual(conf['server-ip'::'0.0.0.0'], '127.0.0.1')
Example #7
0
    def test_config_file_sectionless_getandset(self):
        conf = config_file(self.CONFIG_FILES['sectionless'])
        conf.use_sections(False)
        self.assertFalse(conf._use_sections)

        conf['first'] = 'hello'
        conf['second'] = 150
        conf['third'] = True

        self.assertEqual(conf['first'], 'hello')
        self.assertEqual(conf['second'], '150')
        self.assertEqual(conf['third'], 'True')

        self.assertEqual(conf['first':], 'hello')
        self.assertEqual(conf['first'::], 'hello')

        with self.assertRaises(TypeError): conf[::]
        with self.assertRaises(KeyError): conf['doesnotexist']
        with self.assertRaises(SyntaxError): conf['first':'second']
        with self.assertRaises(SyntaxError): conf['first':'second':]
        with self.assertRaises(SyntaxError): conf['first':'second']
        with self.assertRaises(SyntaxError): conf['first':'second':]
        with self.assertRaises(SyntaxError): conf['first':'second':'third']

        self.assertEqual(conf['doesnotexist'::5], 5)
        self.assertEqual(conf['doesnotexist'::'default'], 'default')

        self.assertIsInstance(conf[:], dict)
        self.assertEqual(conf[:], {
            'first': 'hello',
            'second': '150',
            'third': 'True'
            })

        with self.assertRaises(TypeError): conf[5] = 12
        with self.assertRaises(TypeError): conf[None] = 12
        with self.assertRaises(TypeError): conf[{}] = 12
        with self.assertRaises(TypeError): conf[()] = 12
        
        conf.commit()
        self.assertTrue(os.path.isfile(self.CONFIG_FILES['sectionless']))

        with config_file(self.CONFIG_FILES['sectionless']) as conf:
            pass
Example #8
0
    def test_config_file(self):
        conf = config_file()
        self.assertIsInstance(conf[:], dict)
        self.assertFalse(conf[:])
        self.assertTrue(conf._use_sections)

        conf.use_sections(False)
        self.assertFalse(conf._use_sections)

        with self.assertRaises(TypeError):
            conf.commit()
Example #9
0
    def test_config_file(self):
        conf = config_file()
        self.assertIsInstance(conf[:], dict)
        self.assertFalse(conf[:])
        self.assertTrue(conf._use_sections)

        conf.use_sections(False)
        self.assertFalse(conf._use_sections)

        with self.assertRaises(TypeError):
            conf.commit()
Example #10
0
    def test_sp_defaults(self):
        from conf_reader import config_file
        instance = mc('one', **self.instance_arguments)
        instance.create(sp={'server-ip': '127.0.0.1'})

        conf = config_file(instance.env['sp'])
        self.assertFalse(conf._use_sections)
        self.assertEqual(conf['server-ip'], '127.0.0.1')

        instance = mc('one', **self.instance_arguments)
        self.assertFalse(conf._use_sections)
        self.assertEqual(instance.server_properties['server-ip'], '127.0.0.1')
Example #11
0
 def test_sp_defaults(self):
     from conf_reader import config_file
     instance = Mc('one', **self.instance_arguments)
     instance.create(sp={'server-ip':'127.0.0.1'})
     
     conf = config_file(instance.env['sp'])
     self.assertFalse(conf._use_sections)
     self.assertEqual(conf['server-ip'],'127.0.0.1')
     
     instance = Mc('one', **self.instance_arguments)
     self.assertFalse(conf._use_sections)
     self.assertEqual(instance.server_properties['server-ip'], '127.0.0.1')
Example #12
0
    def test_sc_defaults(self):
        from conf_reader import config_file
        instance = Mc('one', **self.instance_arguments)
        instance.create(sc={'java':{'java-bin':'isworking'}})
        
        conf = config_file(instance.env['sc'])
        self.assertTrue(conf._use_sections)
        self.assertEqual(conf['java':'java-bin'], 'isworking')

        instance = Mc('one', **self.instance_arguments)
        self.assertTrue(conf._use_sections)
        self.assertEqual(instance.server_config['java':'java-bin'], 'isworking')
Example #13
0
    def test_sc_defaults(self):
        from conf_reader import config_file
        instance = mc('one', **self.instance_arguments)
        instance.create(sc={'java': {'java-bin': 'isworking'}})

        conf = config_file(instance.env['sc'])
        self.assertTrue(conf._use_sections)
        self.assertEqual(conf['java':'java-bin'], 'isworking')

        instance = mc('one', **self.instance_arguments)
        self.assertTrue(conf._use_sections)
        self.assertEqual(instance.server_config['java':'java-bin'],
                         'isworking')
Example #14
0
    def test_config_file_sections_delitem(self):
        conf = config_file(self.CONFIG_FILES['sections'])
        self.assertTrue(conf._use_sections)

        with self.assertRaises(SyntaxError): del conf['doesnotexist']
        with self.assertRaises(SyntaxError): del conf['doesnotexist':]
        with self.assertRaises(SyntaxError): del conf['doesnotexist'::]
        with self.assertRaises(KeyError): del conf['doesnotexist':'stilldoesnt']
        with self.assertRaises(KeyError): del conf['doesnotexist':'stilldoesnt':]
        with self.assertRaises(SyntaxError): del conf['doesnotexist':'stilldoesnt':'default']

        with self.assertRaises(SyntaxError): del conf[5]
        with self.assertRaises(TypeError): del conf[5:]
        with self.assertRaises(SyntaxError): del conf[5::]
        with self.assertRaises(TypeError): del conf[5:5]
        with self.assertRaises(TypeError): del conf[5:5:]
        with self.assertRaises(SyntaxError): del conf[5:5:5]
Example #15
0
    def _create_sp(self, startup_values={}):
        """Creates a server.properties file for the server given a dict.
        startup_values is expected to have more options than
        server.properties should have, so provided startup_values
        are only used if they overwrite an option already
        hardcoded in the defaults dict.

        Expected startup_values should match format of "defaults".          
        """
        defaults = {
            'server-port': 25565,
            'max-players': 20,
            'level-seed': '',
            'gamemode': 0,
            'difficulty': 1,
            'level-type': 'DEFAULT',
            'level-name': 'world',
            'max-build-height': 256,
            'generate-structures': 'false',
            'generator-settings': '',
            'server-ip': '0.0.0.0',
            }

        sanitize_integers = set(['server-port',
                                 'max-players',
                                 'gamemode',
                                 'difficulty'])

        for option in sanitize_integers:
            try:
                defaults[option] = int(startup_values[option])
            except (KeyError, ValueError):
                continue

        for option, value in startup_values.iteritems():
            if option not in sanitize_integers:
                defaults[option] = value

        self._command_direct('touch %s' % self.env['sp'], self.env['cwd'])
        with config_file(self.env['sp']) as sp:
            sp.use_sections(False)
            for key, value in defaults.iteritems():
                sp[key] = str(value)
Example #16
0
    def _create_sc(self, startup_values={}):
        """Creates a server.config file for a server given a dict.
        
        Expected startup_values should match format of "defaults".
        """
        defaults = {
            'minecraft': {
                'profile': '',
                },
            'crontabs': {
                'archive_interval': 0,
                'backup_interval': 0,
                },
            'onreboot': {
                'restore': False,
                'start': False,
                },
            'java': {
                'java_tweaks': '-server',
                'java_xmx': 256,
                'java_xms': 256,
                }
            }

        sanitize_integers = set([('java', 'java_xmx'),
                                 ('java', 'java_xms'),
                                 ])

        d = defaults.copy()
        d.update(startup_values)

        for section, option in sanitize_integers:
            try:
                d[section][option] = int(startup_values[section][option])
            except (KeyError, ValueError):
                d[section][option] = defaults[section][option]

        self._command_direct('touch %s' % self.env['sc'], self.env['cwd'])
        with config_file(self.env['sc']) as sc:
            for section in d:
                sc.add_section(section)
                for option in d[section]:
                    sc[section:option] = str(d[section][option])
Example #17
0
    def _create_sc(self, startup_values={}):
        defaults = {
            'crontabs': {
                'archive_interval': '',
                'backup_interval': '',
                'restart_interval': '',
            },
            'onreboot': {
                'start': True,
            },
            'java': {
                'java_tweaks': '',
                'java_xmx': 256,
                'java_xms': 256,
                'jarfile': 'minecraft_server.jar'
            }
        }

        sanitize_integers = {('java', 'java_xmx'), ('java', 'java_xms'),
                             ('crontabs', 'archive_interval'),
                             ('crontabs', 'backup_interval'),
                             ('crontabs', 'restart_interval')}

        d = defaults.copy()
        d.update(startup_values)

        for section, option in sanitize_integers:
            try:
                d[section][option] = int(startup_values[section][option])
            except (KeyError, ValueError):
                d[section][option] = defaults[section][option]

        self._command_direct('touch %s' % self.env['sc'], self.env['cwd'])
        with config_file(self.env['sc']) as sc:
            for section in d:
                sc.add_section(section)
                for option in d[section]:
                    sc[section:option] = str(d[section][option])
Example #18
0
 def load_sp():
     self.server_properties = config_file(
         self.env['sp_backup']) if load_backup else config_file(
             self.env['sp'])
     self.server_properties.use_sections(False)
     return self.server_properties[:]
Example #19
0
 def eula(self):
     try:
         cf = config_file(os.path.join(self.env['cwd'], 'eula.txt'))
         return cf['eula']
     except (SyntaxError, KeyError):
         return None
Example #20
0
 def list_profiles(cls, base_directory):
     """Lists all profiles found in profile.config at the base_directory root"""
     pc = config_file(os.path.join(base_directory, 'profiles', 'profile.config'))
     return pc[:]
Example #21
0
    def test_config_file_sections_getandset(self):
        conf = config_file(self.CONFIG_FILES['sections'])
        self.assertTrue(conf._use_sections)

        with self.assertRaises(SyntaxError): conf['section'] = 'hello'
        with self.assertRaises(TypeError): conf['section':] = 'hello'
        with self.assertRaises(TypeError): conf['section'::] = 'hello'
        with self.assertRaises(KeyError): conf['section':'option'] = 'hello'
        with self.assertRaises(KeyError): conf['section':'option':] = 'hello'
        with self.assertRaises(TypeError): conf[:] = 'hello'
        with self.assertRaises(TypeError): conf[::] = 'hello'

        with self.assertRaises(TypeError): conf[5:] = 'hello'
        with self.assertRaises(TypeError): conf[5:5] = 'hello'
        with self.assertRaises(SyntaxError): conf[5:5:5] = 'hello'
        with self.assertRaises(TypeError): conf['5':5] = 'hello'
        with self.assertRaises(TypeError): conf[5:'5'] = 'hello'
        with self.assertRaises(SyntaxError): conf[5:'5':5] = 'hello'

        with self.assertRaises(KeyError): conf['fakesection']
        with self.assertRaises(KeyError): conf['fakesection':]
        with self.assertRaises(KeyError): conf['fakesection'::]
        with self.assertRaises(KeyError): conf['fakesection':'fake']
        with self.assertRaises(KeyError): conf['fakesection':'fake':]

        self.assertIsInstance(conf[:], dict)

        conf.add_section('java')
        conf['java':'java_xmx'] = 512
        conf['java':'java_xms'] = '256'
        conf['java':'thirdcolon':] = 'present'

        self.assertIsInstance(conf[:], dict)
        self.assertEqual(conf[:], {
            'java': {
                'java_xmx': '512',
                'java_xms': '256',
                'thirdcolon': 'present'
                }
            })

        self.assertIsInstance(conf['java'], dict)
        self.assertEqual(conf['java'], {
                'java_xmx': '512',
                'java_xms': '256',
                'thirdcolon': 'present'
                })

        self.assertEqual(conf['java':], {
                'java_xmx': '512',
                'java_xms': '256',
                'thirdcolon': 'present'
                })

        self.assertEqual(conf['java':'java_xmx'], '512')
        self.assertEqual(conf['java':'java_xms'], '256')

        self.assertEqual(conf['java':'madeup':768], 768)
        self.assertEqual(conf['java':'fake':'attr'], 'attr')

        with self.assertRaises(TypeError): conf['java':] = 'hello'
        with self.assertRaises(TypeError): conf['java'::] = 'hello'
        with self.assertRaises(TypeError): conf[::] = 'hello'
        with self.assertRaises(SyntaxError): conf['java':'second':'third'] = 'hello'

        with self.assertRaises(KeyError): conf['java':'madeup']
        with self.assertRaises(KeyError): conf['java':'madeup':]

        with self.assertRaises(SyntaxError): conf[5] = 12
        with self.assertRaises(SyntaxError): conf[None] = 12
        with self.assertRaises(SyntaxError): conf[{}] = 12
        with self.assertRaises(SyntaxError): conf[()] = 12

        conf.commit()
        self.assertTrue(os.path.isfile(self.CONFIG_FILES['sections']))

        with config_file(self.CONFIG_FILES['sections']) as conf:
            pass
Example #22
0
 def load_sp():
     self.server_properties = config_file(self.env['sp_backup']) if load_backup else config_file(self.env['sp'])
     self.server_properties.use_sections(False)
     return self.server_properties[:]
Example #23
0
 def load_sc():
     self.server_config = config_file(self.env['sc_backup']) if load_backup else config_file(self.env['sc'])
     return self.server_config[:]
Example #24
0
 def load_profiles():
     self.profile_config = config_file(self.env['pc'])
     return self.profile_config[:]
Example #25
0
 def load_sc():
     self.server_config = config_file(
         self.env['sc_backup']) if load_backup else config_file(
             self.env['sc'])
     return self.server_config[:]
Example #26
0
    def test_config_file_sections_getandset(self):
        conf = config_file(self.CONFIG_FILES['sections'])
        self.assertTrue(conf._use_sections)

        with self.assertRaises(SyntaxError):
            conf['section'] = 'hello'
        with self.assertRaises(TypeError):
            conf['section':] = 'hello'
        with self.assertRaises(TypeError):
            conf['section'::] = 'hello'
        with self.assertRaises(KeyError):
            conf['section':'option'] = 'hello'
        with self.assertRaises(KeyError):
            conf['section':'option':] = 'hello'
        with self.assertRaises(TypeError):
            conf[:] = 'hello'
        with self.assertRaises(TypeError):
            conf[::] = 'hello'

        with self.assertRaises(TypeError):
            conf[5:] = 'hello'
        with self.assertRaises(TypeError):
            conf[5:5] = 'hello'
        with self.assertRaises(SyntaxError):
            conf[5:5:5] = 'hello'
        with self.assertRaises(TypeError):
            conf['5':5] = 'hello'
        with self.assertRaises(TypeError):
            conf[5:'5'] = 'hello'
        with self.assertRaises(SyntaxError):
            conf[5:'5':5] = 'hello'

        with self.assertRaises(KeyError):
            conf['fakesection']
        with self.assertRaises(KeyError):
            conf['fakesection':]
        with self.assertRaises(KeyError):
            conf['fakesection'::]
        with self.assertRaises(KeyError):
            conf['fakesection':'fake']
        with self.assertRaises(KeyError):
            conf['fakesection':'fake':]

        self.assertIsInstance(conf[:], dict)

        conf.add_section('java')
        conf['java':'java_xmx'] = 512
        conf['java':'java_xms'] = '256'
        conf['java':'thirdcolon':] = 'present'

        self.assertIsInstance(conf[:], dict)
        self.assertEqual(
            conf[:], {
                'java': {
                    'java_xmx': '512',
                    'java_xms': '256',
                    'thirdcolon': 'present'
                }
            })

        self.assertIsInstance(conf['java'], dict)
        self.assertEqual(conf['java'], {
            'java_xmx': '512',
            'java_xms': '256',
            'thirdcolon': 'present'
        })

        self.assertEqual(conf['java':], {
            'java_xmx': '512',
            'java_xms': '256',
            'thirdcolon': 'present'
        })

        self.assertEqual(conf['java':'java_xmx'], '512')
        self.assertEqual(conf['java':'java_xms'], '256')

        self.assertEqual(conf['java':'madeup':768], 768)
        self.assertEqual(conf['java':'fake':'attr'], 'attr')

        with self.assertRaises(TypeError):
            conf['java':] = 'hello'
        with self.assertRaises(TypeError):
            conf['java'::] = 'hello'
        with self.assertRaises(TypeError):
            conf[::] = 'hello'
        with self.assertRaises(SyntaxError):
            conf['java':'second':'third'] = 'hello'

        with self.assertRaises(KeyError):
            conf['java':'madeup']
        with self.assertRaises(KeyError):
            conf['java':'madeup':]

        with self.assertRaises(SyntaxError):
            conf[5] = 12
        with self.assertRaises(SyntaxError):
            conf[None] = 12
        with self.assertRaises(SyntaxError):
            conf[{}] = 12
        with self.assertRaises(SyntaxError):
            conf[()] = 12

        conf.commit()
        self.assertTrue(os.path.isfile(self.CONFIG_FILES['sections']))

        with config_file(self.CONFIG_FILES['sections']) as conf:
            pass