Skip to content

Commit a4d6595

Browse files
Add docstrings, typehinting
1 parent 84fadf6 commit a4d6595

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

admin/cli.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,12 +276,14 @@ def connect(c, tunnel_id, command="/bin/bash", pty=True):
276276
device.sudo(command, pty=pty)
277277

278278

279-
def is_remote_directory(remote_device, remote_path):
279+
def is_remote_directory(remote_device: Connection, remote_path: str):
280+
"""Determines if a remote path is a directory using a bash command over a tunnel connection, returns true or false"""
280281
result = remote_device.run(f"if [ -d '{remote_path}' ]; then echo 'directory'; else echo 'file'; fi", hide=True).stdout.strip()
281282
return result == 'directory'
282283

283284

284-
def send_file(remote_device, local_file, remote_dir):
285+
def send_file(remote_device: Connection, local_file: str, remote_dir: str):
286+
"""Copies local file to remote directory via a tunnel connection"""
285287
filename = path.basename(local_file)
286288
remote_path = path.join(remote_dir, filename).replace("./", "") # path.join adds an unneccessary ./ when combining things with their own directory, making the prints down the line look odd
287289

@@ -293,7 +295,8 @@ def send_file(remote_device, local_file, remote_dir):
293295
print(f"File successfully uploaded to {remote_path}")
294296

295297

296-
def send_directory(remote_device, local_dir, remote_dir):
298+
def send_directory(remote_device: Connection, local_dir: str, remote_dir: str):
299+
"""Recursively copies everything in a local directory to a remote directory via a tunnel connection"""
297300
for root, _, files in walk(local_dir):
298301
relative_root = path.relpath(root, local_dir)
299302
remote_root = path.join(remote_dir, relative_root)
@@ -320,7 +323,8 @@ def sfile(c, tunnel_id, local, remote):
320323
send_file(device, local, remote)
321324

322325

323-
def get_file(remote_device, local_dir, remote_file):
326+
def get_file(remote_device: Connection, local_dir: str, remote_file: str):
327+
"""Copies a remote file to a local directory using a tunnel connection"""
324328
filename = path.basename(remote_file)
325329
local_path = path.join(local_dir, filename)
326330

@@ -330,6 +334,7 @@ def get_file(remote_device, local_dir, remote_file):
330334

331335

332336
def get_directory(remote_device, remote_dir, local_dir):
337+
"""Recursively copies everything in a remote directory to the local directory using a tunnel connection"""
333338
# List all files and directories under the remote directory
334339
result = remote_device.run(f"find {remote_dir} -type d -or -type f", hide=True).stdout.splitlines()
335340

0 commit comments

Comments
 (0)