# nobodd.prep

This module contains the implementation (and entry point) of the nobodd-prep application.

## Application functions

nobodd.prep.main(args=None)

  The main entry point for the nobodd-prep application. Takes args, the sequence of command line arguments to parse. Returns the exit code of the application (0 for a normal exit, and non-zero otherwise).

  If `DEBUG=1` is found in the application’s environment, top-level exceptions will be printed with a full back-trace. `DEBUG=2` will launch PDB in post-mortem mode.

nobodd.prep.get_parser()

  Returns the command line parser for the application, pre-configured with defaults from the application’s configuration file(s). See `ConfigArgumentParser()` for more information.

nobodd.prep.prepare_image(conf)

  Given the script’s configuration in conf, an `argparse.Namespace`, resize the target image, and re-write the kernel command line within its boot partition to point to the configured NBD server and share.

nobodd.prep.remove_items(fs, conf)

  In fs, a `FatFileSystem`, remove all items in the `list` conf.remove, where conf is the script’s configuration.

  If any item is a directory, it and all files under it will be removed recursively. If an item in to_remove does not exist, a warning will be printed, but no error is raised.

nobodd.prep.copy_items(fs, conf)

  Copy all `Path` items in the `list` conf.copy into fs, a `FatFileSystem`, where conf is the script’s configuration.

  If an item is a directory, it and all files under it will be copied recursively. If an item is a hard-link or a sym-link it will be copied as a regular file (since FAT does not support links). If an item does not exist, an `OSError` will be raised. This is in contrast to `to_remove()` since it is assumed that control over the source file-system is under the caller’s control, which is not the case in `to_remove()`.

nobodd.prep.rewrite_cmdline(fs, conf)

  Given the script’s configuration conf, find the file conf.cmdline containing the kernel command-line in the `FatFileSystem` fs, and re-write it to point the NBD share specified.

nobodd.prep.detect_partitions(conf)

  Given the script’s configuration in conf, an `argparse.Namespace`, open the target image, and attempt to detect the root and/or boot partition.