Beispiel #1
0
def EncryptionOptions():
    return _config([config.StringOption('crypto-key', 'k', None,
                                        short_help='Encryption key'),
                    config.StringOption('hash', None, 'sha512',
                                        short_help='Hash algorithm'),
                    ]
                   )
Beispiel #2
0
    def test_default_configuration_creation(self):
        c = config.DefaultConfiguration()
        self.assertFalse(c.has_option('a'))

        c = config.DefaultConfiguration({'test-option': config.StringOption('test-option')})
        self.assertTrue(c.has_option('test-option'))
        self.assertEqual(c.options()['test-option'].short_name(), None)

        c = config.DefaultConfiguration({'test-option': config.StringOption('test-option', 't')})
        self.assertTrue(c.has_option('test-option'))
        self.assertEqual(c.options()['test-option'].short_name(), 't')
Beispiel #3
0
def S3Options():
    return _config([
            config.StringOption('aws_secret_access_key', None, None,
                                short_help='S3 Secret key'),
            config.StringOption('aws_access_key_id', None, None,
                                short_help='S3 Access key'),
            config.StringOption('proxy', None, None,
                                short_help='HTTP Proxy address'),
            config.StringOption('proxy_port', None, None,
                                short_help='HTTP Proxy port'),
            config.BoolOption('https', None, True,
                                short_help='Use HTTPS with S3'),
                    ])
Beispiel #4
0
def PersistOptions():
    return _config([
            config.StringOption('skip-blocks', None, None,
                                short_help='File containing blocks to skip'),
            config.BoolOption('continue', None, False,
                              short_help='Check list of blocks uploaded'),
                    ])
Beispiel #5
0
    def test_default_configuration_option_getter(self):
        opt = config.StringOption('o-1')
        opt2 = config.StringOption('non-specified-option')
        c = config.DefaultConfiguration({'o-1': opt,
                                         'non-specified-option': opt2})

        opt.set('value')

        self.assertEqual(opt.get(), c.opts.o_1)

        # caller asked for non-existent option
        self.assertRaises(AttributeError,
                          lambda: c.opts.nonexistent_option)

        # user did not provide a value for an existing option
        self.assertRaises(config.RequiredOptionMissingError,
                          lambda: c.opts.non_specified_option)
Beispiel #6
0
    def test_default_configuration_merge(self):
        c1 = config.DefaultConfiguration({'o1': config.StringOption('o1')})
        c2 = config.DefaultConfiguration({'o2': config.StringOption('o2')})

        c3 = c1.merge(c2)

        self.assertTrue(c3.has_option('o1'))
        self.assertTrue(c3.has_option('o2'))

        c4 = config.DefaultConfiguration({'o2': config.StringOption('o2', 'o')})

        self.assertRaises(config.ConflictingMergeError,
                          lambda: c4.merge(c3))

        c5 = c3.merge(c4, allow_override=True)

        self.assertEqual(c5.get_option('o2').short_name(), 'o')
Beispiel #7
0
def GlobalOptions():
    """
    Instantiate a Configuration of global options that apply to
    shastity regardless of which command is running.
    """
    return _config([ config.VerboseOption('verbosity', 'v', verbosity.to_verbosity(logging.DEBUG)),
                     config.IntOption('block-size', None, DEFAULT_BLOCK_SIZE,
                                      short_help='The size in bytes of storage blocks.'),
                     config.StringOption('config', 'c', '~/.shastity',
                                         short_help='Config file.'),
                     ]
                   )
Beispiel #8
0
 def test_string_option(self):
     config.StringOption('testname').parse('test')
     self.assertRaises(config.BadOptionValueType, lambda: config.StringOption('testname').parse(5))
Beispiel #9
0
 def test_required(self):
     self.assertRaises(config.RequiredOptionMissingError,
                       lambda: config.StringOption('testname').get_required())
     self.assertEqual('test', config.StringOption('testname').parse('test').get_required())
Beispiel #10
0
 def test_default(self):
     self.assertEqual(config.StringOption('testname', default='test').get(), 'test')
Beispiel #11
0
 def test_naming(self):
     self.assertEqual(config.StringOption('long-name', 'l').name(), 'long-name')
     self.assertEqual(config.StringOption('long-name', 'l').short_name(), 'l')