Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 25 additions & 6 deletions leapp/cli/__init__.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,37 @@

import os
import pkgutil
import socket

from leapp.utils.clicmd import command, command_opt
from leapp.cli import upgrade
from leapp import VERSION
from leapp.cli import commands
from leapp.utils.clicmd import command


@command('')
def cli(args): # noqa; pylint: disable=unused-argument
pass
def cli(args): # noqa; pylint: disable=unused-argument
"""
Top level base command dummy function
"""


def _load_commands(base_command):
pkgdir = os.path.dirname(commands.__file__)
for entry in os.listdir(pkgdir):
entry_path = os.path.join(pkgdir, entry)
if os.path.isdir(entry_path) and os.path.isfile(os.path.join(entry_path, '__init__.py')):
# We found a package - We will import it and get the `register` symbol and check if it is callable.
package_name = 'leapp.cli.commands.{}'.format(entry)
package = pkgutil.get_loader(package_name).load_module(package_name)
register = getattr(package, 'register', None)
if callable(register):
register(base_command)


def main():
"""
leapp entry point
"""
os.environ['LEAPP_HOSTNAME'] = socket.getfqdn()
for cmd in [upgrade.list_runs, upgrade.preupgrade, upgrade.upgrade, upgrade.answer, upgrade.rerun]:
cli.command.add_sub(cmd.command)
_load_commands(cli.command)
cli.command.execute('leapp version {}'.format(VERSION))
Empty file added leapp/cli/commands/__init__.py
Empty file.
Loading