Skip to content

Commit e0cf437

Browse files
jmbergkuba-moo
authored andcommitted
pw_poller: make list module configurable
There only is a 'netdev' module now, but make that configuration so we can add other modules (i.e. wireless) later. Put the names of trees into the module instead of hard-coding. Signed-off-by: Johannes Berg <[email protected]>
1 parent fffbdaf commit e0cf437

File tree

2 files changed

+19
-12
lines changed

2 files changed

+19
-12
lines changed

netdev/__init__.py

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@
1212
series_tree_name_should_be_local, \
1313
series_is_a_fix_for, \
1414
series_needs_async
15+
16+
current_tree = 'net'
17+
next_tree = 'net-next'

pw_poller.py

+16-12
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import time
1313
import queue
1414
from typing import Dict
15+
from importlib import import_module
1516

1617
from core import NIPA_DIR
1718
from core import NipaLifetime
@@ -21,7 +22,6 @@
2122
from pw import Patchwork
2223
from pw import PwSeries
2324
import core
24-
import netdev
2525

2626

2727
class IncompleteSeries(Exception):
@@ -80,6 +80,9 @@ def __init__(self, config) -> None:
8080
self._recheck_period = config.getint('poller', 'recheck_period', fallback=3)
8181
self._recheck_lookback = config.getint('poller', 'recheck_lookback', fallback=9)
8282

83+
listmodname = config.get('list', 'module', fallback='netdev')
84+
self.list_module = import_module(listmodname)
85+
8386
def init_state_from_disk(self) -> None:
8487
try:
8588
with open('poller.state', 'r') as f:
@@ -91,28 +94,28 @@ def init_state_from_disk(self) -> None:
9194
pass
9295

9396
def _series_determine_tree(self, s: PwSeries) -> str:
94-
s.tree_name = netdev.series_tree_name_direct(s)
97+
s.tree_name = self.list_module.series_tree_name_direct(s)
9598
s.tree_mark_expected = True
9699
s.tree_marked = bool(s.tree_name)
97100

98101
if s.is_pure_pull():
99102
if s.title.find('-next') >= 0:
100-
s.tree_name = 'net-next'
103+
s.tree_name = self.list_module.next_tree
101104
else:
102-
s.tree_name = 'net'
105+
s.tree_name = self.list_module.current_tree
103106
s.tree_mark_expected = None
104107
return f"Pull request for {s.tree_name}"
105108

106109
if s.tree_name:
107110
log(f'Series is clearly designated for: {s.tree_name}', "")
108111
return f"Clearly marked for {s.tree_name}"
109112

110-
s.tree_mark_expected, should_test = netdev.series_tree_name_should_be_local(s)
113+
s.tree_mark_expected, should_test = self.list_module.series_tree_name_should_be_local(s)
111114
if not should_test:
112115
log("No tree designation found or guessed", "")
113116
return "Not a local patch"
114117

115-
if netdev.series_ignore_missing_tree_name(s):
118+
if self.list_module.series_ignore_missing_tree_name(s):
116119
s.tree_mark_expected = None
117120
log('Okay to ignore lack of tree in subject, ignoring series', "")
118121
return "Series ignored based on subject"
@@ -122,11 +125,12 @@ def _series_determine_tree(self, s: PwSeries) -> str:
122125
else:
123126
log_open_sec('Series okay without a tree designation')
124127

125-
# TODO: make this configurable
126-
if "net" in self._trees and netdev.series_is_a_fix_for(s, self._trees["net"]):
127-
s.tree_name = "net"
128-
elif "net-next" in self._trees and self._trees["net-next"].check_applies(s):
129-
s.tree_name = "net-next"
128+
if self.list_module.current_tree in self._trees and \
129+
self.list_module.series_is_a_fix_for(s, self._trees[self.list_module.current_tree]):
130+
s.tree_name = self.list_module.current_tree
131+
elif self.list_module.next_tree in self._trees and \
132+
self._trees[self.list_module.next_tree].check_applies(s):
133+
s.tree_name = self.list_module.next_tree
130134

131135
if s.tree_name:
132136
log(f"Target tree - {s.tree_name}", "")
@@ -166,7 +170,7 @@ def _process_series(self, pw_series) -> None:
166170
raise IncompleteSeries
167171

168172
comment = self.series_determine_tree(s)
169-
s.need_async = netdev.series_needs_async(s)
173+
s.need_async = self.list_module.series_needs_async(s)
170174
if s.need_async:
171175
comment += ', async'
172176

0 commit comments

Comments
 (0)