Exemple #1
0
def main():
    args = parse_args()

    if args.verbosity > 0:
        levels = [logging.INFO, logging.DEBUG]
        if args.verbosity > len(levels):
            level = levels[-1]
        else:
            level = levels[args.verbosity - 1]

        handler = logging.StreamHandler(sys.stderr)

        for name in ['blivet', 'program']:
            logger = logging.getLogger(name)
            logger.setLevel(level)
            logger.addHandler(handler)

    expr = config2json(args.nixos_config,
                       is_json=args.is_json,
                       verbose=args.verbosity > 0)

    devtree = DeviceTree()
    devtree.populate(expr, for_mounting=args.mount is not None)

    if args.dry_run:
        print(devtree.devices)
    elif args.mount is not None:
        devtree.mount(args.mount)
    else:
        devtree.realize()
Exemple #2
0
    def test_help_formatting(self):
        with patch('sys.stdout', io.StringIO()) as stdout_io, \
             patch('sys.stderr', io.StringIO()) as stderr_io, \
             patch('sys.exit'):
            parse_args(['--help'])
            stdout_io.seek(0)
            stdout = stdout_io.read()
            stderr_io.seek(0)
            stderr = stderr_io.read()

        for expect in [
            "[-m[SYSROOT]]",
            "-m[SYSROOT], --mount[=SYSROOT]",
        ]:
            self.assertIn(expect, stdout)

        for expect in [
            "the following arguments are required: nixos_config",
            "[-m[SYSROOT]]",
        ]:
            self.assertIn(expect, stderr)
Exemple #3
0
 def test_mount_defaults_to_none(self):
     result = parse_args([self.cfg])
     self.assertIn('mount', result)
     self.assertIsNone(result.mount)
Exemple #4
0
 def test_long_mount_without_sysroot(self):
     result = parse_args(['--mount', self.cfg])
     self.assertIn('mount', result)
     self.assertEqual('/mnt', result.mount)
Exemple #5
0
 def test_short_mount_with_sysroot(self):
     result = parse_args(['-m/foo', self.cfg])
     self.assertIn('mount', result)
     self.assertEqual('/foo', result.mount)