Skip to content

Commit

Permalink
Implement --replace-all option
Browse files Browse the repository at this point in the history
This replaces the GUI and two background services (by using the
recently added `--replace` options). This is helpful during development
to easily replace the existing deamons (even when installed system-wide)
with a development version, without having to resort to fragile pkill
commands.

This also updates the README to recommend using this option instead of
kill commands. This also removes a note about not calling windows via
dbus, since that does not seem to be true with the current codebase.

This fixes #746
  • Loading branch information
matthijskooijman committed Dec 27, 2023
1 parent e5ba311 commit 4109d79
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 33 deletions.
33 changes: 10 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down
18 changes: 17 additions & 1 deletion src/hamster-cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import argparse
import time
import re
import pathlib
import subprocess

import gi
gi.require_version('Gdk', '3.0') # noqa: E402
Expand Down Expand Up @@ -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=[])

Expand All @@ -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
Expand Down
13 changes: 4 additions & 9 deletions src/hamster/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
)
Expand Down
1 change: 1 addition & 0 deletions src/hamster/defs.py.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
DATA_DIR = "@DATADIR@"
LIBEXEC_DIR = "@LIBEXECDIR@"
VERSION = "@VERSION@"

0 comments on commit 4109d79

Please sign in to comment.