浏览代码

added github release helper to octotray and openraider

Thomas Buck 4 年前
父节点
当前提交
910c2050b6
共有 4 个文件被更改,包括 74 次插入1 次删除
  1. 5
    1
      input/projects/3d-printing/octotray.md
  2. 4
    0
      input/projects/openraider.md
  3. 55
    0
      macros.py
  4. 10
    0
      static/css/style.css

+ 5
- 1
input/projects/3d-printing/octotray.md 查看文件

10
 
10
 
11
 <span class="listdesc">[...back to 3D-Printing overview](3d-printing.html)</span>
11
 <span class="listdesc">[...back to 3D-Printing overview](3d-printing.html)</span>
12
 
12
 
13
+<!--%
14
+printLatestRelease("xythobuz", "OctoTray")
15
+%-->
16
+
13
 To quickly print new stuff on one of my printers, I am using the [OctoPrint](https://octoprint.org) integration of [PrusaSlicer](https://github.com/prusa3d/PrusaSlicer).
17
 To quickly print new stuff on one of my printers, I am using the [OctoPrint](https://octoprint.org) integration of [PrusaSlicer](https://github.com/prusa3d/PrusaSlicer).
14
 Unfortunately, it does not allow me to turn on the printers power supply using the Raspberry Pi.
18
 Unfortunately, it does not allow me to turn on the printers power supply using the Raspberry Pi.
15
 But it is possible to do that via the [OctoPrint REST API](https://docs.octoprint.org/en/master/api/index.html).
19
 But it is possible to do that via the [OctoPrint REST API](https://docs.octoprint.org/en/master/api/index.html).
16
 Because of that, I wrote a small tool to trigger the power of my printers that lives in the system tray.
20
 Because of that, I wrote a small tool to trigger the power of my printers that lives in the system tray.
17
-It runs on Linux using the Python Qt5 bindings, but without much work it should be able to run on other platforms with PyQt5 as well.
21
+It runs on Linux using the Python Qt5 bindings, but it has been tested on Windows and should run on macOS as well.
18
 
22
 
19
 <!--%
23
 <!--%
20
 lightgallery([
24
 lightgallery([

+ 4
- 0
input/projects/openraider.md 查看文件

10
 I also wanted to learn a bit about 3D graphics and OpenGL.
10
 I also wanted to learn a bit about 3D graphics and OpenGL.
11
 Without planning it, I completely rewrote the whole project in a span of about two years.
11
 Without planning it, I completely rewrote the whole project in a span of about two years.
12
 
12
 
13
+<!--%
14
+printLatestRelease("xythobuz", "OpenRaider")
15
+%-->
16
+
13
 I wrote some blog posts about OpenRaider.
17
 I wrote some blog posts about OpenRaider.
14
 
18
 
15
 * [Initial blog post about fork](2014_03_22_openraider.html)
19
 * [Initial blog post about fork](2014_03_22_openraider.html)

+ 55
- 0
macros.py 查看文件

55
     print '</div>'
55
     print '</div>'
56
 
56
 
57
 # -----------------------------------------------------------------------------
57
 # -----------------------------------------------------------------------------
58
+# github helper macros
59
+# -----------------------------------------------------------------------------
60
+
61
+import urllib, json
62
+
63
+def restRequest(url):
64
+    response = urllib.urlopen(url)
65
+    data = json.loads(response.read())
66
+    return data
67
+
68
+def restReleases(user, repo):
69
+    s = "https://api.github.com/repos/"
70
+    s += user
71
+    s += "/"
72
+    s += repo
73
+    s += "/releases"
74
+    return restRequest(s)
75
+
76
+def printLatestRelease(user, repo):
77
+    repo_url = "https://github.com/" + user + "/" + repo
78
+    print("<div class=\"releasecard\">")
79
+    print("Release builds for " + repo + " are <a href=\"" + repo_url + "/releases\">available on GitHub</a>.<br>\n")
80
+
81
+    releases = restReleases(user, repo)
82
+    if len(releases) <= 0:
83
+        print("No release has been published on GitHub yet.")
84
+        print("</div>")
85
+        return
86
+
87
+    releases.sort(key=lambda x: x["published_at"], reverse=True)
88
+    r = releases[0]
89
+    release_url = r["html_url"]
90
+    print("Latest release of <a href=\"" + repo_url + "\">" + repo + "</a>, at the time of this writing: <a href=\"" + release_url + "\">" + r["name"] + "</a> (" + datetime.strptime(r["published_at"], "%Y-%m-%dT%H:%M:%SZ").strftime("%Y-%m-%d %H:%M:%S") + ")\n")
91
+
92
+    if len(r["assets"]) <= 0:
93
+        print("<br>No release assets have been published on GitHub for that.")
94
+        print("</div>")
95
+        return
96
+
97
+    print("<ul>")
98
+    print("Release Assets:")
99
+    for a in r["assets"]:
100
+        size = int(a["size"])
101
+        ss = " "
102
+        if size >= (1024 * 1024):
103
+            ss += "(%.1f MiB)" % (size / (1024.0 * 1024.0))
104
+        elif size >= 1024:
105
+            ss += "(%d KiB)" % (size // 1024)
106
+        else:
107
+            ss += "(%d Byte)" % (size)
108
+
109
+        print("<li><a href=\"" + a["browser_download_url"] + "\">" + a["name"] + "</a>" + ss)
110
+    print("</ul></div>")
111
+
112
+# -----------------------------------------------------------------------------
58
 # preconvert hooks
113
 # preconvert hooks
59
 # -----------------------------------------------------------------------------
114
 # -----------------------------------------------------------------------------
60
 
115
 

+ 10
- 0
static/css/style.css 查看文件

76
     color: blue;
76
     color: blue;
77
 }
77
 }
78
 
78
 
79
+.releasecard {
80
+    border: 2px solid purple;
81
+    width: max-content;
82
+    padding: 0.6em 1em 0em 1em;
83
+    border-radius: 10px;
84
+    background-color: lightgray;
85
+    text-align: center;
86
+    margin: auto;
87
+}
88
+
79
 #home {
89
 #home {
80
     font-size: 2.5em;
90
     font-size: 2.5em;
81
     margin-right: 0.5em;
91
     margin-right: 0.5em;

正在加载...
取消
保存