|
|
@@ -4,6 +4,8 @@ import queue
|
|
|
import shlex
|
|
|
import subprocess
|
|
|
import sys
|
|
|
+import readline
|
|
|
+import os
|
|
|
|
|
|
from threading import Thread
|
|
|
from ircclient import IRCClient, MODE_SEARCH, MODE_BOOK
|
|
|
@@ -11,6 +13,7 @@ from ircclient import IRCClient, MODE_SEARCH, MODE_BOOK
|
|
|
logging.basicConfig(level=logging.DEBUG)
|
|
|
log = logging.getLogger(__name__)
|
|
|
log.setLevel(logging.DEBUG)
|
|
|
+histfile = os.path.join(os.path.expanduser("~"), ".book_history")
|
|
|
|
|
|
def usage():
|
|
|
print("USAGE:")
|
|
|
@@ -81,8 +84,8 @@ def main():
|
|
|
results_t = Thread(target=handle_results, args=(rq,))
|
|
|
results_t.daemon = True
|
|
|
results_t.start()
|
|
|
- for line in sys.stdin:
|
|
|
- line = line.strip().lower()
|
|
|
+ while True:
|
|
|
+ line = input('> ').strip().lower()
|
|
|
try:
|
|
|
split = shlex.split(line)
|
|
|
except Exception as e:
|
|
|
@@ -95,7 +98,7 @@ def main():
|
|
|
usage()
|
|
|
continue
|
|
|
|
|
|
- if not any([ worker.free for worker in workers]):
|
|
|
+ if not any([ not worker.busy for worker in workers]):
|
|
|
print("Spawning a new worker as all are busy...")
|
|
|
worker = IRCClient(command_queue=q, results_queue=rq)
|
|
|
worker.start()
|
|
|
@@ -105,13 +108,24 @@ def main():
|
|
|
query = " ".join(split[1:])
|
|
|
data = {'query': query, 'mode': mode}
|
|
|
q.put(data)
|
|
|
+ print("Command acknowledged")
|
|
|
|
|
|
results_t.join()
|
|
|
for worker in workers:
|
|
|
worker.join()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
+ try:
|
|
|
+ readline.read_history_file(histfile)
|
|
|
+ # default history len is -1 (infinite), which may grow unruly
|
|
|
+ readline.set_history_length(10000)
|
|
|
+ except FileNotFoundError:
|
|
|
+ pass
|
|
|
+
|
|
|
try:
|
|
|
main()
|
|
|
except KeyboardInterrupt:
|
|
|
print("\nBye")
|
|
|
+ except EOFError:
|
|
|
+ print("\nBye")
|
|
|
+ readline.write_history_file(histfile)
|