Fix most remaining LGTM alerts (#1893)
* fixups from LGTM * short globals * fix spinner and textwindow * total ordering * no spinner/text window when import from manager * not androidalbatross
parent
b299a1b9bb
commit
5db81f60ca
|
@ -4,14 +4,17 @@ from common.basedir import BASEDIR
|
|||
|
||||
|
||||
class Spinner():
|
||||
def __init__(self):
|
||||
try:
|
||||
self.spinner_proc = subprocess.Popen(["./spinner"],
|
||||
stdin=subprocess.PIPE,
|
||||
cwd=os.path.join(BASEDIR, "selfdrive", "ui", "spinner"),
|
||||
close_fds=True)
|
||||
except OSError:
|
||||
self.spinner_proc = None
|
||||
def __init__(self, noop=False):
|
||||
# spinner is currently only implemented for android
|
||||
self.spinner_proc = None
|
||||
if not noop:
|
||||
try:
|
||||
self.spinner_proc = subprocess.Popen(["./spinner"],
|
||||
stdin=subprocess.PIPE,
|
||||
cwd=os.path.join(BASEDIR, "selfdrive", "ui", "spinner"),
|
||||
close_fds=True)
|
||||
except OSError:
|
||||
self.spinner_proc = None
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
@ -40,23 +43,6 @@ class Spinner():
|
|||
self.close()
|
||||
|
||||
|
||||
class FakeSpinner(Spinner):
|
||||
def __init__(self): # pylint: disable=super-init-not-called
|
||||
pass
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def update(self, _):
|
||||
pass
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import time
|
||||
with Spinner() as s:
|
||||
|
|
|
@ -6,20 +6,22 @@ from common.basedir import BASEDIR
|
|||
|
||||
|
||||
class TextWindow():
|
||||
def __init__(self, s):
|
||||
try:
|
||||
self.text_proc = subprocess.Popen(["./text", s],
|
||||
stdin=subprocess.PIPE,
|
||||
cwd=os.path.join(BASEDIR, "selfdrive", "ui", "text"),
|
||||
close_fds=True)
|
||||
except OSError:
|
||||
self.text_proc = None
|
||||
def __init__(self, s, noop=False):
|
||||
# text window is only implemented for android currently
|
||||
self.text_proc = None
|
||||
if not noop:
|
||||
try:
|
||||
self.text_proc = subprocess.Popen(["./text", s],
|
||||
stdin=subprocess.PIPE,
|
||||
cwd=os.path.join(BASEDIR, "selfdrive", "ui", "text"),
|
||||
close_fds=True)
|
||||
except OSError:
|
||||
self.text_proc = None
|
||||
|
||||
def get_status(self):
|
||||
if self.text_proc is not None:
|
||||
self.text_proc.poll()
|
||||
return self.text_proc.returncode
|
||||
|
||||
return None
|
||||
|
||||
def __enter__(self):
|
||||
|
@ -31,10 +33,11 @@ class TextWindow():
|
|||
self.text_proc = None
|
||||
|
||||
def wait_for_exit(self):
|
||||
while True:
|
||||
if self.get_status() == 1:
|
||||
return
|
||||
time.sleep(0.1)
|
||||
if self.text_proc is not None:
|
||||
while True:
|
||||
if self.get_status() == 1:
|
||||
return
|
||||
time.sleep(0.1)
|
||||
|
||||
def __del__(self):
|
||||
self.close()
|
||||
|
@ -43,29 +46,6 @@ class TextWindow():
|
|||
self.close()
|
||||
|
||||
|
||||
class FakeTextWindow(TextWindow):
|
||||
def __init__(self, s): # pylint: disable=super-init-not-called
|
||||
pass
|
||||
|
||||
def get_status(self):
|
||||
return 1
|
||||
|
||||
def wait_for_exit(self):
|
||||
return
|
||||
|
||||
def __enter__(self):
|
||||
return self
|
||||
|
||||
def update(self, _):
|
||||
pass
|
||||
|
||||
def close(self):
|
||||
pass
|
||||
|
||||
def __exit__(self, exc_type, exc_value, traceback):
|
||||
pass
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
text = """Traceback (most recent call last):
|
||||
File "./controlsd.py", line 608, in <module>
|
||||
|
|
|
@ -10,9 +10,9 @@
|
|||
#define RAD2DEG(x) ((x) * 180.0 / M_PI)
|
||||
|
||||
|
||||
double a = 6378137;
|
||||
double b = 6356752.3142;
|
||||
double esq = 6.69437999014 * 0.001;
|
||||
double a = 6378137; // lgtm [cpp/short-global-name]
|
||||
double b = 6356752.3142; // lgtm [cpp/short-global-name]
|
||||
double esq = 6.69437999014 * 0.001; // lgtm [cpp/short-global-name]
|
||||
double e1sq = 6.73949674228 * 0.001;
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from cereal import log, car
|
||||
from functools import total_ordering
|
||||
|
||||
from cereal import log, car
|
||||
from common.realtime import DT_CTRL
|
||||
from selfdrive.config import Conversions as CV
|
||||
from selfdrive.locationd.calibration_helpers import Filter
|
||||
|
@ -93,6 +94,7 @@ class Events:
|
|||
ret.append(event)
|
||||
return ret
|
||||
|
||||
@total_ordering
|
||||
class Alert:
|
||||
def __init__(self,
|
||||
alert_text_1,
|
||||
|
@ -136,6 +138,9 @@ class Alert:
|
|||
def __gt__(self, alert2):
|
||||
return self.alert_priority > alert2.alert_priority
|
||||
|
||||
def __eq__(self, alert2):
|
||||
return self.alert_priority == alert2.alert_priority
|
||||
|
||||
class NoEntryAlert(Alert):
|
||||
def __init__(self, alert_text_2, audible_alert=AudibleAlert.chimeError,
|
||||
visual_alert=VisualAlert.none, duration_hud_alert=2.):
|
||||
|
|
|
@ -70,19 +70,15 @@ def unblock_stdout():
|
|||
if __name__ == "__main__":
|
||||
unblock_stdout()
|
||||
|
||||
if __name__ == "__main__" and ANDROID:
|
||||
from common.spinner import Spinner
|
||||
from common.text_window import TextWindow
|
||||
else:
|
||||
from common.spinner import FakeSpinner as Spinner
|
||||
from common.text_window import FakeTextWindow as TextWindow
|
||||
from common.spinner import Spinner
|
||||
from common.text_window import TextWindow
|
||||
|
||||
import importlib
|
||||
import traceback
|
||||
from multiprocessing import Process
|
||||
|
||||
# Run scons
|
||||
spinner = Spinner()
|
||||
spinner = Spinner(noop=(__name__ != "main" or not ANDROID))
|
||||
spinner.update("0")
|
||||
|
||||
if not prebuilt:
|
||||
|
@ -142,8 +138,9 @@ if not prebuilt:
|
|||
cloudlog.error("scons build failed\n" + error_s)
|
||||
|
||||
# Show TextWindow
|
||||
no_ui = __name__ != "__main__" or not ANDROID
|
||||
error_s = "\n \n".join(["\n".join(textwrap.wrap(e, 65)) for e in errors])
|
||||
with TextWindow("openpilot failed to build\n \n" + error_s) as t:
|
||||
with TextWindow("openpilot failed to build\n \n" + error_s, noop=no_ui) as t:
|
||||
t.wait_for_exit()
|
||||
|
||||
exit(1)
|
||||
|
|
|
@ -15,13 +15,13 @@ void frame_init(ModelFrame* frame, int width, int height,
|
|||
frame->transformed_height = height;
|
||||
|
||||
frame->transformed_y_cl = clCreateBuffer(frame->context, CL_MEM_READ_WRITE,
|
||||
frame->transformed_width*frame->transformed_height, NULL, &err);
|
||||
(size_t)frame->transformed_width*frame->transformed_height, NULL, &err);
|
||||
assert(err == 0);
|
||||
frame->transformed_u_cl = clCreateBuffer(frame->context, CL_MEM_READ_WRITE,
|
||||
(frame->transformed_width/2)*(frame->transformed_height/2), NULL, &err);
|
||||
(size_t)(frame->transformed_width/2)*(frame->transformed_height/2), NULL, &err);
|
||||
assert(err == 0);
|
||||
frame->transformed_v_cl = clCreateBuffer(frame->context, CL_MEM_READ_WRITE,
|
||||
(frame->transformed_width/2)*(frame->transformed_height/2), NULL, &err);
|
||||
(size_t)(frame->transformed_width/2)*(frame->transformed_height/2), NULL, &err);
|
||||
assert(err == 0);
|
||||
|
||||
frame->net_input_size = ((width*height*3)/2)*sizeof(float);
|
||||
|
|
|
@ -83,7 +83,7 @@ int touch_read(TouchState *s, int* out_x, int* out_y) {
|
|||
#include "sound.hpp"
|
||||
|
||||
bool Sound::init(int volume) { return true; }
|
||||
bool Sound::play(AudibleAlert alert) { return true; }
|
||||
bool Sound::play(AudibleAlert alert) { printf("play sound: %d\n", (int)alert); return true; }
|
||||
void Sound::stop() {}
|
||||
void Sound::setVolume(int volume) {}
|
||||
Sound::~Sound() {}
|
||||
|
|
Loading…
Reference in New Issue