예제 #1
0
파일: app.py 프로젝트: macanhhuy/setman
def main(available_settings=None):
    available_settings = available_settings or settings.available_settings
    app_name = available_settings.app_name

    if not app_name:
        print('Found %d available setting(s)' % len(available_settings))

    for mixed in available_settings:
        if is_settings_container(mixed):
            main(mixed)
        else:
            setting = mixed
            values = getattr(settings, app_name) if app_name else settings
            old_value = getattr(values, setting.name)

            print('\n%s (%s)' % (setting.label, setting.help_text))
            new_value = raw_input('Enter new value, old value is %r: ' % \
                                  old_value)

            if not new_value:
                new_value = old_value

            setattr(values, setting.name, new_value)

    if not available_settings.app_name:
        if settings.is_valid():
            settings.save()
            print('\nSettings were saved! Exit...')
        else:
            print('\nCannot save settings, error:\n%s' % settings.error)
예제 #2
0
def main(available_settings=None):
    available_settings = available_settings or settings.available_settings
    app_name = available_settings.app_name

    if not app_name:
        print('Found %d available setting(s)' % len(available_settings))

    for mixed in available_settings:
        if is_settings_container(mixed):
            main(mixed)
        else:
            setting = mixed
            values = getattr(settings, app_name) if app_name else settings
            old_value = getattr(values, setting.name)

            print('\n%s (%s)' % (setting.label, setting.help_text))
            new_value = raw_input('Enter new value, old value is %r: ' % \
                                  old_value)

            if not new_value:
                new_value = old_value

            setattr(values, setting.name, new_value)

    if not available_settings.app_name:
        if settings.is_valid():
            settings.save()
            print('\nSettings were saved! Exit...')
        else:
            print('\nCannot save settings, error:\n%s' % settings.error)
예제 #3
0
    def test_convert_value(self):
        settings.max_processes = '16'
        settings.save()

        self.assertEqual(settings.max_processes, 16)

        settings.max_processes = 'abc'
        self.assertFalse(settings.is_valid())
예제 #4
0
    def test_validators(self):
        settings.max_processes = 24
        self.assertFalse(settings.is_valid())
        self.assertRaises(ValueError, settings.save)

        settings.max_processes = 4
        settings.hosts_file = 'something'
        self.assertFalse(settings.is_valid())
        self.assertRaises(ValueError, settings.save)

        settings.max_processes = 4
        settings.hosts_file = '/etc/hosts.new'
        settings.hourly_rate = Decimal('0.5')
        self.assertFalse(settings.is_valid())
        self.assertRaises(ValueError, settings.save)

        settings.hourly_rate = Decimal('12.725')
        self.assertFalse(settings.is_valid())
        self.assertRaises(ValueError, settings.save)

        settings.hourly_rate = Decimal('1200.50')
        self.assertFalse(settings.is_valid())
        self.assertRaises(ValueError, settings.save)

        settings.hourly_rate = Decimal('10.00')
        self.assertTrue(settings.is_valid())
        settings.save()
예제 #5
0
 def test_validation(self):
     settings.INT_SETTING = 12
     self.assertFalse(settings.is_valid())
     self.assertRaises(ValueError, settings.save)