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 health_logger = None
screen_send_cmd = lambda s : None # TODO temporary until move actions to modules 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): class bar_mode(Enum):
power, normal, control = range(-1,2) # Don't cycle through power power, normal, control = range(-1,2) # Don't cycle through power

View File

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

View File

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

View File

@@ -16,16 +16,16 @@ if [ "$1" == "next" ]; then
fi fi
setxkbmap $next setxkbmap $next
if [ -e $panel_fifo ]; then if [ -e $panel_fifo ]; then
echo -e "LANG$next\n" > "${panel_fifo}" echo -e "LANG$next" > "${panel_fifo}"
fi fi
if [ -e $panel_commands ]; then if [ -e $panel_commands ]; then
echo -e "setlang $next\n" > "${panel_commands}" echo -e "setlang $next" > "${panel_commands}"
fi fi
elif [ "$1" == "qset" ]; then elif [ "$1" == "qset" ]; then
next=$2 next=$2
setxkbmap $next setxkbmap $next
if [ -e $panel_fifo ]; then if [ -e $panel_fifo ]; then
echo -e "LANG$next\n" > "${panel_fifo}" echo -e "LANG$next" > "${panel_fifo}"
fi fi
elif [ "$1" == "show" ]; then elif [ "$1" == "show" ]; then
show show