cli: pretty++
This commit is contained in:
parent
3c77a3ef33
commit
44c7fb5f03
@ -15,13 +15,25 @@ def list_(ctx):
|
|||||||
for repo in ctx.obj['config'].repositories():
|
for repo in ctx.obj['config'].repositories():
|
||||||
click.echo("{} ({})".format(click.style(repo.name,bold=True), repo.path))
|
click.echo("{} ({})".format(click.style(repo.name,bold=True), repo.path))
|
||||||
rows = []
|
rows = []
|
||||||
|
currentPlugin = None
|
||||||
|
pluginVersions = []
|
||||||
for plugin in sorted(repo.plugins()):
|
for plugin in sorted(repo.plugins()):
|
||||||
|
if currentPlugin != plugin.name:
|
||||||
|
if currentPlugin is not None:
|
||||||
|
rows.append([
|
||||||
|
click.style(currentPlugin, fg='green'),
|
||||||
|
click.style(', '.join(pluginVersions), fg='yellow')
|
||||||
|
])
|
||||||
|
currentPlugin = plugin.name
|
||||||
|
pluginVersions = []
|
||||||
|
pluginVersions.append(str(plugin.version))
|
||||||
|
if currentPlugin is not None:
|
||||||
rows.append([
|
rows.append([
|
||||||
click.style(plugin.name, fg='green'),
|
click.style(currentPlugin, fg='green'),
|
||||||
click.style(str(plugin.version), fg='yellow')
|
click.style(', '.join(pluginVersions), fg='yellow')
|
||||||
])
|
])
|
||||||
if len(rows) > 0:
|
if len(rows) > 0:
|
||||||
click.echo(columnar(rows, ['Plugin', 'Version'], no_borders=True))
|
click.echo(columnar(rows, ['Plugin', 'Versions'], no_borders=True))
|
||||||
else:
|
else:
|
||||||
click.echo("No plugins found.")
|
click.echo("No plugins found.")
|
||||||
for badFile in sorted(repo.badFiles()):
|
for badFile in sorted(repo.badFiles()):
|
||||||
|
@ -2,6 +2,7 @@ import click
|
|||||||
from mpm.model import *
|
from mpm.model import *
|
||||||
import pathlib
|
import pathlib
|
||||||
from mpm.config import ServerParamType
|
from mpm.config import ServerParamType
|
||||||
|
from columnar import columnar
|
||||||
|
|
||||||
@click.group(help='Add, remove, and synchronize Servers')
|
@click.group(help='Add, remove, and synchronize Servers')
|
||||||
def server():
|
def server():
|
||||||
@ -18,8 +19,11 @@ def add(ctx, name, path):
|
|||||||
|
|
||||||
@server.command('list', help='List configured servers')
|
@server.command('list', help='List configured servers')
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
def list_(ctx):
|
@click.argument('servers', type=ServerParamType(), nargs=-1)
|
||||||
for server in ctx.obj['config'].servers():
|
def list_(ctx, servers):
|
||||||
|
if len(servers) == 0:
|
||||||
|
servers = ctx.obj['config'].servers()
|
||||||
|
for server in servers:
|
||||||
click.echo('{} ({}):'.format(server.name, server.path))
|
click.echo('{} ({}):'.format(server.name, server.path))
|
||||||
serverPath = pathlib.Path(server.path)
|
serverPath = pathlib.Path(server.path)
|
||||||
if not serverPath.exists():
|
if not serverPath.exists():
|
||||||
@ -46,22 +50,50 @@ def list_(ctx):
|
|||||||
elif isinstance(state, SymlinkConflict):
|
elif isinstance(state, SymlinkConflict):
|
||||||
conflicts.append(state)
|
conflicts.append(state)
|
||||||
|
|
||||||
click.echo("Installed plugins:")
|
rows = []
|
||||||
for state in sorted(installed):
|
for state in sorted(installed):
|
||||||
click.echo("\t{} {}: {}".format(state.plugin.name, state.plugin.versionSpec, state.currentVersion))
|
rows.append([
|
||||||
click.echo("Oudated symlinks:")
|
state.plugin.name,
|
||||||
|
str(state.plugin.versionSpec),
|
||||||
|
str(state.currentVersion),
|
||||||
|
str(state.currentVersion),
|
||||||
|
])
|
||||||
for state in sorted(outdatedLinks):
|
for state in sorted(outdatedLinks):
|
||||||
click.echo("\t{} {}: Current: {} Wanted: {}".format(state.plugin.name, state.plugin.versionSpec, state.currentVersion, state.wantedVersion))
|
rows.append([
|
||||||
click.echo("Missing plugins:")
|
state.plugin.name,
|
||||||
|
click.style(str(state.wantedVersion), fg='green'),
|
||||||
|
click.style(str(state.currentVersion), fg='yellow'),
|
||||||
|
click.style(str(state.plugin.versionSpec), fg='green')
|
||||||
|
])
|
||||||
for state in sorted(missing):
|
for state in sorted(missing):
|
||||||
click.echo("\t{}: {}".format(state.plugin.name, state.plugin.versionSpec))
|
rows.append([
|
||||||
click.echo("Unmanaged files:")
|
click.style(state.plugin.name, fg='red'),
|
||||||
|
click.style(str(state.plugin.versionSpec), fg='yellow'),
|
||||||
|
click.style('Missing', fg='red'),
|
||||||
|
click.style('Missing', fg='red')
|
||||||
|
])
|
||||||
for state in sorted(unmanaged):
|
for state in sorted(unmanaged):
|
||||||
click.echo("\t{}".format(state.filename))
|
rows.append([
|
||||||
click.echo("Symlink Conflicts:")
|
click.style(state.filename, fg='yellow'),
|
||||||
|
'?',
|
||||||
|
click.style('Unmanaged', fg='yellow', bold=True),
|
||||||
|
''
|
||||||
|
])
|
||||||
for state in sorted(conflicts):
|
for state in sorted(conflicts):
|
||||||
|
rows.append([
|
||||||
|
state.plugin.name,
|
||||||
|
click.style(str(state.plugin.versionSpec), fg='yellow'),
|
||||||
|
click.style('Symlink Conflict', fg='red', bold=True),
|
||||||
|
click.style(str(state.plugin.versionSpec), fg='yellow'),
|
||||||
|
])
|
||||||
click.echo("\t{}.jar".format(state.plugin.name))
|
click.echo("\t{}.jar".format(state.plugin.name))
|
||||||
|
|
||||||
|
if len(rows) > 0:
|
||||||
|
click.echo(columnar(rows, ['Plugin', 'Wanted', 'Installed',
|
||||||
|
'Available'], no_borders=True))
|
||||||
|
else:
|
||||||
|
click.echo(click.style('No plugins configured!', fg='yellow'))
|
||||||
|
|
||||||
@server.command(help='Add a plugin to a server')
|
@server.command(help='Add a plugin to a server')
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
@click.argument('server', type=ServerParamType())
|
@click.argument('server', type=ServerParamType())
|
||||||
@ -100,10 +132,9 @@ def add_plugin(ctx, server, plugins):
|
|||||||
else:
|
else:
|
||||||
click.echo("Cancelled.")
|
click.echo("Cancelled.")
|
||||||
|
|
||||||
|
|
||||||
@server.command(help="Synchronize a server's plugins")
|
@server.command(help="Synchronize a server's plugins")
|
||||||
@click.pass_context
|
@click.pass_context
|
||||||
@click.argument('servers', type=ServerParamType, nargs=-1)
|
@click.argument('servers', type=ServerParamType(), nargs=-1)
|
||||||
def sync(ctx, servers):
|
def sync(ctx, servers):
|
||||||
allServers = ctx.obj['config'].servers()
|
allServers = ctx.obj['config'].servers()
|
||||||
if len(servers) > 0:
|
if len(servers) > 0:
|
||||||
@ -121,17 +152,37 @@ def sync(ctx, servers):
|
|||||||
elif isinstance(state, MissingVersions):
|
elif isinstance(state, MissingVersions):
|
||||||
missing.append(state)
|
missing.append(state)
|
||||||
|
|
||||||
click.echo("Plugins to update:")
|
rows = []
|
||||||
|
|
||||||
for state in sorted(outdatedLinks):
|
for state in sorted(outdatedLinks):
|
||||||
click.echo("\t{} {}: Current: {} Wanted: {}".format(state.plugin.name, state.plugin.versionSpec, state.currentVersion, state.wantedVersion))
|
rows.append([
|
||||||
click.echo("New plugins to install:")
|
state.plugin.name,
|
||||||
|
click.style(str(state.wantedVersion), fg='green'),
|
||||||
|
click.style(str(state.currentVersion), fg='yellow'),
|
||||||
|
click.style(str(state.plugin.versionSpec), fg='green')
|
||||||
|
])
|
||||||
|
|
||||||
for state in sorted(available):
|
for state in sorted(available):
|
||||||
click.echo("\t{}: {}".format(state.plugin.name, state.plugin.version))
|
rows.append([
|
||||||
|
state.plugin.name,
|
||||||
|
click.style(str(state.wantedVersion), fg='green'),
|
||||||
|
click.style('Missing', fg='red'),
|
||||||
|
click.style(str(state.plugin.version), fg='green')
|
||||||
|
])
|
||||||
|
|
||||||
click.echo("Missing plugins:")
|
click.echo("Missing plugins:")
|
||||||
for state in sorted(missing):
|
for state in sorted(missing):
|
||||||
click.echo("\t{} {}".format(click.style(state.plugin.name, fg='red'),
|
rows.append([
|
||||||
click.style(str(state.plugin.versionSpec),
|
click.style(state.plugin.name, fg='red'),
|
||||||
fg='yellow')))
|
click.style(str(state.plugin.versionSpec), fg='yellow'),
|
||||||
|
click.style('Missing', fg='red'),
|
||||||
|
click.style('Missing', fg='red')
|
||||||
|
])
|
||||||
|
|
||||||
|
if len(rows) > 0:
|
||||||
|
click.echo(columnar(rows, ['Plugin', 'Wanted', 'Installed',
|
||||||
|
'Available'], no_borders=True))
|
||||||
|
|
||||||
if len(outdatedLinks) > 0 or len(available) > 0:
|
if len(outdatedLinks) > 0 or len(available) > 0:
|
||||||
click.echo("Apply changes? [y/N]", nl=False)
|
click.echo("Apply changes? [y/N]", nl=False)
|
||||||
answer = click.getchar().lower()
|
answer = click.getchar().lower()
|
||||||
|
@ -83,6 +83,9 @@ class OutdatedSymlink(PluginState):
|
|||||||
self.currentVersion = currentVersion
|
self.currentVersion = currentVersion
|
||||||
self.wantedVersion = wantedVersion
|
self.wantedVersion = wantedVersion
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'OutdatedSymlink({})'.format(self.plugin)
|
||||||
|
|
||||||
class SymlinkConflict(PluginState):
|
class SymlinkConflict(PluginState):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -90,10 +93,17 @@ class MissingVersions(PluginState):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
class Available(PluginState):
|
class Available(PluginState):
|
||||||
def __init__(self, repoPlugin):
|
def __init__(self, repoPlugin, wantedVersion):
|
||||||
super().__init__(repoPlugin)
|
super().__init__(repoPlugin)
|
||||||
|
self.wantedVersion = wantedVersion
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'Available({})'.format(self.plugin)
|
||||||
|
|
||||||
class Installed(PluginState):
|
class Installed(PluginState):
|
||||||
def __init__(self, plugin, currentVersion):
|
def __init__(self, plugin, currentVersion):
|
||||||
super().__init__(plugin)
|
super().__init__(plugin)
|
||||||
self.currentVersion = currentVersion
|
self.currentVersion = currentVersion
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return 'Installed({} @ )'.format(self.plugin, self.currentVersion)
|
||||||
|
@ -42,7 +42,7 @@ class Server:
|
|||||||
yield MissingVersions(plugin)
|
yield MissingVersions(plugin)
|
||||||
else:
|
else:
|
||||||
preferredVersion = list(reversed(sorted(compatibleVersions)))[0]
|
preferredVersion = list(reversed(sorted(compatibleVersions)))[0]
|
||||||
yield Available(preferredVersion)
|
yield Available(preferredVersion, plugin.versionSpec)
|
||||||
else:
|
else:
|
||||||
preferredVersion = list(reversed(sorted(compatibleVersions)))[0]
|
preferredVersion = list(reversed(sorted(compatibleVersions)))[0]
|
||||||
currentVersion = self.currentVersionForPlugin(plugin.name)
|
currentVersion = self.currentVersionForPlugin(plugin.name)
|
||||||
@ -97,4 +97,7 @@ class Server:
|
|||||||
if not os.path.exists(os.path.join(self.pluginPath, 'versions')):
|
if not os.path.exists(os.path.join(self.pluginPath, 'versions')):
|
||||||
os.path.mkdir(os.path.join(self.pluginPath, 'versions'))
|
os.path.mkdir(os.path.join(self.pluginPath, 'versions'))
|
||||||
dest = os.path.join(self.pluginPath, 'versions/{}-{}.jar'.format(plugin.name, plugin.version))
|
dest = os.path.join(self.pluginPath, 'versions/{}-{}.jar'.format(plugin.name, plugin.version))
|
||||||
shutil.copyfile(plugin.path, dest)
|
try:
|
||||||
|
os.link(plugin.path, dest)
|
||||||
|
except Exception:
|
||||||
|
shutil.copyfile(plugin.path, dest)
|
||||||
|
Loading…
Reference in New Issue
Block a user