|
5 | 5 | import sh
|
6 | 6 | import socket
|
7 | 7 | import sqlite3
|
| 8 | +import re |
8 | 9 | import utils
|
9 | 10 | from pprint import pprint
|
10 | 11 | from uptime import uptime
|
@@ -111,6 +112,34 @@ def get_load_avg():
|
111 | 112 | return load_avg
|
112 | 113 |
|
113 | 114 |
|
| 115 | +def get_git_branch(): |
| 116 | + screenly_path = os.path.join(os.getenv('HOME'), 'screenly', '.git') |
| 117 | + try: |
| 118 | + get_hash = sh.git( |
| 119 | + '--git-dir={}'.format(screenly_path), |
| 120 | + 'rev-parse', |
| 121 | + '--abbrev-ref', |
| 122 | + 'HEAD' |
| 123 | + ) |
| 124 | + return get_hash.stdout.strip() |
| 125 | + except: |
| 126 | + return 'Unable to get git branch.' |
| 127 | + |
| 128 | + |
| 129 | +def get_git_short_hash(): |
| 130 | + screenly_path = os.path.join(os.getenv('HOME'), 'screenly', '.git') |
| 131 | + try: |
| 132 | + get_hash = sh.git( |
| 133 | + '--git-dir={}'.format(screenly_path), |
| 134 | + 'rev-parse', |
| 135 | + '--short', |
| 136 | + 'HEAD' |
| 137 | + ) |
| 138 | + return get_hash.stdout.strip() |
| 139 | + except: |
| 140 | + return 'Unable to get git hash.' |
| 141 | + |
| 142 | + |
114 | 143 | def get_git_hash():
|
115 | 144 | screenly_path = os.path.join(os.getenv('HOME'), 'screenly', '.git')
|
116 | 145 | try:
|
@@ -159,6 +188,124 @@ def get_debian_version():
|
159 | 188 | return 'Unable to get Debian version.'
|
160 | 189 |
|
161 | 190 |
|
| 191 | +def get_raspberry_code(): |
| 192 | + matches = re.findall(r'\:(.*)', sh.grep('Revision', '/proc/cpuinfo').stdout) |
| 193 | + if matches: |
| 194 | + return matches[0].strip() |
| 195 | + |
| 196 | + |
| 197 | +def get_raspberry_model(): |
| 198 | + """ |
| 199 | + Data source |
| 200 | + https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md |
| 201 | + """ |
| 202 | + models = { |
| 203 | + '900021': 'Model A+', |
| 204 | + '900032': 'Model B+', |
| 205 | + '900092': 'Model Zero', |
| 206 | + '920092': 'Model Zero', |
| 207 | + '900093': 'Model Zero', |
| 208 | + '9000c1': 'Model Zero W', |
| 209 | + '920093': 'Model Zero', |
| 210 | + 'a01040': 'Model 2B', |
| 211 | + 'a01041': 'Model 2B', |
| 212 | + 'a02082': 'Model 3B', |
| 213 | + 'a020a0': 'Model CM3', |
| 214 | + 'a21041': 'Model 2B', |
| 215 | + 'a22042': 'Model 2B (with BCM2837)', |
| 216 | + 'a22082': 'Model 3B', |
| 217 | + 'a32082': 'Model 3B', |
| 218 | + 'a52082': 'Model 3B', |
| 219 | + 'a020d3': 'Model 3B+', |
| 220 | + '9020e0': 'Model 3A+' |
| 221 | + } |
| 222 | + return models.get(get_raspberry_code()) |
| 223 | + |
| 224 | + |
| 225 | +def get_raspberry_revision(): |
| 226 | + """ |
| 227 | + Data source |
| 228 | + https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md |
| 229 | + """ |
| 230 | + revisions = { |
| 231 | + '900021': '1.1', |
| 232 | + '900032': '1.2', |
| 233 | + '900092': '1.2', |
| 234 | + '920092': '1.2', |
| 235 | + '900093': '1.3', |
| 236 | + '9000c1': '1.1', |
| 237 | + '920093': '1.3', |
| 238 | + 'a01040': '1.0', |
| 239 | + 'a01041': '1.1', |
| 240 | + 'a02082': '1.2', |
| 241 | + 'a020a0': '1.0', |
| 242 | + 'a21041': '1.1', |
| 243 | + 'a22042': '1.2', |
| 244 | + 'a22082': '1.2', |
| 245 | + 'a32082': '1.2', |
| 246 | + 'a52082': '1.2', |
| 247 | + 'a020d3': '1.3', |
| 248 | + '9020e0': '1.0' |
| 249 | + } |
| 250 | + return revisions.get(get_raspberry_code()) |
| 251 | + |
| 252 | + |
| 253 | +def get_raspberry_ram(): |
| 254 | + """ |
| 255 | + Data source |
| 256 | + https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md |
| 257 | + """ |
| 258 | + rams = { |
| 259 | + '900021': '512 MB', |
| 260 | + '900032': '512 MB', |
| 261 | + '900092': '512 MB', |
| 262 | + '920092': '512 MB', |
| 263 | + '900093': '512 MB', |
| 264 | + '9000c1': '512 MB', |
| 265 | + '920093': '512 MB', |
| 266 | + 'a01040': '1 GB', |
| 267 | + 'a01041': '1 GB', |
| 268 | + 'a02082': '1 GB', |
| 269 | + 'a020a0': '1 GB', |
| 270 | + 'a21041': '1 GB', |
| 271 | + 'a22042': '1 GB', |
| 272 | + 'a22082': '1 GB', |
| 273 | + 'a32082': '1 GB', |
| 274 | + 'a52082': '1 GB', |
| 275 | + 'a020d3': '1 GB', |
| 276 | + '9020e0': '512 MB' |
| 277 | + } |
| 278 | + return rams.get(get_raspberry_code()) |
| 279 | + |
| 280 | + |
| 281 | +def get_raspberry_manufacturer(): |
| 282 | + """ |
| 283 | + Data source |
| 284 | + https://www.raspberrypi.org/documentation/hardware/raspberrypi/revision-codes/README.md |
| 285 | + """ |
| 286 | + manufacturers = { |
| 287 | + '900021': 'Sony UK', |
| 288 | + '900032': 'Sony UK', |
| 289 | + '900092': 'Sony UK', |
| 290 | + '920092': 'Embest', |
| 291 | + '900093': 'Sony UK', |
| 292 | + '9000c1': 'Sony UK', |
| 293 | + '920093': 'Embest', |
| 294 | + 'a01040': 'Sony UK', |
| 295 | + 'a01041': 'Sony UK', |
| 296 | + 'a02082': 'Sony UK', |
| 297 | + 'a020a0': 'Sony UK', |
| 298 | + 'a21041': 'Embest', |
| 299 | + 'a22042': 'Embest', |
| 300 | + 'a22082': 'Embest', |
| 301 | + 'a32082': 'Sony Japan', |
| 302 | + 'a52082': 'Stadium', |
| 303 | + 'a020d3': 'Sony UK', |
| 304 | + '9020e0': 'Sony UK' |
| 305 | + } |
| 306 | + return manufacturers.get(get_raspberry_code()) |
| 307 | + |
| 308 | + |
162 | 309 | def compile_report():
|
163 | 310 | report = {}
|
164 | 311 | report['cpu_info'] = parse_cpu_info()
|
|
0 commit comments