|
34 | 34 | # local imports
|
35 | 35 | import logger
|
36 | 36 | from kernelwindow import KernelWindow
|
37 |
| -from Classes import Update, PRIORITY_UPDATES, UpdateTracker, _idle, _async |
| 37 | +from Classes import Update, PRIORITY_UPDATES, CONFIG_PATH, UpdateTracker, _idle, _async |
38 | 38 |
|
39 | 39 |
|
40 | 40 | settings = Gio.Settings(schema_id="com.linuxmint.updates")
|
@@ -642,8 +642,9 @@ def show_updates_in_UI(self, num_visible, num_software, num_security, download_s
|
642 | 642 | self.ui_statusbar.set_visible(False)
|
643 | 643 | status_string = ""
|
644 | 644 | details = []
|
645 |
| - for update in updates: |
646 |
| - details.append(f"{update.source_name} {update.new_version}") |
| 645 | + |
| 646 | + for item in model_items: |
| 647 | + details.append(f"{item[0].source_name} {item[0].new_version}") |
647 | 648 | details = ", ".join(details)
|
648 | 649 | self.ui_label_self_update_details.set_text(details)
|
649 | 650 | else:
|
@@ -2141,10 +2142,70 @@ def refresh_flatpak_cache(self):
|
2141 | 2142 | def on_cache_updated(self, transaction=None, exit_state=None):
|
2142 | 2143 | self.refreshing_apt = False
|
2143 | 2144 |
|
| 2145 | + |
| 2146 | +# ---------------- Test Mode ------------------------------------------# |
| 2147 | + def dummy_update(self, check, package_name, kernel=False): |
| 2148 | + pkg = check.cache[package_name] |
| 2149 | + check.add_update(pkg, kernel, "99.0.0") |
| 2150 | + |
| 2151 | + # Part of check_apt_in_external_process fork |
| 2152 | + def handle_apt_check_test(self, queue): |
| 2153 | + test_mode = os.getenv("MINTUPDATE_TEST") |
| 2154 | + if test_mode is None: |
| 2155 | + return False |
| 2156 | + |
| 2157 | + if test_mode == "error": |
| 2158 | + # See how an error from checkAPT subprocess is handled |
| 2159 | + raise Exception("Testing - this is a simulated error.") |
| 2160 | + elif test_mode == "up-to-date": |
| 2161 | + # Simulate checkAPT finding no updates |
| 2162 | + queue.put([None, []]) |
| 2163 | + elif test_mode == "self-update": |
| 2164 | + # Simulate an update of mintupdate itself. |
| 2165 | + check = checkAPT.APTCheck() |
| 2166 | + self.dummy_update(check, "mintupdate", False) |
| 2167 | + queue.put([None, list(check.updates.values())]) |
| 2168 | + elif test_mode == "updates": |
| 2169 | + # Simulate some normal updates |
| 2170 | + check = checkAPT.APTCheck() |
| 2171 | + self.dummy_update(check, "python3", False) |
| 2172 | + self.dummy_update(check, "mint-meta-core", False) |
| 2173 | + self.dummy_update(check, "linux-generic", True) |
| 2174 | + self.dummy_update(check, "xreader", False) |
| 2175 | + queue.put([None, list(check.updates.values())]) |
| 2176 | + elif test_mode == "tracker-max-age": |
| 2177 | + # Simulate the UpdateTracker notifying about updates. |
| 2178 | + check = checkAPT.APTCheck() |
| 2179 | + self.dummy_update(check, "dnsmasq", False) |
| 2180 | + self.dummy_update(check, "linux-generic", True) |
| 2181 | + |
| 2182 | + updates_json = { |
| 2183 | + "mint-meta-common": { "type": "package", "since": "2020.12.03", "days": 99 }, |
| 2184 | + "linux-meta": { "type": "security", "since": "2020.12.03", "days": 99 } |
| 2185 | + } |
| 2186 | + root_json = { |
| 2187 | + "updates": updates_json, |
| 2188 | + "version": 1, |
| 2189 | + "checked": "2020.12.04", |
| 2190 | + "notified": "2020.12.03" |
| 2191 | + } |
| 2192 | + |
| 2193 | + os.makedirs(CONFIG_PATH, exist_ok=True) |
| 2194 | + with open(os.path.join(CONFIG_PATH, "updates.json"), "w") as f: |
| 2195 | + json.dump(root_json, f) |
| 2196 | + |
| 2197 | + queue.put([None, list(check.updates.values())]) |
| 2198 | + |
| 2199 | + return True |
| 2200 | +# ---------------- Testing ------------------------------------------# |
| 2201 | + |
2144 | 2202 | # called in a different process
|
2145 | 2203 | def check_apt_in_external_process(self, queue):
|
2146 | 2204 | # in the queue we put: error_message (None if successful), list_of_updates (None if error)
|
2147 | 2205 | try:
|
| 2206 | + if self.handle_apt_check_test(queue): |
| 2207 | + return |
| 2208 | + |
2148 | 2209 | check = checkAPT.APTCheck()
|
2149 | 2210 | check.find_changes()
|
2150 | 2211 | check.apply_l10n_descriptions()
|
@@ -2186,20 +2247,13 @@ def refresh_updates(self):
|
2186 | 2247 | try:
|
2187 | 2248 | error = None
|
2188 | 2249 | updates = None
|
2189 |
| - if os.getenv("MINTUPDATE_TEST") is None: |
2190 |
| - output = subprocess.run("/usr/lib/linuxmint/mintUpdate/checkAPT.py", stdout=subprocess.PIPE).stdout.decode("utf-8") |
2191 |
| - # call checkAPT in a different process |
2192 |
| - queue = Queue() |
2193 |
| - process = Process(target=self.check_apt_in_external_process, args=(queue,)) |
2194 |
| - process.start() |
2195 |
| - error, updates = queue.get() |
2196 |
| - process.join() |
2197 |
| - # TODO rewrite tests to deal with classes vs text lines |
2198 |
| - # else: |
2199 |
| - # if os.path.exists("/usr/share/linuxmint/mintupdate/tests/%s.test" % os.getenv("MINTUPDATE_TEST")): |
2200 |
| - # output = subprocess.run("sleep 1; cat /usr/share/linuxmint/mintupdate/tests/%s.test" % os.getenv("MINTUPDATE_TEST"), shell=True, stdout=subprocess.PIPE).stdout.decode("utf-8") |
2201 |
| - # else: |
2202 |
| - # output = subprocess.run("/usr/lib/linuxmint/mintUpdate/checkAPT.py", stdout=subprocess.PIPE).stdout.decode("utf-8") |
| 2250 | + |
| 2251 | + # call checkAPT in a different process |
| 2252 | + queue = Queue() |
| 2253 | + process = Process(target=self.check_apt_in_external_process, args=[queue]) |
| 2254 | + process.start() |
| 2255 | + error, updates = queue.get() |
| 2256 | + process.join() |
2203 | 2257 |
|
2204 | 2258 | if error is not None:
|
2205 | 2259 | self.logger.write_error("Error in checkAPT.py, could not refresh the list of updates")
|
|
0 commit comments