2023-10-27 13:08:10 +00:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
#
|
|
|
|
|
# This is a small script that tries to replace pgadmin4-runtime as
|
|
|
|
|
# a desktop version of pgadmin4.
|
|
|
|
|
|
|
|
|
|
# pgadmin4-runtime uses NW.js (which is based on Chromium and Node.js) which
|
|
|
|
|
# makes it hard to package in a standard way.
|
|
|
|
|
# pgadmin4-desktop tries to be a simple replacement which just runs pgadmin4
|
|
|
|
|
# in runtime mode but uses Qt6 for the GUI in order to show an icon in the
|
|
|
|
|
# system tray and provide two options: open a new browser window with pgAdmin
|
|
|
|
|
# and quit the application.
|
|
|
|
|
#
|
|
|
|
|
# This script is released under the PostgreSQL License.
|
|
|
|
|
# (C) 2023 Antonio Larrosa <alarrosa@suse.com>
|
|
|
|
|
|
|
|
|
|
import subprocess
|
|
|
|
|
import os
|
|
|
|
|
import os.path
|
|
|
|
|
import uuid
|
|
|
|
|
import socket
|
|
|
|
|
import time
|
|
|
|
|
import sys
|
|
|
|
|
import fcntl
|
Accepting request 1138820 from home:alarrosa:branches:server:database:postgresql
- Update to 8.2
* Supported Database Servers
- PostgreSQL: 12, 13, 14, 15, and 16
- EDB Advanced Server: 12, 13, 14, 15, and 16
* Bundled PostgreSQL Utilities
- psql, pg_dump, pg_dumpall, pg_restore: 16.0
* New features
- Administer pgAdmin Users and Preferences Using the Command
Line Interface (CLI).
- Allow users to convert View/Edit table into a Query tool to
enable editing the SQL generated.
- Added copy server support, allowing the duplication of
existing servers with the option to make certain
modifications.
- Added keep-alive support for SSH sessions when connecting to
a PostgreSQL server via an SSH tunnel.
* Housekeeping
- Ensure that eventlet's subprocess should be used following
the resolution of an issue with Python 3.12 by eventlet.
* Bug fixes
- Fixed an issue where query tool title did not change after
"Save As" until any new change is made.
- Fixed an issue where export servers was not adding extension
if not specified.
- Fixed an issue where pgAdmin imports servers to the wrong
accounts for the external authentication.
- Fixed an issue where an error occurred in the SQL tab when
using an extended index(pgroonga).
- Fixed an issue where changes done to a node using edit
dialog are not reflecting on the properties tab if the
OBS-URL: https://build.opensuse.org/request/show/1138820
OBS-URL: https://build.opensuse.org/package/show/server:database:postgresql/pgadmin4?expand=0&rev=64
2024-01-15 11:11:25 +00:00
|
|
|
from PyQt5.QtWidgets import QApplication, QSystemTrayIcon, QMenu, QSplashScreen, QAction
|
|
|
|
|
from PyQt5.QtGui import QIcon, QPixmap, QImage, QPalette, QPainter
|
|
|
|
|
from PyQt5.QtCore import QTimer, Qt
|
2023-10-27 13:08:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class PGAdminDesktop(QApplication):
|
|
|
|
|
def __init__(self):
|
|
|
|
|
super().__init__(sys.argv)
|
|
|
|
|
self.environ = os.environ
|
|
|
|
|
self.pgadmin_process = None
|
|
|
|
|
self.url = None
|
|
|
|
|
|
|
|
|
|
self.setQuitOnLastWindowClosed(False)
|
|
|
|
|
self.aboutToQuit.connect(self.cleanup)
|
|
|
|
|
self.create_ui()
|
|
|
|
|
|
|
|
|
|
pixmap = self.load_splash_pixmap()
|
|
|
|
|
if pixmap:
|
|
|
|
|
self.splash = QSplashScreen(pixmap)
|
|
|
|
|
self.splash.showMessage("Starting pgAdmin.", Qt.AlignmentFlag.AlignBottom)
|
|
|
|
|
self.splash.show()
|
|
|
|
|
else:
|
|
|
|
|
self.splash = None
|
|
|
|
|
|
|
|
|
|
self.run_pgadmin_server()
|
|
|
|
|
QTimer.singleShot(500, self.open_pgadmin)
|
|
|
|
|
|
|
|
|
|
def load_splash_pixmap(self):
|
|
|
|
|
paths = [path + '/pgadmin4/assets/welcome_logo.svg' for path in sys.path]
|
|
|
|
|
paths = [path for path in paths if os.path.exists(path)]
|
|
|
|
|
if not paths:
|
|
|
|
|
return None
|
|
|
|
|
return QPixmap(paths[0])
|
|
|
|
|
|
|
|
|
|
def run_pgadmin_server(self):
|
|
|
|
|
if 'PGADMIN_INT_KEY' not in self.environ:
|
|
|
|
|
self.environ['PGADMIN_INT_KEY'] = str(uuid.uuid4())
|
|
|
|
|
|
|
|
|
|
if 'PGADMIN_INT_PORT' not in self.environ:
|
|
|
|
|
self.environ['PGADMIN_INT_PORT'] = '5051'
|
|
|
|
|
|
|
|
|
|
self.environ['PGADMIN_SERVER_MODE'] = 'OFF'
|
|
|
|
|
self.pgadmin_process = subprocess.Popen(['pgadmin4'],
|
|
|
|
|
env=self.environ, shell=True)
|
|
|
|
|
|
|
|
|
|
def create_ui(self):
|
|
|
|
|
icon = QIcon.fromTheme("pgadmin4")
|
|
|
|
|
self.tray = QSystemTrayIcon()
|
|
|
|
|
self.tray.setIcon(icon)
|
|
|
|
|
self.tray.setVisible(True)
|
|
|
|
|
|
|
|
|
|
menu = QMenu()
|
|
|
|
|
|
|
|
|
|
self.title = QAction("pgAdmin")
|
|
|
|
|
self.title.setEnabled(False)
|
|
|
|
|
menu.addAction(self.title)
|
|
|
|
|
menu.addSeparator()
|
|
|
|
|
|
|
|
|
|
self.openPGAdminAction = QAction("New Window")
|
|
|
|
|
menu.addAction(self.openPGAdminAction)
|
|
|
|
|
self.openPGAdminAction.triggered.connect(self.open_pgadmin)
|
|
|
|
|
|
|
|
|
|
self.quitAction = QAction("Quit")
|
|
|
|
|
menu.addAction(self.quitAction)
|
|
|
|
|
self.quitAction.triggered.connect(self.quit)
|
|
|
|
|
|
|
|
|
|
self.tray.setContextMenu(menu)
|
|
|
|
|
|
2024-02-09 06:41:39 +00:00
|
|
|
def check_if_pgadmin_is_running(self):
|
2023-10-27 13:08:10 +00:00
|
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
|
|
|
sock.settimeout(1)
|
|
|
|
|
result = sock.connect_ex(('127.0.0.1',
|
|
|
|
|
int(self.environ['PGADMIN_INT_PORT'])))
|
|
|
|
|
|
|
|
|
|
if result == 0:
|
|
|
|
|
if self.splash:
|
|
|
|
|
self.splash.hide()
|
|
|
|
|
port = self.environ['PGADMIN_INT_PORT']
|
|
|
|
|
key = self.environ['PGADMIN_INT_KEY']
|
|
|
|
|
subprocess.run(["xdg-open", f"http://127.0.0.1:{port}/?key={key}"])
|
|
|
|
|
|
2024-02-09 06:41:39 +00:00
|
|
|
self.openPGAdminAction.setText("New Window")
|
|
|
|
|
self.openPGAdminAction.setEnabled(True)
|
|
|
|
|
else:
|
|
|
|
|
self.checks_for_pgadmin += 1
|
|
|
|
|
if self.checks_for_pgadmin < 15:
|
|
|
|
|
dots = "." * (self.checks_for_pgadmin % 3 + 1)
|
|
|
|
|
self.openPGAdminAction.setText("Opening pgAdmin" + dots)
|
|
|
|
|
if self.splash and not self.splash.isHidden():
|
|
|
|
|
self.splash.showMessage("Starting pgAdmin" + dots, Qt.AlignmentFlag.AlignBottom)
|
|
|
|
|
|
|
|
|
|
QTimer.singleShot(1000, self.check_if_pgadmin_is_running)
|
|
|
|
|
else:
|
|
|
|
|
error_msg = 'Timeout waiting for pgAdmin to start. Exiting...'
|
|
|
|
|
print(error_msg)
|
|
|
|
|
self.splash.showMessage(error_msg, Qt.AlignmentFlag.AlignBottom)
|
|
|
|
|
QTimer.singleShot(10000, self.quit)
|
2023-10-27 13:08:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
def open_pgadmin(self):
|
|
|
|
|
self.openPGAdminAction.setText("Opening pgAdmin...")
|
|
|
|
|
self.openPGAdminAction.setEnabled(False)
|
2024-02-09 06:41:39 +00:00
|
|
|
self.checks_for_pgadmin = 0
|
|
|
|
|
QTimer.singleShot(1000, self.check_if_pgadmin_is_running)
|
2023-10-27 13:08:10 +00:00
|
|
|
|
|
|
|
|
def cleanup(self):
|
|
|
|
|
self.pgadmin_process.kill()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
app = PGAdminDesktop()
|
|
|
|
|
sys.exit(app.exec())
|