emsm.core.worlds

exception emsm.core.worlds.WorldError[source]

Bases: Exception

Base class for all other exceptions in this module.

exception emsm.core.worlds.WorldStatusError(world, is_online)[source]

Bases: emsm.core.worlds.WorldError

Raised, if a task can not be done because of the current status of the world (online or not online).

exception emsm.core.worlds.WorldIsOnlineError(world)[source]

Bases: emsm.core.worlds.WorldStatusError

Raised if a world is online but should be offline.

exception emsm.core.worlds.WorldIsOfflineError(world)[source]

Bases: emsm.core.worlds.WorldStatusError

Raised if a world is offline but should be online.

exception emsm.core.worlds.WorldStartFailed(world)[source]

Bases: emsm.core.worlds.WorldError

Raised if the world start failed.

exception emsm.core.worlds.WorldStopFailed(world)[source]

Bases: emsm.core.worlds.WorldError

Raised if the world stop failed.

exception emsm.core.worlds.WorldCommandTimeout(world='')[source]

Bases: emsm.core.worlds.WorldError

Raised, when the server did not react in x seconds.

class emsm.core.worlds.WorldWrapper(app, name)[source]

Bases: object

Provides methods to handle a minecraft world like start(), stop(), restart(), …

The WorldWrapper is initialised using the configuration options in the section with the name name in the server.conf configuration file.

address()[source]

Returns the binding (ip, port) of the world. If those values can not be retrieved, (None, None) is returned.

conf()[source]

The configuration section of this world in the name.world.conf configuration file:

.. code-block:: ini
# morpheus.world.conf [world] server = vanilla 1.8
directory()[source]

Returns the directory that contains all world data generated by the minecraft server.

If the world is run by the mojang minecraft server, this directory contains the server.properties, whitelist.json, … files.

install()[source]

Creates the directory of the world.

See also

  • meth:directory
is_installed()[source]

Returns True if the directory() of the world exists, otherwise False.

is_offline()[source]

Returns True if the world is currently not running.

is_online()[source]

Returns True if the world is currently running.

kill_processes()[source]

Kills all processes with a pid in pids().

Signals:

Raises:WorldStopFailed – if the process could not be killed.

See also

latest_log()[source]

Returns the log of the world since the last start. If the logfile does not exist, an empty string will be returned.

name()[source]

The name of the world.

This is the name of the configuration section in worlds.conf and the folder name in the worlds directory.

open_console()[source]

Opens all screen sessions whichs pid is in pids().

Raises:WorldIsOfflineError – if the world is offline.
pids()[source]

Returns a list with the pids of the screen sessions with the name screen_name().

restart(force_restart=False, stop_args=None)[source]

Restarts the server.

Parameters:
  • force_restart (bool) – Forces the stop of the server by calling kill_processes`() if necessary.
  • stop_args (dict) – If provided, these values are passed to stop().

Signals:

Raises:

See also

screen_name()[source]

Returns the name of the screen sessions that run the server of this world.

send_command(server_cmd)[source]

Sends the given command to all screen sessions with the world’s screen name.

Raises:WorldIsOfflineError – if the world is offline.

Warning

There is no guarantee, that the server reacted to the command.

send_command_get_output(server_cmd, timeout=10, poll_intervall=0.2)[source]

Like send_commmand() but checks every poll_intervall seconds, if content has been added to the logfile and returns the change. If no change could be detected after timeout seconds, an error will be raised.

Raises:
server()[source]

The ServerWrapper for the server that runs this world.

set_server(server)[source]

Changes the server that runs this world. The world has to be offline.

Parameters:server (emsm.core.server.ServerWrapper) – The new server
:raises WorldIsOnlineError*
if the world is online.
start(wait_check_time=0.1)[source]

Starts the world if the world is offline. If the world is already online, nothing happens.

Signals:

Parameters:wait_check_time (float) – Time waited, before checking if the server actually started.
Raises:WorldStartFailed – if the world could not be started.
stop(force_stop=False, message=None, delay=None, timeout=None)[source]

Stops the server.

Parameters:
  • message (str) – Send to the world before the stop() command is executed.
  • delay (float) – Time in seconds that is waited between seding the message and executing the :meth`stop` command.
  • timeout (float) – Maximum time in seconds waited for the server stop after executing the stop() command.
  • force_stop (bool) – If true and the server could not be stopped, kill_processes() is called.

Signals:

Raises:WorldStopFailed – if the world could not be stopped.
uninstall()[source]

Stops the world and removes the world directory.

world_about_to_start = <blinker.base.NamedSignal object at 0x7fafff499f98; 'world_about_to_start'>

Signal, that is emitted when a world is about to start.

world_about_to_stop = <blinker.base.NamedSignal object at 0x7fafff4ab080; 'world_about_to_stop'>

Signal, that is emitted when a world is about to be stopped.

world_start_failed = <blinker.base.NamedSignal object at 0x7fafff4ab048; 'world_start_failed'>

Signal, that is emitted when a world could not be started.

world_started = <blinker.base.NamedSignal object at 0x7fafff499fd0; 'world_started'>

Signal, that is emitted when a world has been started.

world_stop_failed = <blinker.base.NamedSignal object at 0x7fafff4ab0f0; 'world_stop_failed'>

Signal, that is emitted when a world could not be stopped.

world_stopped = <blinker.base.NamedSignal object at 0x7fafff4ab0b8; 'world_stopped'>

Signal, that is emitted when a world has been stopped.

world_uninstalled = <blinker.base.NamedSignal object at 0x7fafff499f60; 'world_uninstalled'>

Signal, that is emitted when a world has been uninstalled.

worldpath_to_ospath(rel_path)[source]

Converts rel_path, that is relative to the root directory of the minecraft world, into the absolute path of the operating system.

Example:

>>> # I assume the EMSM root is: "/home/minecraft"
>>> foo.name()
"foo"
>>> foo.worldpath_to_ospath("server.properties")
"/opt/minecraft/worlds/foo/server.properties"

See also

class emsm.core.worlds.WorldManager(app)[source]

Bases: object

Works as a container for the WorldWrapper instances.

get(worldname)[source]

Returns the WorldWrapper for the world with the name worldname or None if there is no world with that name.

get_all()[source]

Returns a list with all loaded worlds.

get_by_pred(pred=None)[source]

Filters the worlds using the predicate pred.

Example:

>>> # All running worlds
>>> wm.get_by_pred(lambda w: w.is_online())
...

See also

get_names()[source]

Returns a list with the names of all worlds.

get_selected()[source]

Returns all worlds that have been selected per command line argument.

load_worlds()[source]

Loads all worlds declared in the worlds.conf configuration file.

See also

  • WorldsConfiguration