|
3 | 3 |
|
4 | 4 |
|
5 | 5 | def reboot(): |
| 6 | + """When called the node will be rebooted""" |
6 | 7 | subprocess.call(["sudo", "reboot"]) |
7 | 8 |
|
8 | 9 |
|
9 | 10 | def shutdown(): |
| 11 | + """When called the node will be shut down, make sure you can turn it back on if needed!""" |
10 | 12 | subprocess.call(["sudo", "shutdown", "-h"]) |
11 | 13 |
|
12 | 14 |
|
13 | 15 | def update_node(): |
14 | | - node_update_log_1 = subprocess.check_output(["sudo", "apt-get", "update"]) |
15 | | - node_update_log_2 = subprocess.check_output(["sudo", "apt-get", "upgrade"]) |
| 16 | + """When called the node will run apt update followed by apt upgrade""" |
| 17 | + node_update_log_1 = subprocess.check_output(["sudo", "apt", "update"]) |
| 18 | + node_update_log_2 = subprocess.check_output(["sudo", "apt", "upgrade", "-y"]) |
16 | 19 | return [node_update_log_1, node_update_log_2] |
17 | 20 |
|
18 | 21 |
|
19 | 22 | def get_node_time(): |
| 23 | + """Returns the current node time which may be useful for times when the Pi clock might be out of sync""" |
20 | 24 | return time.time() |
21 | 25 |
|
22 | 26 |
|
23 | 27 | def get_node_codebase_revision(): |
| 28 | + """Gets the revision of the codebase currently on the filesystem |
| 29 | +
|
| 30 | + TODO: Improve this so we store the revision "on load" rather than hoping its the same |
| 31 | + """ |
24 | 32 | # Note: This is not necessarily the revision of the code currently running |
25 | 33 | current_rev = subprocess.check_output(["git", "rev-parse", "HEAD"]) |
26 | 34 | return current_rev.rstrip("\r\n") |
27 | 35 |
|
28 | 36 |
|
29 | 37 | def get_node_codebase_revision_time(): |
| 38 | + """Gets the time of the revision of the codebase currently on the filesystem |
| 39 | +
|
| 40 | + TODO: Improve this so we store the revision "on load" rather than hoping its the same |
| 41 | + """ |
30 | 42 | node_rev = get_node_codebase_revision() |
31 | 43 | rev_time = subprocess.check_output(["git", "show", "-s", "--format=%ct", node_rev]) |
32 | 44 | return int(rev_time.rstrip("\r\n")) |
33 | 45 |
|
34 | 46 |
|
35 | 47 | def update_node_codebase(): |
| 48 | + """Updates the codebase using git pull, note if any local changes are present this might fail horribly """ |
36 | 49 | update_log = subprocess.check_output(["git", "pull"]) |
37 | 50 | return update_log |
38 | 51 |
|
|
0 commit comments