diff --git a/README.md b/README.md index b3c116d37..b7901f097 100644 --- a/README.md +++ b/README.md @@ -25,21 +25,16 @@ ls --reverse -clt ~/.local/share/hamster*/*.db ``` Backup the last file in the list. +### Upgrading -### Kill hamster daemons +When installed from source, it is recommended to uninstall before +installing a new version. When using system packages or flatpak, you +should be able to just install the new version. -When trying a different version, make sure to kill the running daemons: +After upgrading, the hamster background services might still be running +the old version. To replace them, you can either log out, or run: -```bash -# either step-by-step, totally safe -pkill -f hamster-service -pkill -f hamster-windows-service -# check (should be empty) -pgrep -af hamster - -# or be bold and kill them all at once: -pkill -ef hamster -``` + hamster --replace-all ### Install from packages @@ -206,22 +201,14 @@ flatpak uninstall org.gnome.Hamster #### Development During development (As explained above, backup `hamster.db` first !), -if only python files are changed +if only python files are changed (*deeper changes such as the migration to gsettings require a new install*) the changes can be quickly tested by ``` -# either -pgrep -af hamster -# and kill them one by one -# or be bold and kill all processes with "hamster" in their command line -pkill -ef hamster -python3 src/hamster-service.py & -python3 src/hamster-cli.py + ./src/hamster-cli.py --replace-all ``` -Advantage: running uninstalled is detected, and windows are *not* called via -D-Bus, so that all the traces are visible. -Note: You'll need recent version of hamster installed on your system (or +Note: You'll need recent version of hamster installed on your system (or [this workaround](https://github.com/projecthamster/hamster/issues/552#issuecomment-585166000)). #### Running tests diff --git a/src/hamster-cli.py b/src/hamster-cli.py index 97e86a198..c0e61e33c 100755 --- a/src/hamster-cli.py +++ b/src/hamster-cli.py @@ -26,6 +26,8 @@ import argparse import time import re +import pathlib +import subprocess import gi gi.require_version('Gdk', '3.0') # noqa: E402 @@ -468,6 +470,8 @@ def version(self): help="Set the logging level (default: %(default)s)") parser.add_argument("--replace", action='store_true', help="Replace an existing GUI process (if any) instead of activating it") + parser.add_argument("--replace-all", action='store_true', + help="Replace all existing hamster processes (if any)") parser.add_argument("action", nargs="?", default="overview") parser.add_argument('action_args', nargs=argparse.REMAINDER, default=[]) @@ -478,9 +482,21 @@ def version(self): # hamster_logger for the rest hamster_logger.setLevel(args.log_level) + if args.replace_all: + if hamster.installed: + from hamster import defs # only available when running installed + d = pathlib.Path(defs.LIBEXEC_DIR) + cmds = [d / 'hamster-service', d / 'hamster-windows-service'] + else: + d = pathlib.Path(__file__).parent + cmds = [d / 'hamster-service.py', d / 'hamster-windows-service.py'] + + for cmd in cmds: + subprocess.run((cmd, '--replace')) + app = Hamster() logger.debug("app instantiated") - if args.replace: + if args.replace or args.replace_all: app.register() if app.get_is_remote(): # This code is prone to race conditions (if processing the quit diff --git a/src/hamster/client.py b/src/hamster/client.py index ab3d3ba04..8d0f0071b 100644 --- a/src/hamster/client.py +++ b/src/hamster/client.py @@ -94,15 +94,10 @@ def conn(self): server: {} client: {} - This is sometimes used during bisections, - but generally calls for trouble. - - Remember to kill hamster daemons after any version change - (this is safe): - pkill -f hamster-service - pkill -f hamster-windows-service - see also: - https://github.com/projecthamster/hamster#kill-hamster-daemons + To replace the running services, you can use: + + hamster --replace-all + """.format(server_version, client_version) ) ) diff --git a/src/hamster/defs.py.in b/src/hamster/defs.py.in index c74866049..0f1f8bd44 100644 --- a/src/hamster/defs.py.in +++ b/src/hamster/defs.py.in @@ -1,2 +1,3 @@ DATA_DIR = "@DATADIR@" +LIBEXEC_DIR = "@LIBEXECDIR@" VERSION = "@VERSION@"