def install(name, path):
"""
Install inventories.
"""
if not name:
update()
return
if not name.isalnum():
fatal("Your inventory name should only contains alphanumeric "
"characters.")
dest_path = os.path.join(inventory_path, name)
if os.path.exists(dest_path):
update_inventory(name, dest_path)
return
if not path:
fatal("You must specify a path to a local directory or an URL to a "
"git repository to install a new inventory.")
if os.path.exists(path) and os.path.isdir(path):
if not os.path.exists(os.path.dirname(dest_path)):
os.mkdir(os.path.dirname(dest_path))
os.symlink(path, dest_path)
else:
click.echo('We will clone %s in %s\n' % (path, dest_path))
try:
vgit('clone', path, dest_path)
except ErrorReturnCode:
fatal("Unable to install the inventory %s." % name)
success("The %s inventory has been installed." % name)
评论列表
文章目录