move src to src/, make packagable

This commit is contained in:
Victoria Fierce 2022-09-03 14:57:05 +02:00
parent 99f4220a67
commit 55c5bc489c
9 changed files with 111 additions and 19 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
*.swp
Pipfile.lock

View File

@ -1,4 +1,4 @@
# Minecraft Plugin Sync # Minecraft Plugin Manager
mpm is a tool used to maintain the various servers and their plugins on mpm is a tool used to maintain the various servers and their plugins on
play.malloc.gg. play.malloc.gg.
@ -22,16 +22,24 @@ be able to work in other systems where:
- You're trying to upgrade a network to a new minecraft release but can't bring - You're trying to upgrade a network to a new minecraft release but can't bring
all the servers and their plugins along at the same time all the servers and their plugins along at the same time
## Installation
# pip install .
## Usage ## Usage
To use, you'll need to create a `plugins.yml` file, using the same structure as - Create a new plugin repository: `mpm repo add`
the one in this repository. Then, create a versions/ directory Inside each - List repositories: `mpm repo list`
server's plugins/ directory. For example, if your server.jar lives at - Import a package to a repository: `mpm repo import`
`/srv/minecraft/server/`, you'll create
`/srv/minecraft/server/plugins/versions/`. Plugin files are not automatically - Add a server to mpm: `mpm server add`
synchronized between each server's versions directory, though this would be the - List your servers: `mpm server list`
next direction for this tool to go. Versions are managed using simple symlinks, - Add a plugin to a server: `mpm server add-plugin`
- Commit your changes: `mpm server sync`
Documentation is scarce. Sorry about that. Pull requests and wiki editors appreciated.
Versions are managed using simple symlinks,
and they require that the actual .jar files use Semver naming. Any deviation and they require that the actual .jar files use Semver naming. Any deviation
from Semver can result in some really goofy behavior, but for the most part, the from Semver can result in some really goofy behavior, but for the most part, the
majority of plugins available on spigot.org include a compatible string in the majority of plugins available on spigot.org include a compatible string in the
@ -45,8 +53,7 @@ for good measure if you run into this.
## Known Bugs ## Known Bugs
- Sometimes you'll end up with a mismatch between where the symlink goes and the - Bad documentation
version'd filename, usually when you've got a version that goes beyond the - 'mpm' is not an uncommon name
traditional $MAJOR.$MINOR.$PATCH tuple. Just rename your files, I guess.
Maybe you'll find this useful too. Batteries not included. Maybe you'll find this useful too. Batteries not included.

12
pyproject.toml Normal file
View File

@ -0,0 +1,12 @@
[build-system]
requires = ["setuptools", "wheel", "setuptools-pipfile"]
build-backend = "setuptools.build_meta"
[tool.setuptools-pipfile]
[project]
name = "minecraft-package-manager"
version = "0.0.1"
[project.scripts]
mpm = "mpm.main:main"

0
src/mpm/__init__.py Normal file
View File

View File

@ -5,9 +5,9 @@ import sys
import yaml import yaml
import os import os
from repo import Repo from mpm.repo import Repo
from server import Server from mpm.server import Server
from model import * from mpm.model import *
try: try:
from yaml import CLoader as Loader, CDumper as Dumper from yaml import CLoader as Loader, CDumper as Dumper
@ -23,7 +23,7 @@ class Config():
def __init__(self, path): def __init__(self, path):
if path is None: if path is None:
path = './mpm.yaml' path = os.path.expanduser('~/mpm.yaml')
self.path = path self.path = path
with open(path, 'r') as fd: with open(path, 'r') as fd:
self.yaml = yaml.load(fd, Loader=Loader) self.yaml = yaml.load(fd, Loader=Loader)

View File

@ -3,8 +3,6 @@ from functools import total_ordering
import os import os
import re import re
#version_pattern = re.compile('^(?P<name>.*)-(?P<version>[^-]+)(?P<extra>-[^-]+)?\.jar$')
version_pattern = re.compile('^(?P<name>.*)-(?P<version>[^-]+(?:-[^-]+)?)\.jar$')
version_pattern = re.compile('^(?P<name>.+)-(?P<version>(?:\.?\d+)+).+jar$') version_pattern = re.compile('^(?P<name>.+)-(?P<version>(?:\.?\d+)+).+jar$')
@total_ordering @total_ordering

73
src/mpm/plugin-sync.py Executable file
View File

@ -0,0 +1,73 @@
#!/bin/env python
import yaml
import os
import sys
from model import *
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
conf = yaml.load(open('plugins.yml', 'r'), Loader=Loader)
for (serverName,server) in conf['servers'].items():
changeset = []
if len(sys.argv) > 1 and serverName not in sys.argv[1:]:
continue
if 'pluginPath' not in server:
continue
if not os.path.exists(server['pluginPath']):
print("Missing plugin path for {}: {}".format(serverName, server['pluginPath']))
else:
print("=== Updating server {}".format(serverName))
pluginSpecs = {}
for inherited in server.get('inherit', ()):
for inheritedPlugin in conf['servers'][inherited]['plugins']:
pluginSpecs[inheritedPlugin['name']] = PluginSpec(inheritedPlugin['name'], str(inheritedPlugin.get('version', '*')))
for pluginConf in server.get('plugins', ()):
pluginSpecs[pluginConf['name']] = PluginSpec(pluginConf['name'], str(pluginConf.get('version', '*')))
repo = Repo(server['pluginPath'], pluginSpecs.values())
outdatedLinks = []
missing = []
installed = []
unmanaged = []
conflicts = []
for state in repo.pluginStates():
if isinstance(state, OutdatedSymlink):
outdatedLinks.append(state)
elif isinstance(state, Installed):
installed.append(state)
elif isinstance(state, MissingVersions):
missing.append(state)
elif isinstance(state, UnmanagedFile):
unmanaged.append(state)
elif isinstance(state, SymlinkConflict):
conflicts.append(state)
print("Installed plugins:")
for state in sorted(installed):
print("\t{} {}: {}".format(state.plugin.name, state.plugin.versionSpec, state.currentVersion))
print("Oudated symlinks:")
for state in sorted(outdatedLinks):
print("\t{} {}: Current: {} Wanted: {}".format(state.plugin.name, state.plugin.versionSpec, state.currentVersion, state.wantedVersion))
print("Missing plugins:")
for state in sorted(missing):
print("\t{}: {}".format(state.plugin.name, state.plugin.versionSpec))
print("Unmanaged files:")
for state in sorted(unmanaged):
print("\t{}".format(state.filename))
print("Symlink Conflicts:")
for state in sorted(conflicts):
print("\t{}.jar".format(state.plugin.name))
if len(outdatedLinks) > 0:
print("Apply changes? [y/N]")
answer = input().lower()
if answer == "y":
for state in outdatedLinks:
repo.updateSymlinkForPlugin(state.plugin, state.wantedVersion)
else:
print("Not applying changes.")

View File

@ -1,5 +1,5 @@
import os import os
from model import * from mpm.model import *
import shutil import shutil
class Repo: class Repo:

View File

@ -1,4 +1,4 @@
from model import * from mpm.model import *
import shutil import shutil
class Server: class Server: