Skip to content

Commit b073bbe

Browse files
authored
Merge pull request #296 from Z-Bolt/2.7.3-dev
2.7.3 dev into master
2 parents d102685 + 02adb46 commit b073bbe

34 files changed

+353
-191
lines changed

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ JESSIE_GO_TAGS := gtk_3_14
3232

3333
# Build information
3434
#GIT_COMMIT = $(shell git rev-parse HEAD | cut -c1-7)
35-
VERSION := 2.7.2
35+
VERSION := 2.7.3
3636
BUILD_DATE ?= $(shell date --utc +%Y%m%d-%H:%M:%S)
3737
#BRANCH = $(shell git rev-parse --abbrev-ref HEAD)
3838

README.md

+9-4
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,15 @@ There are two ways to install OctoScreen: the recommended and supported way is t
8383

8484
For example, to install on a new RaspberryPi with OctoPi:
8585
```sh
86-
wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.2/octoscreen_2.7.2_armhf.deb
87-
sudo dpkg -i octoscreen_2.7.2_armhf.deb
86+
wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.3/octoscreen_2.7.3_armhf.deb
87+
sudo dpkg -i octoscreen_2.7.3_armhf.deb
8888
```
8989

9090
Or to update an existing version of OctoScreen:
9191
```sh
92-
wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.2/octoscreen_2.7.2_armhf.deb
92+
wget https://github.com/Z-Bolt/OctoScreen/releases/download/v2.7.3/octoscreen_2.7.3_armhf.deb
9393
sudo dpkg -r octoscreen
94-
sudo dpkg -i octoscreen_2.7.2_armhf.deb
94+
sudo dpkg -i octoscreen_2.7.3_armhf.deb
9595
sudo reboot now
9696
```
9797

@@ -169,6 +169,11 @@ The controls are limit to static controls without `inputs`.
169169

170170

171171

172+
------------
173+
## Wiki
174+
For troubleshooting and general information about this project, be sure to check out the Wiki page, located at https://github.com/Z-Bolt/OctoScreen/wiki
175+
176+
172177

173178
------------
174179
<!--

interfaces/IPanel.go

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
)
66

77
type IPanel interface {
8+
Name() string
89
Grid() *gtk.Grid
910
PreShow()
1011
Show()

main.go

+1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ func main() {
122122
settings, _ := gtk.SettingsGetDefault()
123123
settings.SetProperty("gtk-application-prefer-dark-theme", true)
124124

125+
utils.DumpSystemInformation()
125126
utils.DumpEnvironmentVariables()
126127

127128
setCursor()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package octoprintApis
2+
3+
import (
4+
// "encoding/json"
5+
"fmt"
6+
7+
"github.com/Z-Bolt/OctoScreen/logger"
8+
"github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels"
9+
)
10+
11+
12+
var ExecuteErrors = StatusMapping {
13+
404: "The command could not be found for source and action",
14+
500: "The command didn’t define a command to execute, the command returned a non-zero return code and ignore was not true or some other internal server error occurred",
15+
}
16+
17+
// SystemExecuteCommandRequest retrieves all configured system commands.
18+
type SystemExecuteCommandRequest struct {
19+
// Source for which to list commands.
20+
Source dataModels.CommandSource `json:"source"`
21+
22+
// Action is the identifier of the command, action from its definition.
23+
Action string `json:"action"`
24+
}
25+
26+
// Do sends an API request and returns an error if any.
27+
func (this *SystemExecuteCommandRequest) Do(client *Client) error {
28+
uri := fmt.Sprintf("%s/%s/%s", SystemCommandsApiUri, this.Source, this.Action)
29+
_, err := client.doJsonRequest("POST", uri, nil, ExecuteErrors, true)
30+
if err != nil {
31+
logger.LogError("SystemExecuteCommandRequest.Do()", "client.doJsonRequest(POST)", err)
32+
}
33+
34+
return err
35+
}

octoprintApis/ZOffsetRequest.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ func (this *ZOffsetRequest) Do(client *Client) (*dataModels.ZOffsetResponse, err
2424
return nil, err
2525
}
2626

27-
// bytes, err := client.doJsonRequest("POST", URIZBoltRequest, params, ConnectionErrors)
27+
// bytes, err := client.doJsonRequest("POST", UriZBoltRequest, params, ConnectionErrors)
2828
bytes, err := client.doJsonRequest("GET", PluginZBoltApiUri, params, ConnectionErrors, true)
2929
if err != nil {
3030
logger.LogError("ZOffsetRequest.Do()", "client.doJsonRequest()", err)

octoprintApis/client.go

+60-23
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,14 @@ func (this *Client) doJsonRequest(
5858

5959
bytes, err := this.doRequest(method, target, "application/json", body, statusMapping, isRequired)
6060
if err != nil {
61-
if isRequired {
62-
// Some APIs return an error and the error should be logged.
63-
logger.LogError("Client.doJsonRequest()", "this.doRequest()", err)
64-
} else {
65-
// On the other hand, calls to some APIs are optional, and the result should be logged
66-
// as info and leave it up to the caller to determine whether it's an error or not.
67-
logger.Infof("Client.doJsonRequest() - this.doRequest() returned %q", err)
68-
}
69-
61+
logOptionalError("Client.doJsonRequest()", "this.doRequest()", err, isRequired)
7062
logger.TraceLeave("Client.doJsonRequest()")
7163
return nil, err
7264
}
7365

7466
// Use the following only for debugging.
7567
if logger.LogLevel() == "debug" {
68+
logger.Debug("Client.doJsonRequest() - converting bytes to JSON")
7669
json := string(bytes)
7770
logger.Debugf("JSON response: %s", json)
7871
}
@@ -124,59 +117,103 @@ func (this *Client) doRequest(
124117
logger.LogError("Client.doRequest()", "this.httpClient.Do()", err)
125118
logger.TraceLeave("Client.doRequest()")
126119
return nil, err
120+
} else {
121+
logger.Debug("Client.doRequest() - httpClient.Do() passed")
127122
}
128123

129-
bytes, err := this.handleResponse(response, statusMapping)
124+
bytes, err := this.handleResponse(response, statusMapping, isRequired)
130125
if err != nil {
131-
if isRequired {
132-
// Some APIs return an error and the error should be logged.
133-
logger.LogError("Client.doRequest()", "this.handleResponse()", err)
134-
} else {
135-
// On the other hand, calls to some APIs are optional, and the result should be logged
136-
// as info and leave it up to the caller to determine whether it's an error or not.
137-
logger.Infof("Client.doRequest() - this.handleResponse() returned %q", err)
138-
}
139-
logger.TraceLeave("Client.doRequest()")
140-
return nil, err
126+
logOptionalError("Client.doRequest()", "this.handleResponse()", err, isRequired)
127+
bytes = nil
128+
} else {
129+
logger.Debug("Client.doRequest() - handleResponse() passed")
141130
}
142131

143132
logger.TraceLeave("Client.doRequest()")
144133
return bytes, err
145134
}
146135

147-
148136
func (this *Client) handleResponse(
149137
httpResponse *http.Response,
150138
statusMapping StatusMapping,
139+
isRequired bool,
151140
) ([]byte, error) {
141+
logger.TraceEnter("Client.handleResponse()")
142+
152143
defer httpResponse.Body.Close()
153144

154145
if statusMapping != nil {
155146
if err := statusMapping.Error(httpResponse.StatusCode); err != nil {
147+
logger.LogError("Client.handleResponse()", "statusMapping.Error()", err)
148+
logger.TraceLeave("Client.handleResponse()")
156149
return nil, err
157150
}
158151
}
159152

160153
if httpResponse.StatusCode == 401 {
154+
logger.Error("Client.handleResponse() - StatusCode is 401")
155+
logger.TraceLeave("Client.handleResponse()")
161156
return nil, ErrUnauthorized
162157
}
163158

164159
if httpResponse.StatusCode == 204 {
160+
logger.Error("Client.handleResponse() - StatusCode is 204")
161+
logger.TraceLeave("Client.handleResponse()")
165162
return nil, nil
166163
}
167164

168165
body, err := ioutil.ReadAll(httpResponse.Body)
169166
if err != nil {
167+
logger.LogError("Client.handleResponse()", "ioutil.ReadAll()", err)
168+
logger.TraceLeave("Client.handleResponse()")
170169
return nil, err
171170
}
172171

173172
if httpResponse.StatusCode >= 200 && httpResponse.StatusCode <= 209 {
174-
return body, nil
173+
logger.Debugf("Client.handleResponse() - status code %d was within range", httpResponse.StatusCode)
174+
} else {
175+
errMsg := fmt.Sprintf("Unexpected status code: %d", httpResponse.StatusCode)
176+
if httpResponse.StatusCode == 404 {
177+
logOptionalMessage(errMsg, isRequired)
178+
} else {
179+
logger.Error(errMsg)
180+
}
181+
182+
err = fmt.Errorf(errMsg)
183+
body = nil
175184
}
176185

177-
return nil, fmt.Errorf("unexpected status code: %d", httpResponse.StatusCode)
186+
logger.TraceLeave("Client.handleResponse()")
187+
return body, err
188+
}
189+
190+
func logOptionalError(
191+
currentFunctionName string,
192+
functionCalledName string,
193+
err error,
194+
isRequired bool,
195+
) {
196+
if isRequired {
197+
// Some APIs return an error and the error should be logged.
198+
logger.LogError(currentFunctionName, functionCalledName, err)
199+
} else {
200+
// On the other hand, calls to some APIs are optional, and the result should be logged
201+
// as info and leave it up to the caller to determine whether it's an error or not.
202+
msg := fmt.Sprintf("%s - %s returned %q", currentFunctionName, functionCalledName, err)
203+
logger.Info(msg)
204+
}
178205
}
179206

207+
func logOptionalMessage(
208+
msg string,
209+
isRequired bool,
210+
) {
211+
if isRequired {
212+
logger.Error(msg)
213+
} else {
214+
logger.Info(msg)
215+
}
216+
}
180217

181218
func joinUrl(base, uri string) string {
182219
u, _ := url.Parse(uri)

octoprintApis/system.go

+12-33
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package octoprintApis
22

33
import (
44
"encoding/json"
5-
"fmt"
5+
// "fmt"
66

77
"github.com/Z-Bolt/OctoScreen/logger"
88
"github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels"
@@ -11,13 +11,6 @@ import (
1111

1212
const SystemCommandsApiUri = "/api/system/commands"
1313

14-
15-
var ExecuteErrors = StatusMapping {
16-
404: "The command could not be found for source and action",
17-
500: "The command didn’t define a command to execute, the command returned a non-zero return code and ignore was not true or some other internal server error occurred",
18-
}
19-
20-
2114
// SystemCommandsRequest retrieves all configured system commands.
2215
type SystemCommandsRequest struct{}
2316

@@ -35,39 +28,25 @@ func (cmd *SystemCommandsRequest) Do(c *Client) (*dataModels.SystemCommandsRespo
3528

3629
for i := range response.Core {
3730
commandDefinition := response.Core[i]
38-
err = json.Unmarshal(commandDefinition.RawConfirm, &commandDefinition.Confirm)
39-
if err != nil {
40-
logger.LogError("SystemCommandsRequest.Do()", "json.Unmarshal(Core)", err)
41-
commandDefinition.Confirm = ""
42-
return nil, err
43-
}
31+
convertRawConfirm(commandDefinition)
4432
}
4533

4634
for i := range response.Custom {
4735
commandDefinition := response.Custom[i]
48-
err = json.Unmarshal(commandDefinition.RawConfirm, &commandDefinition.Confirm)
49-
if err != nil {
50-
logger.LogError("SystemCommandsRequest.Do()", "json.Unmarshal(Custom)", err)
51-
commandDefinition.Confirm = ""
52-
return nil, err
53-
}
36+
convertRawConfirm(commandDefinition)
5437
}
5538

5639
return response, err
5740
}
5841

59-
// SystemExecuteCommandRequest retrieves all configured system commands.
60-
type SystemExecuteCommandRequest struct {
61-
// Source for which to list commands.
62-
Source dataModels.CommandSource `json:"source"`
63-
64-
// Action is the identifier of the command, action from its definition.
65-
Action string `json:"action"`
66-
}
42+
func convertRawConfirm(commandDefinition *dataModels.CommandDefinition) {
43+
if commandDefinition == nil || commandDefinition.RawConfirm == nil || len(commandDefinition.RawConfirm) < 1 {
44+
return
45+
}
6746

68-
// Do sends an API request and returns an error if any.
69-
func (cmd *SystemExecuteCommandRequest) Do(c *Client) error {
70-
uri := fmt.Sprintf("%s/%s/%s", SystemCommandsApiUri, cmd.Source, cmd.Action)
71-
_, err := c.doJsonRequest("POST", uri, nil, ExecuteErrors, true)
72-
return err
47+
err := json.Unmarshal(commandDefinition.RawConfirm, &commandDefinition.Confirm)
48+
if err != nil {
49+
logger.LogError("SystemCommandsRequest.convertRawConfirm()", "json.Unmarshal(Custom)", err)
50+
commandDefinition.Confirm = ""
51+
}
7352
}

ui/BedLevelPanel.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@ import (
44
"fmt"
55

66
"github.com/gotk3/gotk3/gtk"
7-
"github.com/Z-Bolt/OctoScreen/interfaces"
7+
8+
// "github.com/Z-Bolt/OctoScreen/interfaces"
89
"github.com/Z-Bolt/OctoScreen/logger"
910
"github.com/Z-Bolt/OctoScreen/octoprintApis"
1011
// "github.com/Z-Bolt/OctoScreen/octoprintApis/dataModels"
1112
"github.com/Z-Bolt/OctoScreen/utils"
1213
)
1314

15+
1416
var bedLevelPanelInstance *bedLevelPanel
1517

1618
type bedLevelPanel struct {
@@ -23,11 +25,10 @@ type bedLevelPanel struct {
2325

2426
func BedLevelPanel(
2527
ui *UI,
26-
parentPanel interfaces.IPanel,
2728
) *bedLevelPanel {
2829
if bedLevelPanelInstance == nil {
2930
instance := &bedLevelPanel {
30-
CommonPanel: NewCommonPanel(ui, parentPanel),
31+
CommonPanel: NewCommonPanel("BedLevelPanel", ui),
3132
}
3233
instance.initialize()
3334
bedLevelPanelInstance = instance

0 commit comments

Comments
 (0)