Create BlockDeviceCmd object

This creates a BlockDeviceCmd object to hold the main() function.
This doesn't really do anything different right now, but sets a base
for using argparse subparsers to handle the command-line

Change-Id: I4acf95ff4d554a3b4e7e2244ab1706631b98458f
This commit is contained in:
Ian Wienand 2017-05-02 14:24:35 +10:00
parent a06c610a8c
commit ff5b30db8a

View File

@ -21,8 +21,12 @@ import yaml
from diskimage_builder.block_device.blockdevice import BlockDevice
from diskimage_builder import logging_config
logger = logging.getLogger(__name__)
def generate_phase_doc():
class BlockDeviceCmd(object):
def generate_phase_doc(self):
phase_doc = ""
bdattrs = dir(BlockDevice)
for attr in bdattrs:
@ -33,11 +37,9 @@ def generate_phase_doc():
phase_doc += " " + method.__doc__.split("\n")[0] + "\n"
return phase_doc
def main():
def main(self):
logging_config.setup()
logger = logging.getLogger(__name__)
phase_doc = generate_phase_doc()
phase_doc = self.generate_phase_doc()
parser = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
@ -46,8 +48,9 @@ def main():
parser.add_argument('--phase', required=True,
help="phase to execute")
parser.add_argument('--params', required=False,
help="YAML file containing parameters for block-device"
"handling. Default is DIB_BLOCK_DEVICE_PARAMS_YAML")
help="YAML file containing parameters for "
"block-device handling. Default is "
"DIB_BLOCK_DEVICE_PARAMS_YAML")
parser.add_argument('--symbol', required=False,
help="symbol to query for getval")
args = parser.parse_args()
@ -57,7 +60,8 @@ def main():
if 'DIB_BLOCK_DEVICE_PARAMS_YAML' in os.environ:
param_file = os.environ['DIB_BLOCK_DEVICE_PARAMS_YAML']
else:
parser.error("DIB_BLOCK_DEVICE_PARAMS_YAML or --params not set")
parser.error(
"DIB_BLOCK_DEVICE_PARAMS_YAML or --params not set")
else:
param_file = args.params
logger.info("params [%s]" % param_file)
@ -84,7 +88,10 @@ def main():
logger.error("phase [%s] does not exists" % args.phase)
return 1
return 0
def main():
bdc = BlockDeviceCmd()
return bdc.main()
if __name__ == "__main__":
main()
sys.exit(main())