Skip to content

Commit

Permalink
Add "Decrypt received files" option to GUI
Browse files Browse the repository at this point in the history
For #21
  • Loading branch information
peterstory committed Jul 23, 2024
1 parent 0bb8d6d commit ce72bec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 5 deletions.
25 changes: 20 additions & 5 deletions src/pydiode/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
SEND_PIPELINE,
SEND_TEST_PIPELINE,
)

# These modules' main methods are run in subprocesses
import pydiode.decrypt
import pydiode.pydiode
import pydiode.tar

Expand Down Expand Up @@ -154,6 +157,7 @@ def gui_main():
rx_progress,
rx_cancelled,
receive_repeatedly,
decrypt_received,
),
)
rx_btn.grid(column=0, row=2, pady=5, columnspan=2)
Expand Down Expand Up @@ -197,6 +201,15 @@ def gui_main():
offvalue=False,
).grid(column=0, row=3, columnspan=2, sticky="W")
receive_repeatedly.set(config["pydiode"].get("receive_repeatedly", True))
decrypt_received = BooleanVar()
ttk.Checkbutton(
settings_inner,
text="Decrypt received files",
variable=decrypt_received,
onvalue=True,
offvalue=False,
).grid(column=0, row=4, columnspan=2, sticky="W")
decrypt_received.set(config["pydiode"].get("decrypt_received", True))
rx_test_cancelled = BooleanVar(value=False)
rx_test_btn = ttk.Button(
settings_inner,
Expand All @@ -209,7 +222,7 @@ def gui_main():
rx_test_cancelled,
),
)
rx_test_btn.grid(column=0, row=4, columnspan=2)
rx_test_btn.grid(column=0, row=5, columnspan=2)
tx_test_cancelled = BooleanVar(value=False)
ttk.Button(
settings_inner,
Expand All @@ -221,7 +234,7 @@ def gui_main():
port.get(),
tx_test_cancelled,
),
).grid(column=0, row=5, columnspan=2)
).grid(column=0, row=6, columnspan=2)

# Override the default behavior of the Quit menu, so it doesn't cause the
# application to exit immediately
Expand All @@ -244,6 +257,7 @@ def gui_main():
"receive_ip": receive_ip.get(),
"port": port.get(),
"receive_repeatedly": receive_repeatedly.get(),
"decrypt_received": decrypt_received.get(),
"saved_window_should_show": SavedWindow.should_show.get(),
}
with open(CONFIG, "w") as configfile:
Expand All @@ -263,11 +277,12 @@ def main():
else:
# Remove the executable from argv for compatibility with argparse
sys.argv.pop(0)
if sys.argv[0] == "pydiode":
# With pydiode as the first argument, launch pydiode
# Based on the first argument, run the appropriate main method
if sys.argv[0] == "decrypt":
pydiode.decrypt.main()
elif sys.argv[0] == "pydiode":
pydiode.pydiode.main()
elif sys.argv[0] == "tar":
# With tar as the first argument, launch tar
pydiode.tar.main()
else:
print(f"Invalid arguments: {sys.argv}", file=sys.stderr)
Expand Down
15 changes: 15 additions & 0 deletions src/pydiode/gui/receive.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def receive_or_cancel(
progress_bar,
cancelled,
receive_repeatedly,
decrypt_received,
):
"""
Receive files from the data diode. If we are already receiving, calling
Expand All @@ -47,6 +48,8 @@ def receive_or_cancel(
:param cancelled: Boolean variable indicating cancellation request
:param receive_repeatedly: Boolean variable indicating whether to receive
again after the subprocesses exit.
:param decrypt_received: Boolean variable indicating whether to decrypt
received files using gpg
"""

if button["text"] == "Cancel Receiving":
Expand All @@ -61,6 +64,7 @@ def receive_or_cancel(
progress_bar,
cancelled,
receive_repeatedly,
decrypt_received,
)


Expand Down Expand Up @@ -164,6 +168,7 @@ def receive_files(
progress_bar,
cancelled,
receive_repeatedly,
decrypt_received,
):
def repeat():
SavedWindow.show_window(root, target_dir)
Expand All @@ -178,6 +183,7 @@ def repeat():
progress_bar,
cancelled,
receive_repeatedly,
decrypt_received,
)

def animate():
Expand Down Expand Up @@ -210,6 +216,15 @@ def animate():
RECEIVE_PIPELINE.append("pydiode", pydiode)
RECEIVE_PIPELINE.append("tar", tar)

if decrypt_received.get():
decrypt = subprocess.Popen(
sys.argv + ["decrypt"],
stdin=tar.stdout,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
RECEIVE_PIPELINE.append("decrypt", decrypt)

check_subprocesses(root, cancelled, RECEIVE_PIPELINE, on_exit=repeat)
animate()

Expand Down

0 comments on commit ce72bec

Please sign in to comment.