From e80a0688cc3c98f760092684255ad5f097a14bb7 Mon Sep 17 00:00:00 2001 From: Thomas Hooge Date: Fri, 7 Nov 2025 14:42:05 +0100 Subject: [PATCH] Work on native gui --- INSTALL | 12 +++++++++++- yms/database.py | 15 +++++++++++++++ ymsgui.py | 13 ++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/INSTALL b/INSTALL index d1f41a1..f272ec8 100644 --- a/INSTALL +++ b/INSTALL @@ -11,6 +11,7 @@ YMS Installation - mupdf-tools for extended pdf file management 1.2 Native GUI +- python3-mysqldb - Python GTK3 - python3-gi - gir1.2-gtk-3.0 @@ -82,7 +83,16 @@ Configfile should be readable by webserver but not writeable. chmod 640 config.inc chgrp www-data config.inc -8. Start using YMS +8. Setup local GUI + +Create a local database user with same name as your computer user and allow +database acces with current unix credentials: + mysql> CREATE USER 'ymsgui'@'localhost' IDENTIFIED BY 'geheim'; + mysql> ALTER USER ymsgui@localhost IDENTIFIED VIA unix_socket; + +Start ymdgui.py, default configuration file is automatically created + +9. Start using YMS Start your browser and login to YMS with the default username/password: captain/captain diff --git a/yms/database.py b/yms/database.py index a445dac..7f6eb02 100644 --- a/yms/database.py +++ b/yms/database.py @@ -23,6 +23,21 @@ class Database(): self.dcur = self.conn.cursor(MySQLdb.cursors.DictCursor) return True + def connect_local(self): + # connection via local unix socket + if self.conn: + return True + MySQLdb.paramstyle = 'pyformat' + try: + self.conn = MySQLdb.connect(host='localhost', db=self.schema, + unix_socket='/run/mysqld/mysqld.sock', charset='utf8') + except MySQLdb.Error as e: + print(e) + return False + self.cur = self.conn.cursor() + self.dcur = self.conn.cursor(MySQLdb.cursors.DictCursor) + return True + def disconnect(self): self.cur.close() self.dcur.close() diff --git a/ymsgui.py b/ymsgui.py index ec109a0..aa63cba 100755 --- a/ymsgui.py +++ b/ymsgui.py @@ -88,13 +88,24 @@ def messagebox(messagetext, symbol=None, title=None, parent=None): md.run() md.destroy() +def create_config(cfgfile): + # create inital config file + with open(cfgfile, 'w') as fh: + fh.write('[DB]\n') + fh.write('host = localhost\n') + fh.write('db = yms\n') + fh.write('user = yms\n') + fh.write('pass = geheim\n') + if __name__ == "__main__": locale.setlocale(locale.LC_ALL, '') gettext.bindtextdomain('ymsgui', 'locale') gettext.textdomain('ymsgui') _ = gettext.gettext config = configparser.ConfigParser() - if not config.read(os.path.expanduser(cfg['cfgfile'])): + cfgfile = os.path.expanduser(cfg['cfgfile']) + if not config.read(cfgfile): + create_config(cfgfile) messagebox(_("Configuration file not found"), title="YMS") else: cfg['host'] = config.get('DB', 'host')