1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
|
"""WebRsync module for portage"""
import logging
import portage
from portage import os
from portage.util import writemsg_level
from portage.output import create_color_func
from portage.sync.syncbase import SyncBase
good = create_color_func("GOOD")
bad = create_color_func("BAD")
warn = create_color_func("WARN")
try:
import gemato.openpgp
except ImportError:
gemato = None
class WebRsync(SyncBase):
"""WebRSync sync class
This class implements syncing via calls to an external binary, either:
- emerge-delta-webrsync (if sync-webrsync-delta is set), or
- emerge-webrsync
It wraps them and performs PGP verification if sync-webrsync-verify-signature
is set via gemato.
"""
short_desc = "Perform sync operations on webrsync based repositories"
@staticmethod
def name():
return "WebRSync"
def __init__(self):
SyncBase.__init__(self, "emerge-webrsync", ">=sys-apps/portage-2.3")
@property
def has_bin(self):
if (
self._bin_command != "emerge-delta-webrsync"
and self.repo.module_specific_options.get(
"sync-webrsync-delta", "false"
).lower()
in ("true", "yes")
):
self._bin_command = "emerge-delta-webrsync"
self.bin_command = portage.process.find_binary(self._bin_command)
self.bin_pkg = ">=app-portage/emerge-delta-webrsync-3.7.5"
return super().has_bin
def sync(self, **kwargs):
"""Sync the repository"""
if kwargs:
self._kwargs(kwargs)
if not self.has_bin:
return (1, False)
# filter these out to prevent gpg errors
for var in ["uid", "gid", "groups"]:
self.spawn_kwargs.pop(var, None)
verbose = "--verbose" in self.options["emerge_config"].opts
quiet = "--quiet" in self.options["emerge_config"].opts
openpgp_env = None
try:
if self.repo.module_specific_options.get(
"sync-webrsync-verify-signature", "false"
).lower() in ("true", "yes"):
if not self.repo.sync_openpgp_key_path:
writemsg_level(
"!!! sync-openpgp-key-path is not set\n",
level=logging.ERROR,
noiselevel=-1,
)
return (1, False)
if not os.path.isfile(self.repo.sync_openpgp_key_path):
writemsg_level(
"!!! sync-openpgp-key-path file not found: %s\n"
% self.repo.sync_openpgp_key_path,
level=logging.ERROR,
noiselevel=-1,
)
return (1, False)
if gemato is None:
writemsg_level(
"!!! Verifying against specified key requires gemato-14.5+ installed\n",
level=logging.ERROR,
noiselevel=-1,
)
return (1, False)
self.spawn_kwargs["env"]["PORTAGE_SYNC_WEBRSYNC_GPG"] = "1"
self.spawn_kwargs["env"][
"PORTAGE_GPG_KEY"
] = self.repo.sync_openpgp_key_path
self.spawn_kwargs["env"][
"PORTAGE_GPG_KEY_SERVER"
] = self.repo.sync_openpgp_keyserver
webrsync_cmd = [self.bin_command]
if verbose:
webrsync_cmd.append("-v")
elif quiet:
webrsync_cmd.append("-q")
if self.repo.module_specific_options.get(
"sync-webrsync-keep-snapshots", "false"
).lower() in ("true", "yes"):
webrsync_cmd.append("-k")
exitcode = portage.process.spawn(webrsync_cmd, **self.spawn_kwargs)
if exitcode != os.EX_OK:
msg = f"!!! emerge-webrsync error in {self.repo.location}"
self.logger(self.xterm_titles, msg)
writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1)
return (exitcode, False)
return (exitcode, True)
finally:
if openpgp_env is not None:
openpgp_env.close()
class PyWebRsync(SyncBase):
"""PyWebRsync sync class
TODO: Implement the sync parts from the emerge-webrsync external
binary to avoid split logic for various components, which
is how we ended up with bug #597800.
"""
short_desc = "Perform sync operations on webrsync based repositories"
@staticmethod
def name():
return "WebRSync"
def __init__(self):
SyncBase.__init__(self, None, ">=sys-apps/portage-2.3")
def sync(self, **kwargs):
"""Sync the repository"""
raise NotImplementedError(
"Python impl. of webrsync backend is not yet implemented"
)
|