diff options
author | Ben Sima <ben@bsima.me> | 2020-04-15 15:24:32 -0700 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2020-04-15 17:19:43 -0700 |
commit | e9a53b69ad68e531a789eff3128f7304fd411808 (patch) | |
tree | 7c0382cb3c49458e8c989eaaa042bc37b37a9699 /Que | |
parent | cb77d0eb623c7a398ca86a632d0ea37ac385cc3d (diff) |
Lint fixes, also delete Biz.Language
Diffstat (limited to 'Que')
-rw-r--r-- | Que/Server.hs | 12 | ||||
-rw-r--r-- | Que/Website.hs | 4 | ||||
-rwxr-xr-x | Que/client.py | 49 |
3 files changed, 34 insertions, 31 deletions
diff --git a/Que/Server.hs b/Que/Server.hs index b0f3fbd..9e8d893 100644 --- a/Que/Server.hs +++ b/Que/Server.hs @@ -84,7 +84,7 @@ newtype App a (STM.TVar AppState) ) -data AppState +newtype AppState = AppState { ques :: HashMap Namespace Quebase } @@ -92,7 +92,7 @@ data AppState initialAppState :: AppState initialAppState = AppState {ques = mempty} -data Config +newtype Config = Config { -- | QUE_PORT quePort :: Warp.Port @@ -139,9 +139,9 @@ routes = do q <- app <| que ns qp poll <- Scotty.param "poll" !: (pure . const False) guardNs ns ["pub", "_"] - case poll of - True -> Scotty.stream $ streamQue q - _ -> do + if poll + then Scotty.stream $ streamQue q + else do r <- liftIO <| Go.read q Scotty.html <| fromStrict <| Encoding.decodeUtf8 r -- POST que @@ -225,7 +225,7 @@ app = lift -- | Get something from the app state gets :: (AppState -> b) -> App b -gets f = ask >>= liftIO . STM.readTVarIO >>= return . f +gets f = ask >>= liftIO . STM.readTVarIO >>= return </ f -- | Apply a function to the app state modify :: (AppState -> AppState) -> App () diff --git a/Que/Website.hs b/Que/Website.hs index cfb860c..7eb3ae6 100644 --- a/Que/Website.hs +++ b/Que/Website.hs @@ -53,7 +53,7 @@ getKey :: Namespace -> IO (Maybe Key) getKey ns = do home <- Directory.getHomeDirectory let file = home </> ".config" </> "que.conf" - exists <- (Directory.doesFileExist file) + exists <- Directory.doesFileExist file unless exists <| panic <| "not found: " <> Text.pack file conf <- Text.readFile file print (home </> ".config" </> "que.conf") @@ -84,7 +84,7 @@ auth "pub" = pure Nothing auth ns = Config.sectionMb ns <| Config.field "key" run :: Maybe Key -> Text -> Sources -> IO () -run key ns Sources {..} = Async.runConcurrently actions >> return () +run key ns Sources {..} = Async.runConcurrently actions |> void where actions = traverse diff --git a/Que/client.py b/Que/client.py index 3d9291d..6958576 100755 --- a/Que/client.py +++ b/Que/client.py @@ -17,16 +17,16 @@ MAX_TIMEOUT = 99999999 # basically never timeout def auth(args): - ns = args.target.split("/")[0] - if ns == "pub": + "Returns the auth key for the given ns from ~/.config/que.conf" + namespace = args.target.split("/")[0] + if namespace == "pub": return None - else: - conf_file = os.path.expanduser("~/.config/que.conf") - if not os.path.exists(conf_file): - sys.exit("you need a ~/.config/que.conf") + conf_file = os.path.expanduser("~/.config/que.conf") + if not os.path.exists(conf_file): + sys.exit("you need a ~/.config/que.conf") cfg = configparser.ConfigParser() cfg.read(conf_file) - return cfg[ns]["key"] + return cfg[namespace]["key"] def send(args): @@ -53,7 +53,9 @@ def recv(args): print(msg) if args.then: subprocess.run( - args.then.replace("\msg", msg).replace("\que", args.target), shell=True + args.then.replace(r"\msg", msg).replace(r"que", args.target), + shell=True, + check=False, ) params = urllib.parse.urlencode({"poll": args.poll}) @@ -70,8 +72,8 @@ def recv(args): _recv(_req) -def autodecode(b): - """Attempt to decode bytes `b` into common codecs, preferably utf-8. If +def autodecode(bytestring): + """Attempt to decode bytes `bs` into common codecs, preferably utf-8. If no decoding is available, just return the raw bytes. For all available codecs, see: @@ -81,13 +83,14 @@ def autodecode(b): codecs = ["utf-8", "ascii"] for codec in codecs: try: - return b.decode(codec) + return bytestring.decode(codec) except UnicodeDecodeError: pass - return b + return bytestring def get_args(): + "Command line parser" cli = argparse.ArgumentParser(description=__doc__) cli.add_argument( "--host", default="http://que.run", help="where que-server is running" @@ -101,7 +104,7 @@ def get_args(): [ "when polling, run this shell command after each response,", "presumably for side effects," - "replacing '\que' with the target and '\msg' with the body of the response", + r"replacing '\que' with the target and '\msg' with the body of the response", ] ), ) @@ -129,21 +132,21 @@ def get_args(): if __name__ == "__main__": - args = get_args() + ARGV = get_args() try: - if args.infile: - send(args) + if ARGV.infile: + send(ARGV) else: - recv(args) + recv(ARGV) except KeyboardInterrupt: sys.exit(0) - except urllib.error.HTTPError as e: - print(e) + except urllib.error.HTTPError as err: + print(err) sys.exit(1) - except http.client.RemoteDisconnected as e: + except http.client.RemoteDisconnected as err: print("disconnected... retrying in 5 seconds") time.sleep(5) - if args.infile: - send(args) + if ARGV.infile: + send(ARGV) else: - recv(args) + recv(ARGV) |