From cce1953eb1f8fe8c927a1720c95caed45b71ef1d Mon Sep 17 00:00:00 2001 From: Sebastian Reichel Date: Fri, 29 Jun 2018 21:05:46 +0200 Subject: all: simplify datadir configuration This simplifies the datadir configuration and removes the expectation, that the code is executed from the repository. It should now be possible to install this into the system like any other common Linux application. --- data/po/de.po | 48 ++++++++++++++++++++++---------------------- data/po/shopsystem.pot | 48 ++++++++++++++++++++++---------------------- example.cfg | 5 +---- src/audio/main.vala | 3 ++- src/config/main.vala | 4 +--- src/curses-ui/curses-ui.vala | 4 ++-- src/curses-ui/logo.vala | 14 ++++++------- src/curses-ui/main.vala | 14 +++++++++---- src/invoice/invoice.vala | 3 ++- src/pdf-invoice/main.vala | 3 ++- src/web/main.vala | 3 ++- 11 files changed, 77 insertions(+), 72 deletions(-) diff --git a/data/po/de.po b/data/po/de.po index f70e4ce..9196b50 100644 --- a/data/po/de.po +++ b/data/po/de.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: shopsystem 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-06-29 01:20+0200\n" +"POT-Creation-Date: 2018-06-29 21:19+0200\n" "PO-Revision-Date: 2018-06-28 21:14+0200\n" "Last-Translator: Sebastian Reichel \n" "Language-Team: German\n" @@ -56,8 +56,8 @@ msgstr "GStreamer Plugin für ALSA konnte nicht gefunden werden" msgid "Cannot find playbin2 GStreamer plugin" msgstr "GStreamer Plugin playbin2 konnte nicht gefunden werden" -#: audio/main.vala:39 database/main.vala:29 input-device/main.vala:31 -#: pdf-invoice/main.vala:30 pgp/main.vala:35 serial-device/main.vala:29 +#: audio/main.vala:40 database/main.vala:29 input-device/main.vala:31 +#: pdf-invoice/main.vala:31 pgp/main.vala:35 serial-device/main.vala:29 #, c-format msgid "Config Error: %s\n" msgstr "Konfigurationsfehler: %s\n" @@ -67,8 +67,8 @@ msgstr "Konfigurationsfehler: %s\n" msgid "Convert Error: %s" msgstr "Konvertierungsfehler" -#: audio/main.vala:30 cli/main.vala:37 config/main.vala:32 -#: database/main.vala:40 input-device/main.vala:42 pdf-invoice/main.vala:39 +#: audio/main.vala:30 cli/main.vala:37 config/main.vala:30 +#: database/main.vala:40 input-device/main.vala:42 pdf-invoice/main.vala:40 #: pdf-stock/main.vala:26 pgp/main.vala:44 scanner-session/main.vala:28 #: serial-device/main.vala:40 msgid "Could not acquire name\n" @@ -93,7 +93,7 @@ msgstr "Konnte SVG nicht laden: %s\n" msgid "Could not load configuration file: %s" msgstr "Konnte Konfigurationsdatei nicht laden: %s" -#: invoice/invoice.vala:338 pdf-invoice/pdf-invoice.vala:379 +#: invoice/invoice.vala:339 pdf-invoice/pdf-invoice.vala:379 #, c-format msgid "Could not open VAT template: %s" msgstr "Konnte VAT-Template nicht öffnen: %s" @@ -102,19 +102,19 @@ msgstr "Konnte VAT-Template nicht öffnen: %s" msgid "Could not open device!\n" msgstr "Konnte Gerätedatei nicht öffnen!\n" -#: invoice/invoice.vala:252 invoice/invoice.vala:319 +#: invoice/invoice.vala:253 invoice/invoice.vala:320 #, c-format msgid "Could not open invoice template: %s" msgstr "Konnte Rechnungs-Template nicht öffnen: %s" -#: audio/main.vala:53 cli/main.vala:68 config/main.vala:43 +#: audio/main.vala:54 cli/main.vala:68 config/main.vala:41 #: database/main.vala:51 input-device/main.vala:53 input-device/main.vala:58 #: pdf-stock/main.vala:37 pgp/main.vala:55 scanner-session/main.vala:41 #: serial-device/main.vala:51 msgid "Could not register service\n" msgstr "Konnte DBus-Service nicht registrieren\n" -#: pdf-invoice/main.vala:50 +#: pdf-invoice/main.vala:51 #, c-format msgid "Could not register service: %s\n" msgstr "Konnte DBus-Servicenicht registieren: %s\n" @@ -123,7 +123,7 @@ msgstr "Konnte DBus-Servicenicht registieren: %s\n" msgid "Could not setup webserver!" msgstr "Konnte Webserver nicht konfigurieren!" -#: web/main.vala:64 +#: web/main.vala:65 #, c-format msgid "Could not start Webserver: %s\n" msgstr "Konnte Webserver nicht starten: %s\n" @@ -133,9 +133,9 @@ msgstr "Konnte Webserver nicht starten: %s\n" msgid "DBus Error: %s" msgstr "DBus Fehler: %s" -#: audio/main.vala:41 database/main.vala:31 input-device/main.vala:33 -#: pdf-invoice/main.vala:26 pgp/main.vala:31 serial-device/main.vala:31 -#: web/main.vala:51 +#: audio/main.vala:42 curses-ui/main.vala:68 database/main.vala:31 +#: input-device/main.vala:33 pdf-invoice/main.vala:27 pgp/main.vala:31 +#: serial-device/main.vala:31 web/main.vala:52 #, c-format msgid "DBus Error: %s\n" msgstr "DBus Fehler: %s\n" @@ -223,10 +223,10 @@ msgstr "Gast" msgid "IO Error: %s" msgstr "EA Fehler: %s" -#: audio/main.vala:37 curses-ui/main.vala:60 database/main.vala:27 -#: input-device/main.vala:29 pdf-invoice/main.vala:28 pgp/main.vala:33 +#: audio/main.vala:38 curses-ui/main.vala:66 database/main.vala:27 +#: input-device/main.vala:29 pdf-invoice/main.vala:29 pgp/main.vala:33 #: scanner-session/scannersession.vala:49 serial-device/main.vala:27 -#: web/main.vala:47 +#: web/main.vala:48 #, c-format msgid "IO Error: %s\n" msgstr "EA Fehler: %s\n" @@ -250,7 +250,7 @@ msgstr "Eingabegerät wird ignoriert\n" msgid "Internal Error!" msgstr "Interner Fehler!" -#: web/main.vala:44 web/main.vala:49 +#: curses-ui/main.vala:70 web/main.vala:45 web/main.vala:50 #, c-format msgid "KeyFile Error: %s\n" msgstr "Schlüsseldatei Fehler: %s\n" @@ -348,25 +348,25 @@ msgstr "Antwort vom SMTP-Server: %s" msgid "Sending: %s\n" msgstr "Sende: %s\n" -#: curses-ui/main.vala:72 +#: curses-ui/main.vala:78 msgid "Shop System has been started" msgstr "Shop System wurde gestartet" -#: curses-ui/main.vala:78 +#: curses-ui/main.vala:84 msgid "Stopping Shop System" msgstr "Shop System wird gestoppt" -#: web/main.vala:55 +#: web/main.vala:56 #, c-format msgid "TLS certificate: %s\n" msgstr "TLS Zertifikat: %s\n" -#: web/main.vala:56 +#: web/main.vala:57 #, c-format msgid "TLS private key: %s\n" msgstr "TLS Privater Schlüssel: %s\n" -#: invoice/invoice.vala:314 +#: invoice/invoice.vala:315 msgid "Unknown MessageType" msgstr "Unbekannter Nachrichten Typ" @@ -375,7 +375,7 @@ msgstr "Unbekannter Nachrichten Typ" msgid "Usage: %s [timestamp]\n" msgstr "Benutzung: %s [timestamp]\n" -#: web/main.vala:54 +#: web/main.vala:55 #, c-format msgid "Web Server Port: %u\n" msgstr "Webserver Port: %u\n" @@ -407,7 +407,7 @@ msgstr "Konnte STARTTLS nicht konfigurieren" msgid "could not load templates!" msgstr "Konnte Templates nicht laden!" -#: curses-ui/main.vala:27 curses-ui/main.vala:29 +#: curses-ui/main.vala:28 curses-ui/main.vala:30 #, c-format msgid "could not play audio: %s" msgstr "Konnte Audio Datei nicht abspielen: %s" diff --git a/data/po/shopsystem.pot b/data/po/shopsystem.pot index abab319..757f7a5 100644 --- a/data/po/shopsystem.pot +++ b/data/po/shopsystem.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: shopsystem\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2018-06-29 01:20+0200\n" +"POT-Creation-Date: 2018-06-29 21:19+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -57,8 +57,8 @@ msgstr "" msgid "Cannot find playbin2 GStreamer plugin" msgstr "" -#: audio/main.vala:39 database/main.vala:29 input-device/main.vala:31 -#: pdf-invoice/main.vala:30 pgp/main.vala:35 serial-device/main.vala:29 +#: audio/main.vala:40 database/main.vala:29 input-device/main.vala:31 +#: pdf-invoice/main.vala:31 pgp/main.vala:35 serial-device/main.vala:29 #, c-format msgid "Config Error: %s\n" msgstr "" @@ -68,8 +68,8 @@ msgstr "" msgid "Convert Error: %s" msgstr "" -#: audio/main.vala:30 cli/main.vala:37 config/main.vala:32 -#: database/main.vala:40 input-device/main.vala:42 pdf-invoice/main.vala:39 +#: audio/main.vala:30 cli/main.vala:37 config/main.vala:30 +#: database/main.vala:40 input-device/main.vala:42 pdf-invoice/main.vala:40 #: pdf-stock/main.vala:26 pgp/main.vala:44 scanner-session/main.vala:28 #: serial-device/main.vala:40 msgid "Could not acquire name\n" @@ -94,7 +94,7 @@ msgstr "" msgid "Could not load configuration file: %s" msgstr "" -#: invoice/invoice.vala:338 pdf-invoice/pdf-invoice.vala:379 +#: invoice/invoice.vala:339 pdf-invoice/pdf-invoice.vala:379 #, c-format msgid "Could not open VAT template: %s" msgstr "" @@ -103,19 +103,19 @@ msgstr "" msgid "Could not open device!\n" msgstr "" -#: invoice/invoice.vala:252 invoice/invoice.vala:319 +#: invoice/invoice.vala:253 invoice/invoice.vala:320 #, c-format msgid "Could not open invoice template: %s" msgstr "" -#: audio/main.vala:53 cli/main.vala:68 config/main.vala:43 +#: audio/main.vala:54 cli/main.vala:68 config/main.vala:41 #: database/main.vala:51 input-device/main.vala:53 input-device/main.vala:58 #: pdf-stock/main.vala:37 pgp/main.vala:55 scanner-session/main.vala:41 #: serial-device/main.vala:51 msgid "Could not register service\n" msgstr "" -#: pdf-invoice/main.vala:50 +#: pdf-invoice/main.vala:51 #, c-format msgid "Could not register service: %s\n" msgstr "" @@ -124,7 +124,7 @@ msgstr "" msgid "Could not setup webserver!" msgstr "" -#: web/main.vala:64 +#: web/main.vala:65 #, c-format msgid "Could not start Webserver: %s\n" msgstr "" @@ -134,9 +134,9 @@ msgstr "" msgid "DBus Error: %s" msgstr "" -#: audio/main.vala:41 database/main.vala:31 input-device/main.vala:33 -#: pdf-invoice/main.vala:26 pgp/main.vala:31 serial-device/main.vala:31 -#: web/main.vala:51 +#: audio/main.vala:42 curses-ui/main.vala:68 database/main.vala:31 +#: input-device/main.vala:33 pdf-invoice/main.vala:27 pgp/main.vala:31 +#: serial-device/main.vala:31 web/main.vala:52 #, c-format msgid "DBus Error: %s\n" msgstr "" @@ -224,10 +224,10 @@ msgstr "" msgid "IO Error: %s" msgstr "" -#: audio/main.vala:37 curses-ui/main.vala:60 database/main.vala:27 -#: input-device/main.vala:29 pdf-invoice/main.vala:28 pgp/main.vala:33 +#: audio/main.vala:38 curses-ui/main.vala:66 database/main.vala:27 +#: input-device/main.vala:29 pdf-invoice/main.vala:29 pgp/main.vala:33 #: scanner-session/scannersession.vala:49 serial-device/main.vala:27 -#: web/main.vala:47 +#: web/main.vala:48 #, c-format msgid "IO Error: %s\n" msgstr "" @@ -251,7 +251,7 @@ msgstr "" msgid "Internal Error!" msgstr "" -#: web/main.vala:44 web/main.vala:49 +#: curses-ui/main.vala:70 web/main.vala:45 web/main.vala:50 #, c-format msgid "KeyFile Error: %s\n" msgstr "" @@ -346,25 +346,25 @@ msgstr "" msgid "Sending: %s\n" msgstr "" -#: curses-ui/main.vala:72 +#: curses-ui/main.vala:78 msgid "Shop System has been started" msgstr "" -#: curses-ui/main.vala:78 +#: curses-ui/main.vala:84 msgid "Stopping Shop System" msgstr "" -#: web/main.vala:55 +#: web/main.vala:56 #, c-format msgid "TLS certificate: %s\n" msgstr "" -#: web/main.vala:56 +#: web/main.vala:57 #, c-format msgid "TLS private key: %s\n" msgstr "" -#: invoice/invoice.vala:314 +#: invoice/invoice.vala:315 msgid "Unknown MessageType" msgstr "" @@ -373,7 +373,7 @@ msgstr "" msgid "Usage: %s [timestamp]\n" msgstr "" -#: web/main.vala:54 +#: web/main.vala:55 #, c-format msgid "Web Server Port: %u\n" msgstr "" @@ -405,7 +405,7 @@ msgstr "" msgid "could not load templates!" msgstr "" -#: curses-ui/main.vala:27 curses-ui/main.vala:29 +#: curses-ui/main.vala:28 curses-ui/main.vala:30 #, c-format msgid "could not play audio: %s" msgstr "" diff --git a/example.cfg b/example.cfg index a56e074..bfae3ea 100644 --- a/example.cfg +++ b/example.cfg @@ -2,6 +2,7 @@ longname = Kreativität trifft Technik e.V. shortname = KTT spacename = Mainframe +datapath = /usr/share/shopsystem/ [DATABASE] file = /path/to/shop.db [INPUT] @@ -16,16 +17,12 @@ password = my_top_secret_password starttls = true mailfromaddress = shop@kreativitaet-trifft-technik.de treasurermailaddress = shop-einzug@kreativitaet-trifft-technik.de -[AUDIO] -path = /path/to/sounds/ [PGP] keyring = /path/to/keyring/ keyid = 0x12345678 [WEB] -filepath = /path/to/web/templates/ port = 8080 [INVOICE] -datadir = /path/to/invoice/ vat = no addressrow = Kreativität trifft Technik e.V., Bahnhofsplatz 10, 26122 Oldenburg footer1 = Kreativität trifft Technik e.V.\nAmtsgericht Oldenburg VR 201044\n\nHackspace „Mainframe“\nFabLab „Fab-O-Lab“\nSchnittstelle „Schnittstelle“\n\nBahnhofsplatz 10 • 26122 Oldenburg diff --git a/src/audio/main.vala b/src/audio/main.vala index 4a1da2f..2fdaf61 100644 --- a/src/audio/main.vala +++ b/src/audio/main.vala @@ -31,7 +31,8 @@ public static int main(string[] args) { try { Config cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); - var path = cfg.get_string("AUDIO", "path"); + var datapath = cfg.get_string("GENERAL", "datapath"); + var path = Path.build_filename(datapath, "sounds"); player = new AudioPlayerImplementation(path); } catch(IOError e) { error(_("IO Error: %s\n"), e.message); diff --git a/src/config/main.vala b/src/config/main.vala index c24b572..6a90ad0 100644 --- a/src/config/main.vala +++ b/src/config/main.vala @@ -19,9 +19,7 @@ public static int main(string[] args) { Intl.setlocale(LocaleCategory.ALL, ""); Intl.textdomain("shopsystem"); - string binarylocation = File.new_for_path(args[0]).get_parent().get_path(); - - cfg = new Cfg(binarylocation + "/../../ktt-shopsystem.cfg"); + cfg = new Cfg("/etc/shopsystem.cfg"); Bus.own_name( BusType.SYSTEM, diff --git a/src/curses-ui/curses-ui.vala b/src/curses-ui/curses-ui.vala index 0cd6281..e98c6ea 100644 --- a/src/curses-ui/curses-ui.vala +++ b/src/curses-ui/curses-ui.vala @@ -23,7 +23,7 @@ public class CursesUI { //StatusPanel statuswin; MessageBoxOverlay mbOverlay; - public CursesUI(string binarylocation) { + public CursesUI(string datadir) { /* unicode support */ Intl.setlocale(LocaleCategory.CTYPE, ""); @@ -40,7 +40,7 @@ public class CursesUI { Curses.init_pair(2, Curses.Color.WHITE, Curses.Color.RED); /* initialize widgets */ - banner = new Logo(binarylocation); + banner = new Logo(datadir); //statuswin = new StatusPanel(); messages = new MessageBox(); clkwin = new ClockWindow(); diff --git a/src/curses-ui/logo.vala b/src/curses-ui/logo.vala index e7f6fb8..a4a2c2c 100644 --- a/src/curses-ui/logo.vala +++ b/src/curses-ui/logo.vala @@ -19,28 +19,28 @@ using Curses; public class Logo { Window win; - public Logo(string binarylocation) { + public Logo(string datadir) { win = new Window(8, COLS - 2, 0, 1); win.bkgdset(COLOR_PAIR(1) | Attribute.BOLD); win.addstr("\n"); - var file = File.new_for_path (binarylocation + "/../../logo.txt"); - - if (!file.query_exists ()) { + var logofilename = Path.build_filename(datadir, "logo.txt"); + var file = File.new_for_path(logofilename); + if (!file.query_exists()) { stderr.printf (_("File '%s' doesn't exist.\n"), file.get_path ()); } try { // Open file for reading and wrap returned FileInputStream into a // DataInputStream, so we can read line by line - var dis = new DataInputStream (file.read ()); + var dis = new DataInputStream(file.read()); string line; // Read lines until end of file (null) is reached - while ((line = dis.read_line (null)) != null) { + while ((line = dis.read_line(null)) != null) { win.addstr(line+"\n"); } - } catch (Error e) { + } catch(Error e) { error (_("Error: %s"), e.message); } diff --git a/src/curses-ui/main.vala b/src/curses-ui/main.vala index e5ad4c8..3518bb2 100644 --- a/src/curses-ui/main.vala +++ b/src/curses-ui/main.vala @@ -19,6 +19,7 @@ public MainLoop loop; public AudioPlayer audio; public ScannerSession scanner; public CursesUI ui; +private Config cfg; private static void play(string file) { try { @@ -56,14 +57,19 @@ public static int main(string[] args) { try { audio = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.AudioPlayer", "/io/mainframe/shopsystem/audio"); scanner = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.ScannerSession", "/io/mainframe/shopsystem/scanner_session"); + cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); + + var datapath = cfg.get_string("GENERAL", "datapath"); + var datadir = Path.build_filename(datapath, "curses-ui"); + ui = new CursesUI(datadir); } catch(IOError e) { error(_("IO Error: %s\n"), e.message); + } catch(DBusError e) { + error(_("DBus Error: %s\n"), e.message); + } catch(KeyFileError e) { + error(_("KeyFile Error: %s\n"), e.message); } - string binarylocation = File.new_for_path(args[0]).get_parent().get_path(); - - ui = new CursesUI(binarylocation); - Log.set_default_handler(log_handler); scanner.msg.connect(msg_handler); diff --git a/src/invoice/invoice.vala b/src/invoice/invoice.vala index f899cb5..1321071 100644 --- a/src/invoice/invoice.vala +++ b/src/invoice/invoice.vala @@ -44,7 +44,8 @@ public class InvoiceImplementation { db = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Database", "/io/mainframe/shopsystem/database"); pdf = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.InvoicePDF", "/io/mainframe/shopsystem/invoicepdf"); Config cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); - datadir = cfg.get_string("INVOICE", "datadir"); + var datapath = cfg.get_string("GENERAL", "datapath"); + datadir = Path.build_filename(datapath, "invoice"); mailfromaddress = cfg.get_string("MAIL", "mailfromaddress"); treasurermailaddress = cfg.get_string("MAIL", "treasurermailaddress"); shortname = cfg.get_string("GENERAL", "shortname"); diff --git a/src/pdf-invoice/main.vala b/src/pdf-invoice/main.vala index 1848852..4217eb8 100644 --- a/src/pdf-invoice/main.vala +++ b/src/pdf-invoice/main.vala @@ -21,7 +21,8 @@ public static int main(string[] args) { try { Config cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); - datadir = cfg.get_string("INVOICE", "datadir"); + var datapath = cfg.get_string("GENERAL", "datapath"); + datadir = Path.build_filename(datapath, "invoice"); } catch(DBusError e) { error(_("DBus Error: %s\n"), e.message); } catch(IOError e) { diff --git a/src/web/main.vala b/src/web/main.vala index f7b0c30..2043df0 100644 --- a/src/web/main.vala +++ b/src/web/main.vala @@ -34,7 +34,8 @@ public static int main(string[] args) { pgp = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.PGP", "/io/mainframe/shopsystem/pgp"); cfg = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.Config", "/io/mainframe/shopsystem/config"); audio = Bus.get_proxy_sync(BusType.SYSTEM, "io.mainframe.shopsystem.AudioPlayer", "/io/mainframe/shopsystem/audio"); - templatedir = cfg.get_string("WEB", "filepath"); + var datapath = cfg.get_string("GENERAL", "datapath"); + templatedir = Path.build_filename(datapath, "templates"); port = cfg.get_integer("WEB", "port"); try { -- cgit v1.2.3