From 9097a9888446d0f8f5e5505ca44ace34964e8493 Mon Sep 17 00:00:00 2001 From: kuben Date: Thu, 19 Sep 2019 09:55:42 +0200 Subject: [PATCH] Remove extra newline in lang.sh. Change parsing queue to writing queue --- .i3/lemonbar/i3_lemonbar_common.py | 2 +- .i3/lemonbar/i3_lemonbar_launcher.py | 23 +++++++++-------------- .i3/lemonbar/i3_lemonbar_modules.py | 4 ++-- .i3/scripts/lang.sh | 6 +++--- 4 files changed, 15 insertions(+), 20 deletions(-) diff --git a/.i3/lemonbar/i3_lemonbar_common.py b/.i3/lemonbar/i3_lemonbar_common.py index a2aa0e1..ebd024a 100755 --- a/.i3/lemonbar/i3_lemonbar_common.py +++ b/.i3/lemonbar/i3_lemonbar_common.py @@ -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 diff --git a/.i3/lemonbar/i3_lemonbar_launcher.py b/.i3/lemonbar/i3_lemonbar_launcher.py index f422e38..e8b4400 100755 --- a/.i3/lemonbar/i3_lemonbar_launcher.py +++ b/.i3/lemonbar/i3_lemonbar_launcher.py @@ -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() diff --git a/.i3/lemonbar/i3_lemonbar_modules.py b/.i3/lemonbar/i3_lemonbar_modules.py index b9fd962..cd3e96a 100644 --- a/.i3/lemonbar/i3_lemonbar_modules.py +++ b/.i3/lemonbar/i3_lemonbar_modules.py @@ -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: diff --git a/.i3/scripts/lang.sh b/.i3/scripts/lang.sh index b3b6740..5e87a3e 100755 --- a/.i3/scripts/lang.sh +++ b/.i3/scripts/lang.sh @@ -16,16 +16,16 @@ if [ "$1" == "next" ]; then fi setxkbmap $next if [ -e $panel_fifo ]; then - echo -e "LANG$next\n" > "${panel_fifo}" + echo -e "LANG$next" > "${panel_fifo}" fi if [ -e $panel_commands ]; then - echo -e "setlang $next\n" > "${panel_commands}" + echo -e "setlang $next" > "${panel_commands}" fi elif [ "$1" == "qset" ]; then next=$2 setxkbmap $next if [ -e $panel_fifo ]; then - echo -e "LANG$next\n" > "${panel_fifo}" + echo -e "LANG$next" > "${panel_fifo}" fi elif [ "$1" == "show" ]; then show