Remove extra newline in lang.sh. Change parsing queue to writing queue

This commit is contained in:
kuben
2019-09-19 09:55:42 +02:00
parent 9f5078611c
commit 9097a98884
4 changed files with 15 additions and 20 deletions

View File

@@ -11,7 +11,7 @@ logger = None
health_logger = None
screen_send_cmd = lambda s : None # TODO temporary until move actions to modules
parsing_queue = None
write_queue = None # TODO Actually, why is this a queue? Just last element is important
class bar_mode(Enum):
power, normal, control = range(-1,2) # Don't cycle through power

View File

@@ -89,14 +89,12 @@ def clean_up():
modules.stop_all()
sys.exit(0)
def queue_parse_job(job):
common.parsing_queue.put(job)
def keep_fifo_open():
with open(config.fifo_file_status, 'w', buffering=1) as fifo_write:
while True:
fifo_write.write('HEARTBEAT\n')
time.sleep(30)
def put_fifo_in_queue():
with open(config.fifo_file_status, 'r', buffering=1) as fifo_read:
# Let parser read from fifo
@@ -108,7 +106,8 @@ def put_fifo_in_queue():
if len(data) == 0:
common.logger.debug("Writer closed")
break
queue_parse_job(data)
data = data.rstrip() # Remove trailing newlines
common.write_queue.put(lemonparser.parse_line(data))
except BrokenPipeError:
common.logger.debug('Broken pipe in parse status thread, exiting')
common.health_logger.info('Broken pipe in parse status thread, exiting')
@@ -118,24 +117,20 @@ def put_fifo_in_queue():
common.health_logger.info('Unknown exception in parse status thread, exiting')
clean_up()
def parse_status():
def write_parsed():
# Write parse entries in queue to lemonbar
global p_lemonbar
p_lemonbar = subprocess.Popen(config.lemonbar_args, stdin=subprocess.PIPE
, stdout=subprocess.PIPE, text=True)
while True:
data = common.parsing_queue.get() # Blocking read
data = common.write_queue.get() # Blocking read
if data is None:
common.logger.debug('Queue closed')
common.health_logger.info('Queue closed')
break
# Ugly temporary solution
if (isinstance(data, list)):
psd = data[0]
else:
psd = lemonparser.parse_line(data)
p_lemonbar.stdin.write(psd + '\n')
p_lemonbar.stdin.write(data + '\n')
p_lemonbar.stdin.flush()
#common.logger.debug('Read: "{0}"'.format(data))
#common.logger.debug('Parsed "{0}"'.format(psd))
@@ -224,12 +219,12 @@ if __name__ == "__main__":
signal.signal(signal.SIGTERM, handle_exit)
signal.signal(signal.SIGINT, handle_exit)
common.parsing_queue = queue.Queue()
common.write_queue = queue.Queue()
# Start writing and reading threads
# Create readers before writers
i3_thread(target = exec_commands, desc='Exec commands thread')
i3_thread(target = parse_status, desc='Parse status thread')
i3_thread(target = write_parsed, desc='Write parsed status thread')
i3_thread(target = keep_fifo_open, desc='')
i3_thread(target = put_fifo_in_queue, desc='')
modules.start_all()

View File

@@ -30,7 +30,7 @@ class LemonModule(threading.Thread):
break
parsed = self.parse(line)
common.parsing_queue.put([parsed]) # TODO Wrapped in list, temporary solution
common.write_queue.put(parsed)
def stop(self):
self._stop_module()
@@ -48,7 +48,7 @@ def format_load(data, module, alert):
# Changes colors scheme to inactive when interfaces are down, or to alert when
# alert level is reached
# Returns tuple (down, up)
if data[0] == 'down': # wlan
if data[0] == 'down':
module.alt_scheme = parser.COLOR_SCHEME.INA
return ('x', 'x')
else: