class TestCascadingConfigBasic(TestToolsFilesystem):
    def setUp(self):
        self.makeTempdir()
        self.ap = DefaultFreeArgumentParser()
        self.ap.add_argument('--sneeze', action='store_true', default=False)
        self.ap.add_argument('--eructate', default=[], type=str)

    def test_reading_env(self):
        argv = []
        env = {'EFFLUVIA_SNEEZE': 'True'}
        cc = CascadingConfig('effluvia', self.ap, argv=argv, env=env)
        config, args = cc.parse()
        self.assertTrue(config.sneeze)
class TestCascadingConfigBasic(TestToolsFilesystem):

    def setUp(self):
        self.makeTempdir()
        self.ap = DefaultFreeArgumentParser()
        self.ap.add_argument('--sneeze', action='store_true', default=False)
        self.ap.add_argument('--eructate', default=[], type=str)

    def test_reading_env(self):
        argv = []
        env = {'EFFLUVIA_SNEEZE': 'True'}
        cc = CascadingConfig('effluvia', self.ap, argv=argv, env=env)
        config, args = cc.parse()
        self.assertTrue(config.sneeze)
    def test_basic_argv(self):
        ap = DefaultFreeArgumentParser()
        ap.add_argument('--source', default='', action='append', type=str)

        c = Namespace(
            tag='tag',
            argparser=ap,
            argv='--source /some/path'.split(),
            env=dict(),
            cfg='',
            exp_config=Namespace(source=['/some/path']),
            exp_args=[],)
        cc = CascadingConfig(c.tag, c.argparser, argv=c.argv, env=c.env)
        config, args = cc.parse()
        self.assertEqual(c.exp_config, config)
        self.assertEqual(c.exp_args, args)
    def test_defaults_returned(self):
        ap = DefaultFreeArgumentParser()
        ap.add_argument('--configfile', default=None, type=str)
        ap.add_argument('--size', default=9, type=int)

        c = Namespace(
            tag='tag',
            argparser=ap,
            argv=''.split(),
            env=dict(),
            cfg='',
            exp_config=Namespace(size=9),
            exp_args=[],)

        cc = CascadingConfig(c.tag, c.argparser, argv=c.argv, env=c.env)
        config, args = cc.parse()
        self.assertEqual(c.exp_config.size, config.size)
    def test_basic_argv(self):
        ap = DefaultFreeArgumentParser()
        ap.add_argument('--source', default='', action='append', type=str)

        c = Namespace(
            tag='tag',
            argparser=ap,
            argv='--source /some/path'.split(),
            env=dict(),
            cfg='',
            exp_config=Namespace(source=['/some/path']),
            exp_args=[],
        )
        cc = CascadingConfig(c.tag, c.argparser, argv=c.argv, env=c.env)
        config, args = cc.parse()
        self.assertEqual(c.exp_config, config)
        self.assertEqual(c.exp_args, args)
    def test_cfg_is_read_passed_by_env(self):
        ap = DefaultFreeArgumentParser()
        ap.add_argument('--configfile', default=None, type=str)
        ap.add_argument('--size', default=9, type=int)

        c = Namespace(
            tag='tag',
            argparser=ap,
            argv=''.split(),
            env=dict(),
            cfg='[tag]\nsize = 8',
            exp_config=Namespace(size=8),
            exp_args=[],)

        self.writeconfig(c)
        c.env.setdefault('TAG_CONFIGFILE', c.configfile)
        cc = CascadingConfig(c.tag, c.argparser, argv=c.argv, env=c.env)
        config, args = cc.parse()
        self.assertEqual(c.exp_config.size, config.size)
    def test_precedence_argv_env_cfg(self):
        ap = DefaultFreeArgumentParser()
        ap.add_argument('--configfile', default=None, type=str)
        ap.add_argument('--size', default=9, type=int)

        import logging
        logging.getLogger().setLevel(logging.DEBUG)
        c = Namespace(
            tag='tag',
            argparser=ap,
            argv='--size 6'.split(),
            env=dict(TAG_SIZE=7, ),
            cfg='[tag]\nsize = 8',
            exp_config=Namespace(size=6),
            exp_args=[],)
        self.writeconfig(c)
        c.argv.extend(['--configfile', c.configfile])
        cc = CascadingConfig(c.tag, c.argparser, argv=c.argv, env=c.env)
        config, args = cc.parse()
        self.assertEqual(c.exp_config.size, config.size)
    def test_defaults_returned(self):
        ap = DefaultFreeArgumentParser()
        ap.add_argument('--configfile', default=None, type=str)
        ap.add_argument('--size', default=9, type=int)

        c = Namespace(
            tag='tag',
            argparser=ap,
            argv=''.split(),
            env=dict(),
            cfg='',
            exp_config=Namespace(size=9),
            exp_args=[],
        )

        cc = CascadingConfig(c.tag, c.argparser, argv=c.argv, env=c.env)
        config, args = cc.parse()
        self.assertEqual(c.exp_config.size, config.size)
    def test_cfg_is_read_passed_by_env(self):
        ap = DefaultFreeArgumentParser()
        ap.add_argument('--configfile', default=None, type=str)
        ap.add_argument('--size', default=9, type=int)

        c = Namespace(
            tag='tag',
            argparser=ap,
            argv=''.split(),
            env=dict(),
            cfg='[tag]\nsize = 8',
            exp_config=Namespace(size=8),
            exp_args=[],
        )

        self.writeconfig(c)
        c.env.setdefault('TAG_CONFIGFILE', c.configfile)
        cc = CascadingConfig(c.tag, c.argparser, argv=c.argv, env=c.env)
        config, args = cc.parse()
        self.assertEqual(c.exp_config.size, config.size)
    def test_precedence_argv_env_cfg(self):
        ap = DefaultFreeArgumentParser()
        ap.add_argument('--configfile', default=None, type=str)
        ap.add_argument('--size', default=9, type=int)

        import logging
        logging.getLogger().setLevel(logging.DEBUG)
        c = Namespace(
            tag='tag',
            argparser=ap,
            argv='--size 6'.split(),
            env=dict(TAG_SIZE=7, ),
            cfg='[tag]\nsize = 8',
            exp_config=Namespace(size=6),
            exp_args=[],
        )
        self.writeconfig(c)
        c.argv.extend(['--configfile', c.configfile])
        cc = CascadingConfig(c.tag, c.argparser, argv=c.argv, env=c.env)
        config, args = cc.parse()
        self.assertEqual(c.exp_config.size, config.size)
 def setUp(self):
     self.makeTempdir()
     self.ap = DefaultFreeArgumentParser()
     self.ap.add_argument('--sneeze', action='store_true', default=False)
     self.ap.add_argument('--eructate', default=[], type=str)
 def setUp(self):
     self.makeTempdir()
     self.ap = DefaultFreeArgumentParser()
     self.ap.add_argument('--sneeze', action='store_true', default=False)
     self.ap.add_argument('--eructate', default=[], type=str)
 def setUp(self):
     self.ap = DefaultFreeArgumentParser()
 def test_basic(self):
     ap = DefaultFreeArgumentParser()
     self.assertIsInstance(ap, argparse.ArgumentParser)
     self.assertIsInstance(ap, DefaultFreeArgumentParser)
Exemple #15
0
def collectconfiguration(tag, argv):
    '''main specification of command-line (and config file) shape'''

    ap = DefaultFreeArgumentParser()
    ap.add_argument('--sourcedir', '--source-dir', '--source-directory',
                    '-s',
                    default=[], action=DirectoriesExist,
                    help='a directory containing LDP source documents')

    ap.add_argument('--pubdir', '--output', '--outputdir', '--outdir',
                    '-o',
                    default=None, action=DirectoryExists,
                    help='a directory containing LDP output documents')

    ap.add_argument('--builddir', '--build-dir', '--build-directory',
                    '-d',
                    default=None, action=DirectoryExists,
                    help='a scratch directory used for building')

    ap.add_argument('--configfile', '--config-file', '--cfg',
                    '-c',
                    default=DEFAULT_CONFIGFILE,
                    type=arg_isreadablefile,
                    help='a configuration file')

    ap.add_argument('--loglevel',
                    default=logging.ERROR, type=arg_isloglevel,
                    help='set the loglevel')

    ap.add_argument('--verbose',
                    action=StoreTrueOrNargBool, nargs='?', default=False,
                    help='more info in --list/--detail [%(default)s]')

    ap.add_argument('--skip',
                    default=[], action='append', type=str,
                    help='skip this stem during processing')

    ap.add_argument('--resources',
                    default=['images', 'resources'], action='append', type=str,
                    help='subdirs to copy during build [%(default)s]')

    # -- and the distinct, mutually exclusive actions this script can perform
    #
    g = ap.add_mutually_exclusive_group()
    g.add_argument('--publish',
                   '-p',
                   action='store_true', default=False,
                   help='build and publish LDP documentation [%(default)s]')

    g.add_argument('--build',
                   '-b',
                   action='store_true', default=False,
                   help='build LDP documentation [%(default)s]')

    g.add_argument('--script',
                   '-S',
                   action='store_true', default=False,
                   help='dump runnable script [%(default)s]')

    g.add_argument('--detail', '--list',
                   '-l',
                   action='store_true', default=False,
                   help='list elements of LDP system [%(default)s]')

    g.add_argument('--summary',
                   '-t',
                   action='store_true', default=False,
                   help='dump inventory summary report [%(default)s]')

    g.add_argument('--doctypes', '--formats', '--format',
                   '--list-doctypes', '--list-formats',
                   '-T',
                   action='store_true', default=False,
                   help='show supported doctypes [%(default)s]')

    g.add_argument('--statustypes', '--list-statustypes',
                   action='store_true', default=False,
                   help='show status types and classes [%(default)s]')

    g.add_argument('--version',
                   '-V',
                   action='store_true', default=False,
                   help='print out the version number [%(default)s]')

    # -- collect up the distributed configuration fragments
    #
    for cls in tldp.typeguesser.knowndoctypes:
        argparse_method = getattr(cls, 'argparse', None)
        if argparse_method:
            argparse_method(ap)

    cc = CascadingConfig(tag, ap, argv)
    config, args = cc.parse()
    return config, args
Exemple #16
0
def collectconfiguration(tag, argv):
    '''main specification of command-line (and config file) shape'''

    ap = DefaultFreeArgumentParser()
    ap.add_argument('--sourcedir',
                    '--source-dir',
                    '--source-directory',
                    '-s',
                    default=[],
                    action=DirectoriesExist,
                    help='a directory containing LDP source documents')

    ap.add_argument('--pubdir',
                    '--output',
                    '--outputdir',
                    '--outdir',
                    '-o',
                    default=None,
                    action=DirectoryExists,
                    help='a directory containing LDP output documents')

    ap.add_argument('--builddir',
                    '--build-dir',
                    '--build-directory',
                    '-d',
                    default=None,
                    action=DirectoryExists,
                    help='a scratch directory used for building')

    ap.add_argument('--configfile',
                    '--config-file',
                    '--cfg',
                    '-c',
                    default=DEFAULT_CONFIGFILE,
                    type=arg_isreadablefile,
                    help='a configuration file')

    ap.add_argument('--loglevel',
                    default=logging.ERROR,
                    type=arg_isloglevel,
                    help='set the loglevel')

    ap.add_argument('--verbose',
                    action=StoreTrueOrNargBool,
                    nargs='?',
                    default=False,
                    help='more info in --list/--detail [%(default)s]')

    ap.add_argument('--skip',
                    default=[],
                    action='append',
                    type=str,
                    help='skip this stem during processing')

    ap.add_argument('--resources',
                    default=['images', 'resources'],
                    action='append',
                    type=str,
                    help='subdirs to copy during build [%(default)s]')

    # -- and the distinct, mutually exclusive actions this script can perform
    #
    g = ap.add_mutually_exclusive_group()
    g.add_argument('--publish',
                   '-p',
                   action='store_true',
                   default=False,
                   help='build and publish LDP documentation [%(default)s]')

    g.add_argument('--build',
                   '-b',
                   action='store_true',
                   default=False,
                   help='build LDP documentation [%(default)s]')

    g.add_argument('--script',
                   '-S',
                   action='store_true',
                   default=False,
                   help='dump runnable script [%(default)s]')

    g.add_argument('--detail',
                   '--list',
                   '-l',
                   action='store_true',
                   default=False,
                   help='list elements of LDP system [%(default)s]')

    g.add_argument('--summary',
                   '-t',
                   action='store_true',
                   default=False,
                   help='dump inventory summary report [%(default)s]')

    g.add_argument('--doctypes',
                   '--formats',
                   '--format',
                   '--list-doctypes',
                   '--list-formats',
                   '-T',
                   action='store_true',
                   default=False,
                   help='show supported doctypes [%(default)s]')

    g.add_argument('--statustypes',
                   '--list-statustypes',
                   action='store_true',
                   default=False,
                   help='show status types and classes [%(default)s]')

    # -- collect up the distributed configuration fragments
    #
    for cls in tldp.typeguesser.knowndoctypes:
        argparse_method = getattr(cls, 'argparse', None)
        if argparse_method:
            argparse_method(ap)

    cc = CascadingConfig(tag, ap, argv)
    config, args = cc.parse()
    return config, args