Add more docstrings

This commit is contained in:
Daniel Markstedt 2021-09-29 09:48:34 -07:00
parent 44298bf031
commit 0e4c2b7fd7
2 changed files with 41 additions and 7 deletions

View File

@ -37,6 +37,11 @@ def list_config_files():
def create_new_image(file_name, file_type, size): def create_new_image(file_name, file_type, size):
"""
Takes str file_name, str file_type, and int size
Sends a CREATE_IMAGE command to the server
Returns dict with boolean status and str msg
"""
command = proto.PbCommand() command = proto.PbCommand()
command.operation = proto.PbOperation.CREATE_IMAGE command.operation = proto.PbOperation.CREATE_IMAGE
@ -51,6 +56,11 @@ def create_new_image(file_name, file_type, size):
def delete_file(file_name): def delete_file(file_name):
"""
Takes str file_name
Sends a DELETE_IMAGE command to the server
Returns dict with boolean status and str msg
"""
command = proto.PbCommand() command = proto.PbCommand()
command.operation = proto.PbOperation.DELETE_IMAGE command.operation = proto.PbOperation.DELETE_IMAGE
@ -63,6 +73,10 @@ def delete_file(file_name):
def unzip_file(file_name): def unzip_file(file_name):
"""
Takes str file_name
Returns dict with boolean status and str msg
"""
from subprocess import run from subprocess import run
unzip_proc = run( unzip_proc = run(
@ -76,6 +90,10 @@ def unzip_file(file_name):
def download_file_to_iso(scsi_id, url): def download_file_to_iso(scsi_id, url):
"""
Takes int scsi_id and str url
Returns dict with boolean status and str msg
"""
import urllib.request import urllib.request
import urllib.error as error import urllib.error as error
import time import time
@ -102,10 +120,16 @@ def download_file_to_iso(scsi_id, url):
) )
if iso_proc.returncode != 0: if iso_proc.returncode != 0:
return {"status": False, "msg": iso_proc} return {"status": False, "msg": iso_proc}
return attach_image(scsi_id, type="SCCD", image=iso_filename)
process = attach_image(scsi_id, type="SCCD", image=iso_filename)
return {"status": process["status"], "msg": process["msg"]}
def download_image(url): def download_image(url):
"""
Takes str url
Returns dict with boolean status and str msg
"""
import urllib.request import urllib.request
import urllib.error as error import urllib.error as error
@ -123,6 +147,10 @@ def download_image(url):
def write_config(file_name): def write_config(file_name):
"""
Takes str file_name
Returns dict with boolean status and str msg
"""
from json import dump from json import dump
file_name = base_dir + file_name file_name = base_dir + file_name
try: try:
@ -154,6 +182,10 @@ def write_config(file_name):
def read_config(file_name): def read_config(file_name):
"""
Takes str file_name
Returns dict with boolean status and str msg
"""
from json import load from json import load
file_name = base_dir + file_name file_name = base_dir + file_name
try: try:
@ -185,6 +217,7 @@ def write_drive_properties(file_name, conf):
""" """
Writes a drive property configuration file to the images dir. Writes a drive property configuration file to the images dir.
Takes file name base (str) and conf (list of dicts) as arguments Takes file name base (str) and conf (list of dicts) as arguments
Returns dict with boolean status and str msg
""" """
from json import dump from json import dump
try: try:
@ -205,6 +238,7 @@ def read_drive_properties(path_name):
Reads drive properties to any dir. Reads drive properties to any dir.
Either ones deployed to the images dir, or the canonical database. Either ones deployed to the images dir, or the canonical database.
Takes file path and bas (str) as argument Takes file path and bas (str) as argument
Returns dict with boolean status and str msg
""" """
from json import load from json import load
try: try:

View File

@ -120,7 +120,7 @@ def attach_image(scsi_id, **kwargs):
this sends a INJECT command to the server. this sends a INJECT command to the server.
If there is no currently attached device, this sends the ATTACH command to the server. If there is no currently attached device, this sends the ATTACH command to the server.
Returns boolean status and return message str msg Returns boolean status and str msg
""" """
command = proto.PbCommand() command = proto.PbCommand()
@ -180,7 +180,7 @@ def attach_image(scsi_id, **kwargs):
def detach_by_id(scsi_id): def detach_by_id(scsi_id):
""" """
Takes int scsi_id and sends a DETACH command to the server. Takes int scsi_id and sends a DETACH command to the server.
Returns boolean status and return message str msg. Returns boolean status and str msg.
""" """
devices = proto.PbDeviceDefinition() devices = proto.PbDeviceDefinition()
devices.id = int(scsi_id) devices.id = int(scsi_id)
@ -198,7 +198,7 @@ def detach_by_id(scsi_id):
def detach_all(): def detach_all():
""" """
Sends a DETACH_ALL command to the server. Sends a DETACH_ALL command to the server.
Returns boolean status and return message str msg. Returns boolean status and str msg.
""" """
command = proto.PbCommand() command = proto.PbCommand()
command.operation = proto.PbOperation.DETACH_ALL command.operation = proto.PbOperation.DETACH_ALL
@ -212,7 +212,7 @@ def detach_all():
def eject_by_id(scsi_id): def eject_by_id(scsi_id):
""" """
Takes int scsi_id and sends an EJECT command to the server. Takes int scsi_id and sends an EJECT command to the server.
Returns boolean status and return message str msg. Returns boolean status and str msg.
""" """
devices = proto.PbDeviceDefinition() devices = proto.PbDeviceDefinition()
devices.id = int(scsi_id) devices.id = int(scsi_id)
@ -233,7 +233,7 @@ def list_devices(scsi_id=None):
If no scsi_id is provided, returns a list of dicts of all attached devices. If no scsi_id is provided, returns a list of dicts of all attached devices.
If scsi_id is is provided, returns a list of one dict for the given device. If scsi_id is is provided, returns a list of one dict for the given device.
If no attached device is found, returns an empty list. If no attached device is found, returns an empty list.
Returns bolean status, list of dicts device_list Returns boolean status, list of dicts device_list
""" """
from os import path from os import path
command = proto.PbCommand() command = proto.PbCommand()
@ -319,7 +319,7 @@ def set_log_level(log_level):
""" """
Sends a LOG_LEVEL command to the server. Sends a LOG_LEVEL command to the server.
Takes str log_level as an argument. Takes str log_level as an argument.
Returns bolean status and str msg. Returns boolean status and str msg.
""" """
command = proto.PbCommand() command = proto.PbCommand()
command.operation = proto.PbOperation.LOG_LEVEL command.operation = proto.PbOperation.LOG_LEVEL