瀏覽代碼

add fallback urls to all include_url calls. improve http timeout handling.

Thomas B 2 月之前
父節點
當前提交
b2959c258f

+ 12
- 3
input/projects/3d-printing/i3-am8.md 查看文件

@@ -264,7 +264,10 @@ function copyEvent(id) {
264 264
 
265 265
 <pre id="printercfg" class="sh_desktop">
266 266
 <!--%
267
-include_url("https://git.xythobuz.de/thomas/3d-print-designs/raw/branch/master/configs/i3-AM8/printer.cfg")
267
+include_url(
268
+    "https://git.xythobuz.de/thomas/3d-print-designs/raw/branch/master/configs/i3-AM8/printer.cfg",
269
+    "https://codeberg.org/xythobuz/3d-print-designs/raw/branch/master/configs/i3-AM8/printer.cfg"
270
+)
268 271
 %-->
269 272
 </pre>
270 273
 
@@ -273,7 +276,10 @@ include_url("https://git.xythobuz.de/thomas/3d-print-designs/raw/branch/master/c
273 276
 
274 277
 <pre id="moonrakerconf" class="sh_desktop">
275 278
 <!--%
276
-include_url("https://git.xythobuz.de/thomas/3d-print-designs/raw/branch/master/configs/i3-AM8/moonraker.conf")
279
+include_url(
280
+    "https://git.xythobuz.de/thomas/3d-print-designs/raw/branch/master/configs/i3-AM8/moonraker.conf",
281
+    "https://codeberg.org/xythobuz/3d-print-designs/raw/branch/master/configs/i3-AM8/moonraker.conf"
282
+)
277 283
 %-->
278 284
 </pre>
279 285
 
@@ -282,7 +288,10 @@ And [here](https://git.xythobuz.de/thomas/3d-print-designs/raw/branch/master/con
282 288
 
283 289
 <pre id="prusabundle" class="sh_desktop">
284 290
 <!--%
285
-include_url("https://git.xythobuz.de/thomas/3d-print-designs/raw/branch/master/configs/i3-AM8/PrusaSlicer_config_bundle.ini")
291
+include_url(
292
+    "https://git.xythobuz.de/thomas/3d-print-designs/raw/branch/master/configs/i3-AM8/PrusaSlicer_config_bundle.ini",
293
+    "https://codeberg.org/xythobuz/3d-print-designs/raw/branch/master/configs/i3-AM8/PrusaSlicer_config_bundle.ini"
294
+)
286 295
 %-->
287 296
 </pre>
288 297
 

+ 4
- 1
input/projects/3d-printing/sparkmaker_repair.md 查看文件

@@ -144,7 +144,10 @@ The route to take was therefore obvious: write a script that takes `.sl1` files
144 144
 
145 145
 <pre class="sh_python">
146 146
 <!--%
147
-include_url("https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/tools/convert_sparkmaker.py")
147
+include_url(
148
+    "https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/tools/convert_sparkmaker.py",
149
+    "https://codeberg.org/xythobuz/gcode-tools/raw/branch/master/tools/convert_sparkmaker.py"
150
+)
148 151
 %-->
149 152
 </pre>
150 153
 

+ 20
- 5
input/projects/laser-engraver.md 查看文件

@@ -275,7 +275,10 @@ But my script below should work for all variants I have seen up to now.
275 275
 
276 276
 <pre class="sh_python">
277 277
 <!--%
278
-include_url("https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/tools/convert_lasergrbl.py")
278
+include_url(
279
+    "https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/tools/convert_lasergrbl.py",
280
+    "https://codeberg.org/xythobuz/gcode-tools/raw/branch/master/tools/convert_lasergrbl.py"
281
+)
279 282
 %-->
280 283
 </pre>
281 284
 
@@ -338,7 +341,10 @@ I copy this file to the SD card, start it, and just abort it when I'm done with
338 341
 
339 342
 <pre class="sh_python">
340 343
 <!--%
341
-include_url("https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/tools/outline_gcode.py")
344
+include_url(
345
+    "https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/tools/outline_gcode.py",
346
+    "https://codeberg.org/xythobuz/gcode-tools/raw/branch/master/tools/outline_gcode.py"
347
+)
342 348
 %-->
343 349
 </pre>
344 350
 
@@ -349,7 +355,10 @@ It's drawing a grid for reference on the base plate of the machine, including nu
349 355
 
350 356
 <pre class="sh_python">
351 357
 <!--%
352
-include_url("https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/generators/grid_gcode.py")
358
+include_url(
359
+    "https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/generators/grid_gcode.py",
360
+    "https://codeberg.org/xythobuz/gcode-tools/raw/branch/master/generators/grid_gcode.py"
361
+)
353 362
 %-->
354 363
 </pre>
355 364
 
@@ -375,7 +384,10 @@ As I grew tired of removing, flashing and re-inserting of the SD card, I decided
375 384
 
376 385
 <pre class="sh_python">
377 386
 <!--%
378
-include_url("https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/tools/send_gcode.py")
387
+include_url(
388
+    "https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/tools/send_gcode.py",
389
+    "https://codeberg.org/xythobuz/gcode-tools/raw/branch/master/tools/send_gcode.py"
390
+)
379 391
 %-->
380 392
 </pre>
381 393
 
@@ -390,7 +402,10 @@ I then made another Python script go generate G-Code for a cutting test, varying
390 402
 
391 403
 <pre class="sh_python">
392 404
 <!--%
393
-include_url("https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/generators/cut_test_gcode.py")
405
+include_url(
406
+    "https://git.xythobuz.de/thomas/gcode-tools/raw/branch/master/generators/cut_test_gcode.py",
407
+    "https://codeberg.org/xythobuz/gcode-tools/raw/branch/master/generators/cut_test_gcode.py"
408
+)
394 409
 %-->
395 410
 </pre>
396 411
 

+ 9
- 2
input/projects/osci_music_player.md 查看文件

@@ -2,6 +2,7 @@ title: Oscilloscope Music Player
2 2
 description: Properly playing sound files for visualization on an oscilloscope
3 3
 parent: projects
4 4
 git: https://git.xythobuz.de/thomas/osci-music-player
5
+github: https://github.com/xythobuz/osci-music-player
5 6
 date: 2024-02-11
6 7
 update: 2024-03-08
7 8
 comments: true
@@ -257,7 +258,10 @@ Here is [`~/osci-pi.py`](https://git.xythobuz.de/thomas/osci-music-player/raw/br
257 258
 
258 259
 <pre id="oscipipy" class="sh_python">
259 260
 <!--%
260
-include_url("https://git.xythobuz.de/thomas/osci-music-player/raw/branch/master/osci-pi.py")
261
+include_url(
262
+    "https://git.xythobuz.de/thomas/osci-music-player/raw/branch/master/osci-pi.py",
263
+    "https://raw.githubusercontent.com/xythobuz/osci-music-player/refs/heads/master/osci-pi.py"
264
+)
261 265
 %-->
262 266
 </pre>
263 267
 
@@ -267,7 +271,10 @@ Adjust the username and path accordingly.
267 271
 
268 272
 <pre id="osciservice" class="sh_desktop">
269 273
 <!--%
270
-include_url("https://git.xythobuz.de/thomas/osci-music-player/raw/branch/master/osci.service")
274
+include_url(
275
+    "https://git.xythobuz.de/thomas/osci-music-player/raw/branch/master/osci.service",
276
+    "https://raw.githubusercontent.com/xythobuz/osci-music-player/refs/heads/master/osci.service"
277
+)
271 278
 %-->
272 279
 </pre>
273 280
 

+ 7
- 6
macros.py 查看文件

@@ -509,9 +509,9 @@ def print_cnsl_error(s, url):
509 509
     sys.stderr.write("warning: !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n")
510 510
     sys.stderr.write("\n")
511 511
 
512
-def http_request(url):
512
+def http_request(url, timeout = 5):
513 513
     if PY3:
514
-        response = urllib.request.urlopen(url, timeout = 5)
514
+        response = urllib.request.urlopen(url, timeout = timeout)
515 515
     else:
516 516
         response = urllib.urlopen(url)
517 517
 
@@ -521,19 +521,20 @@ def http_request(url):
521 521
     data = response.read().decode("utf-8")
522 522
     return data
523 523
 
524
-def include_url(url, fallback = None):
524
+def include_url(url, fallback = None, timeout = 2):
525 525
     sys.stderr.write('sub    : fetching page "%s"\n' % url)
526 526
 
527 527
     if fallback == None:
528 528
         print_cnsl_error("include_url() without fallback option", url)
529
+        timeout = timeout * 3
529 530
 
530 531
     try:
531
-        data = http_request(url)
532
+        data = http_request(url, timeout)
532 533
     except Exception as e:
533 534
         if fallback != None:
534
-            sys.stderr.write('sub    : fetching fallback page "%s"\n' % url)
535
+            sys.stderr.write('sub    : fetching fallback page "%s"\n' % fallback)
535 536
             try:
536
-                data = http_request(fallback)
537
+                data = http_request(fallback, timeout * 3)
537 538
             except Exception as e:
538 539
                 print_cnsl_error(str(e), fallback)
539 540
                 return

Loading…
取消
儲存