mirror of
https://codeberg.org/gaschz/passff-host.git
synced 2025-06-06 18:08:46 +02:00
Merge pull request #32 from eklitzke/flake8
minor changes to passff.py to conform to flake8
This commit is contained in:
commit
007366dd14
@ -1,17 +1,20 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Host application of the browser extension PassFF
|
Host application of the browser extension PassFF
|
||||||
that wraps around the zx2c4 pass script.
|
that wraps around the zx2c4 pass script.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os, sys, json, struct, subprocess
|
import json
|
||||||
|
import os
|
||||||
|
import struct
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
VERSION = "_VERSIONHOLDER_"
|
VERSION = "_VERSIONHOLDER_"
|
||||||
|
|
||||||
################################################################################
|
###############################################################################
|
||||||
######################## Begin preferences section #############################
|
######################## Begin preferences section ############################
|
||||||
################################################################################
|
###############################################################################
|
||||||
COMMAND = "pass"
|
COMMAND = "pass"
|
||||||
COMMAND_ARGS = []
|
COMMAND_ARGS = []
|
||||||
COMMAND_ENV = {
|
COMMAND_ENV = {
|
||||||
@ -19,9 +22,11 @@ COMMAND_ENV = {
|
|||||||
"PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
|
"PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin",
|
||||||
}
|
}
|
||||||
CHARSET = "UTF-8"
|
CHARSET = "UTF-8"
|
||||||
################################################################################
|
|
||||||
######################### End preferences section ##############################
|
###############################################################################
|
||||||
################################################################################
|
######################### End preferences section #############################
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
|
||||||
def getMessage():
|
def getMessage():
|
||||||
""" Read a message from stdin and decode it. """
|
""" Read a message from stdin and decode it. """
|
||||||
@ -32,18 +37,21 @@ def getMessage():
|
|||||||
message = sys.stdin.buffer.read(messageLength).decode("utf-8")
|
message = sys.stdin.buffer.read(messageLength).decode("utf-8")
|
||||||
return json.loads(message)
|
return json.loads(message)
|
||||||
|
|
||||||
|
|
||||||
def encodeMessage(messageContent):
|
def encodeMessage(messageContent):
|
||||||
""" Encode a message for transmission, given its content. """
|
""" Encode a message for transmission, given its content. """
|
||||||
encodedContent = json.dumps(messageContent)
|
encodedContent = json.dumps(messageContent)
|
||||||
encodedLength = struct.pack('@I', len(encodedContent))
|
encodedLength = struct.pack('@I', len(encodedContent))
|
||||||
return {'length': encodedLength, 'content': encodedContent}
|
return {'length': encodedLength, 'content': encodedContent}
|
||||||
|
|
||||||
|
|
||||||
def sendMessage(encodedMessage):
|
def sendMessage(encodedMessage):
|
||||||
""" Send an encoded message to stdout. """
|
""" Send an encoded message to stdout. """
|
||||||
sys.stdout.buffer.write(encodedMessage['length'])
|
sys.stdout.buffer.write(encodedMessage['length'])
|
||||||
sys.stdout.write(encodedMessage['content'])
|
sys.stdout.write(encodedMessage['content'])
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Read message from standard input
|
# Read message from standard input
|
||||||
receivedMessage = getMessage()
|
receivedMessage = getMessage()
|
||||||
@ -94,7 +102,8 @@ if __name__ == "__main__":
|
|||||||
proc = subprocess.run(cmd, **proc_params)
|
proc = subprocess.run(cmd, **proc_params)
|
||||||
|
|
||||||
# Send response
|
# Send response
|
||||||
sendMessage(encodeMessage({
|
sendMessage(
|
||||||
|
encodeMessage({
|
||||||
"exitCode": proc.returncode,
|
"exitCode": proc.returncode,
|
||||||
"stdout": proc.stdout.decode(CHARSET),
|
"stdout": proc.stdout.decode(CHARSET),
|
||||||
"stderr": proc.stderr.decode(CHARSET),
|
"stderr": proc.stderr.decode(CHARSET),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user