Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modernize #59

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/example_plugins/basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ def stop(self):
super().stop()

def handle_command(self, arguments, lxm):
response_content = "Hello "+RNS.prettyhexrep(lxm.source_hash)+". "
response_content = f"Hello {RNS.prettyhexrep(lxm.source_hash)}. "
response_content += "This is a response from the basic command example. It doesn't do much, but here is a list of the arguments you included:\n"

for argument in arguments:
response_content += "\n"+str(argument)
response_content += f"\n{argument)}"

# Let the Sideband core send a reply.
self.get_sideband().send_message(
Expand Down
2 changes: 1 addition & 1 deletion docs/example_plugins/comic.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def handle_command(self, arguments, lxm):
except Exception as e:
# Send an error message
self.get_sideband().send_message(
"An error occurred while trying to fetch the specified comic:\n\n"+str(e),
f"An error occurred while trying to fetch the specified comic:\n\n{e)}",
lxm.source_hash,
False, # Don't use propagation by default, try direct first
skip_fields = True, # Don't include any additional fields automatically
Expand Down
2 changes: 1 addition & 1 deletion docs/example_plugins/gpsd_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ def update_telemetry(self, telemeter):
telemeter.sensors["location"].accuracy = self.accuracy
telemeter.sensors["location"].stale_time = 5
telemeter.sensors["location"].set_update_time(self.last_update)

else:
RNS.log("No location from GPSd yet", RNS.LOG_DEBUG)

Expand Down
4 changes: 2 additions & 2 deletions docs/example_plugins/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ class BasicServicePlugin(SidebandServicePlugin):
def service_jobs(self):
while self.should_run:
time.sleep(5)
RNS.log("Service ping from "+str(self))
RNS.log(f"Service ping from {self)}")

RNS.log("Jobs stopped running for "+str(self))
RNS.log(f"Jobs stopped running for {self)}")

def start(self):
# Do any initialisation work here
Expand Down
34 changes: 17 additions & 17 deletions docs/example_plugins/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def get_image_field(self, preset="default"):
try:
if self.is_stale():
self.update()

if self.source_data != None:
max_dimension = quality_presets[preset]["max"]
quality = quality_presets[preset]["quality"]
Expand Down Expand Up @@ -121,17 +121,17 @@ def read_frames(self):
if not ret:
self.camera_ready = False
break

if not self.frame_queue.empty():
try:
self.frame_queue.get_nowait()
except queue.Empty:
pass

self.frame_queue.put(frame)

except Exception as e:
RNS.log("An error occurred while reading frames from the camera: "+str(e), RNS.LOG_ERROR)
RNS.log(f"An error occurred while reading frames from the camera: {e)}", RNS.LOG_ERROR)

self.release_camera()

Expand All @@ -140,9 +140,9 @@ def update(self):
self.start_reading()
while not self.camera_ready:
time.sleep(0.2)

retval, frame = self.camera.read()

if not retval:
self.source_data = None
else:
Expand All @@ -154,8 +154,8 @@ def release_camera(self):
try:
self.camera.release()
except:
pass
pass

self.camera = None
self.camera_ready = False

Expand Down Expand Up @@ -185,20 +185,20 @@ def read_frames(self):
if not ret:
self.stream_ready = False
else:
self.stream_ready = True
self.stream_ready = True
if not self.frame_queue.empty():
if self.frame_queue.qsize() > 1:
try:
self.frame_queue.get_nowait()
except queue.Empty:
pass

self.frame_queue.put(frame)

RNS.log(str(self)+" idled", RNS.LOG_DEBUG)
RNS.log(f"{self)} idled", RNS.LOG_DEBUG)

except Exception as e:
RNS.log("An error occurred while reading frames from the stream: "+str(e), RNS.LOG_ERROR)
RNS.log(f"An error occurred while reading frames from the stream: {e)}", RNS.LOG_ERROR)

self.release_stream()

Expand All @@ -220,8 +220,8 @@ def release_stream(self):
try:
self.stream.release()
except:
pass
pass

self.stream = None
self.stream_ready = False

Expand All @@ -236,7 +236,7 @@ def update(self):
self.source_data = image_file.read()

except Exception as e:
RNS.log("Could not read image at \"{self.path}\": "+str(e), RNS.LOG_ERROR)
RNS.log(f"Could not read image at \"{self.path}\": {e)}", RNS.LOG_ERROR)
self.source_data = None

class ViewCommandPlugin(SidebandCommandPlugin):
Expand Down Expand Up @@ -292,7 +292,7 @@ def handle_command(self, arguments, lxm):
else:
response = "Available Sources:\n"
for source in self.sources:
response += "\n - "+str(source)
response += f"\n - {source)}"

self.message_response(response, requestor)
return
Expand All @@ -306,7 +306,7 @@ def handle_command(self, arguments, lxm):

if not source in self.sources:
self.message_response("The specified view source does not exist on this system", requestor)

else:
image_field = self.sources[source].get_image_field(quality_preset)
image_timestamp = self.timestamp_str(self.sources[source].last_update)
Expand Down
4 changes: 2 additions & 2 deletions docs/utilities/rns_audio_call_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def simulate(link_speed=9600, audio_slot_ms=70, codec_rate=1200, method="msgpack
PAYLOAD_LATENCY = round(ENCRYPTED_PAYLOAD_LEN*PER_BYTE_LATENCY_MS, 1)
RAW_DATA_LATENCY = round(AUDIO_LEN*PER_BYTE_LATENCY_MS, 1)
PACKING_LATENCY = round(PACKING_OVERHEAD*PER_BYTE_LATENCY_MS, 1)

DATA_LATENCY = round(ENCRYPTED_PAYLOAD_LEN*PER_BYTE_LATENCY_MS, 1)
ENCRYPTION_LATENCY = round((ENCRYPTED_PAYLOAD_LEN-PL_LEN)*PER_BYTE_LATENCY_MS, 1)
if ENCRYPTED_PAYLOAD_LEN-PL_LEN == 1:
Expand All @@ -100,7 +100,7 @@ def simulate(link_speed=9600, audio_slot_ms=70, codec_rate=1200, method="msgpack
print(f" On-air length : {PACKET_LEN} bytes")
print(f" Packet airtime : {PACKET_AIRTIME}ms")

print( "\n===== Results for "+RNS.prettyspeed(LINK_SPEED)+" Link Speed ===\n")
print( f"\n===== Results for {RNS.prettyspeed(LINK_SPEED)} Link Speed ===\n")
print(f" Final latency : {TOTAL_LATENCY}ms")
print(f" Recording latency : contributes {TARGET_MS}ms")
print(f" Packet transport : contributes {PACKET_LATENCY}ms")
Expand Down
6 changes: 3 additions & 3 deletions recipes/codec2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ class Codec2Recipe(Recipe):
def include_flags(self, arch):
'''Returns a string with the include folders'''
codec2_includes = join(self.get_build_dir(arch.arch), 'build_android')
return (' -I' + codec2_includes)
return (f" -I{codec2_includes}")

def link_dirs_flags(self, arch):
'''Returns a string with the appropriate `-L<lib directory>` to link
with the libs. This string is usually added to the environment
variable `LDFLAGS`'''
return ' -L' + self.get_build_dir(arch.arch)
return f" -L{self.get_build_dir(arch.arch)}"

# def link_libs_flags(self):
# '''Returns a string with the appropriate `-l<lib>` flags to link with
# the libs. This string is usually added to the environment
# variable `LIBS`'''
# return ' -lcodec2{version} -lssl{version}'.format(version=self.version)

def build_arch(self, arch):
def build_arch(self, arch):
with current_directory(self.get_build_dir(arch.arch)):
env = self.get_recipe_env(arch)
flags = [
Expand Down
Loading