Skip to content

Commit f8118ee

Browse files
committed
makes both dbus and gobject optional
1 parent 8f84e8e commit f8118ee

10 files changed

+78
-44
lines changed

README.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,19 @@ See [deployment](#deployment) for notes on how to deploy dups on a live system.
2828
### Prerequisites
2929
Required system packages:
3030
```
31-
dbus
3231
rsync
3332
```
3433

3534
Required python packages:
3635
```
3736
# Runtime
38-
dbus-python
3937
paramiko
40-
pygobject
4138
ruamel.yaml>=0.15.0
4239
40+
# Runtime (Optional)
41+
dbus-python # Daemon support
42+
pygobject # Desktop notification support
43+
4344
# Unittests
4445
ddt
4546
```

data/pkg/archlinux/PKGBUILD

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ pkgdesc="It deduplicates things - Backup as simple as possible."
66
arch=("x86_64")
77
url="https://github.com/linuxwhatelse/dups"
88
license=('GPL3')
9-
depends=('python' 'rsync' 'dbus' 'python-gobject' 'python-dbus'
10-
'python-paramiko' 'python-ruamel-yaml')
9+
depends=('python' 'rsync' 'python-paramiko' 'python-ruamel-yaml')
10+
optdepends=('python-dbus: Daemon support'
11+
'python-gobject: Desktop notification support')
1112
makedepends=('python-setuptools')
1213
provides=("${_pkgname}")
1314
source=("${_pkgname}::git+https://github.com/linuxwhatelse/dups.git")
@@ -35,4 +36,3 @@ package() {
3536

3637

3738
# vim: set syntax=sh:
38-
+10-5
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
post_install() {
22
echo "---"
3-
echo "Reload user units with:"
3+
echo "Start user unit with:"
44
echo " systemctl --user daemon-reload"
5-
echo ""
6-
echo "Start dups with:"
75
echo " systemctl --user start dups"
86
echo ""
7+
echo "Start system unit with:"
8+
echo " sudo systemctl daemon-reload"
9+
echo " sudo systemctl start dups@<USERNAME>"
10+
echo ""
911
echo "To automatically start dups after login:"
1012
echo " systemctl --user enable dups"
13+
echo " sudo systemctl enable dups@<USERNAME>"
1114
echo "---"
1215
}
1316

1417
post_upgrade() {
1518
echo "---"
16-
echo ""
17-
echo "Restart dups with:"
19+
echo "Restart user unit with:"
1820
echo " systemctl --user daemon-reload"
1921
echo " systemctl --user restart dups"
2022
echo ""
23+
echo "Restart system unit with:"
24+
echo " sudo systemctl daemon-reload"
25+
echo " sudo systemctl restart dups@<USERNAME>"
2126
echo "---"
2227
}

data/pkg/debian/stdeb.cfg

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[DEFAULT]
2-
Depends3: rsync, dbus, python3-gi, libdbus-1-dev, python3-dbus,
3-
python3-paramiko, python3-ruamel.yaml
4-
Suggests3: anacron
2+
Depends3: rsync, python3-paramiko, python3-ruamel.yaml
3+
Suggests3: python3-dbus, python3-gi, anacron
54
X-Python3-Version: >= 3.5
65
Setup-Env-Vars: INCLUDE_DATA_FILES=systemd dbus desktop

dependencies.txt

-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
dbus
21
rsync

dups/__main__.py

+25-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
import logging
44
import sys
55

6-
import dbus
6+
from . import const, helper, user, utils
77

8-
from . import const, daemon, helper, user, utils
8+
try:
9+
import dbus
10+
from . import daemon
11+
except ImportError:
12+
dbus = None
13+
daemon = None
914

1015
LOGGER = logging.getLogger(__name__)
1116

@@ -275,10 +280,28 @@ def handle_management(args, cfg):
275280
cfg.remove_excludes(args.remove_excludes)
276281

277282

283+
def is_dbus_required(args):
284+
if any((args.daemon, args.system_daemon)):
285+
return True
286+
287+
if 'background' in args and args.background:
288+
return True
289+
290+
if 'system_background' in args and args.system_background:
291+
return True
292+
293+
return False
294+
295+
278296
def main():
279297
"""Entrypoint for dups."""
280298
args = parse_args()
281299

300+
if is_dbus_required(args) and dbus is None:
301+
print('To use any of the daemon functionality, "dbus-python" '
302+
'is required.')
303+
sys.exit(1)
304+
282305
try:
283306
usr = user.User(args.user)
284307
except ValueError as e:

dups/helper.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,19 @@
66
from contextlib import contextmanager
77
from typing import Tuple
88

9-
import dbus
109
import paramiko
1110
import ruamel.yaml
1211

1312
from . import backup, config, const, exceptions, rsync, user, utils
1413

14+
try:
15+
from dbus.exceptions import DBusException
16+
except ImportError:
17+
18+
class DBusException(Exception):
19+
pass
20+
21+
1522
LOGGER = logging.getLogger(__name__)
1623

1724

@@ -133,7 +140,7 @@ def error_handler(callback, *args, **kwargs):
133140
except (KeyError, socket.gaierror):
134141
error_msg = 'Could not connect to host.'
135142

136-
except dbus.exceptions.DBusException:
143+
except DBusException:
137144
LOGGER.debug(traceback.format_exc())
138145
error_msg = 'Unable to connect to daemon. Is one running?'
139146

@@ -167,7 +174,10 @@ def notify(title, body=None, priority=None, icon=const.APP_ICON):
167174
if not cfg.notify:
168175
return
169176

170-
utils.notify(const.APP_ID, title, body, priority, icon)
177+
try:
178+
utils.notify(const.APP_ID, title, body, priority, icon)
179+
except RuntimeError as e:
180+
LOGGER.warning(str(e))
171181

172182

173183
def get_backups(include_valid=True, include_invalid=True):

dups/utils.py

+12-5
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,19 @@
1111
from typing import TypeVar
1212

1313
import paramiko
14-
from gi.repository import Gio
1514

1615
from . import config
1716

17+
try:
18+
from gi.repository import Gio
19+
except ImportError:
20+
Gio = None
21+
1822
_IO = TypeVar('_IO', bound='IO')
1923

2024

2125
class NPriority:
22-
NORMAL = Gio.NotificationPriority.NORMAL
23-
LOW = Gio.NotificationPriority.LOW
24-
HIGH = Gio.NotificationPriority.HIGH
25-
URGENT = Gio.NotificationPriority.URGENT
26+
NORMAL, LOW, HIGH, URGENT = 0, 1, 2, 3
2627

2728

2829
def confirm(msg, default_yes=False):
@@ -86,7 +87,13 @@ def notify(app_id, title, body=None, priority=None, icon=None):
8687
body (str): The notifications body.
8788
priority (NPriority): The notifications priority level.
8889
icon (str): Name or path of the notifications icon.
90+
91+
Raises:
92+
RuntimeError: If pygobject is missing.
8993
"""
94+
if Gio is None:
95+
raise RuntimeError('"pygobject" required but not available.')
96+
9097
app = Gio.Application.new(app_id, Gio.ApplicationFlags.FLAGS_NONE)
9198
app.register()
9299

requirements.txt

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Runtime
2-
dbus-python
32
paramiko
4-
pygobject
53
ruamel.yaml>=0.15.0
64

5+
# Runtime (Optional)
6+
dbus-python # Daemon support
7+
pygobject # Desktop notification support
8+
79
# Unittests
810
ddt

setup.py

+5-17
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,6 @@
22

33
from setuptools import find_packages, setup
44

5-
HERE = os.path.dirname(os.path.realpath(__file__))
6-
7-
8-
def get_requirements():
9-
requirements = []
10-
with open(os.path.join(HERE, 'requirements.txt'), 'r') as f:
11-
for line in f.readlines():
12-
line = line.strip()
13-
if not line or line.startswith('#'):
14-
if line.lstrip('#').strip().lower().startswith('unittests'):
15-
break
16-
continue
17-
requirements.append(line)
18-
19-
return requirements
20-
215

226
def get_data_files():
237
include_data_files = os.environ.get('INCLUDE_DATA_FILES', '').split(' ')
@@ -67,6 +51,10 @@ def get_data_files():
6751
]},
6852
data_files=get_data_files(),
6953
scripts=['data/bin/dups'],
70-
install_requires=get_requirements(),
54+
install_requires=['paramiko', 'ruamel.yaml>=0.15.0'],
55+
extras_require={
56+
'daemon': ['dbus-python'],
57+
'notification': ['pygobject']
58+
},
7159
zip_safe=False,
7260
)

0 commit comments

Comments
 (0)