dooke/usr/lib/dooke/dooke.py

123 lines
2.5 KiB
Python
Executable File

#!/usr/bin/python3
import gi, os, sys
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk, GLib, Gio, GObject, GdkPixbuf
from webengine.gtk3 import WebEngine, create_setting, create_hmr_server, create_bridge
from _window import Window
from _docker import Docker
APP_ID = 'io.github.yutent.dooke'
__dir__ = os.path.dirname(os.path.realpath(__file__))
web_root = os.path.join(__dir__, './webapp')
client = Docker()
class Application(Gtk.Application):
def __init__(self):
Gtk.Application.__init__(self, application_id = APP_ID)
self.window = Window()
web = WebEngine(self.window)
web.set_root(web_root)
if os.getenv('RUN_ENV') == 'development':
setting = create_setting({"devtools": True})
hmr = create_hmr_server()
web.use(setting).use(hmr)
bridge = create_bridge()
web.use(bridge, self.bridge_handler)
web.connect('quit', self.quit_all)
web.load()
self.window.add(web)
def bridge_handler(self, ev, params):
_error = None
output = None
match ev:
case 'docker':
action = params['action']
match action:
case 'containers':
all = params['all'] or False
output = client.containers(all)
case 'images':
output = client.images()
case 'services':
output = client.services()
case 'service-stop':
_error = client.stop_service(params.get('config'))
case 'volumes':
output = client.volumes()
case 'volume-prune':
_error = client.prune_volumes()
case 'volume-rm':
_error = client.rm_volume(params.get('name'))
case 'networks':
output = client.networks()
case 'network-prune':
_error = client.prune_networks()
case 'network-rm':
_error = client.rm_network(params.get('id'))
case 'start':
_error = client.start(params.get('id'))
case 'stop':
_error = client.stop(params.get('id'))
case 'rm':
_error = client.rm(params.get('id'))
case 'rmi':
_error = client.rmi(params.get('id'))
return (_error, output)
def do_activate(self):
self.set_app_menu(None)
self.set_menubar(None)
self.add_window(self.window)
self.window.show_all()
def quit_all(self, widget):
self.remove_window(self.window)
if __name__ == "__main__":
try:
app = Application()
app.run(sys.argv)
except KeyboardInterrupt:
pass
docker 管理面板。
JavaScript 72%
Python 17.4%
CSS 7%
HTML 1.9%
Shell 1.7%