Skip to content
Snippets Groups Projects
Commit 41d27afa authored by Peter Senna Tschudin's avatar Peter Senna Tschudin
Browse files

Add interactive mode


Calling psdk without arguments will now trigger the interactive mode.

There are a few pre-conditions:
 - empty disk available: asks if the user wants to initialize the disk
   and configure the SDK to use it.
 - persistent disk available, but not in use: asks if the user wants to
   configure the SDK to use the persistent disk.
 - persistent disk in use: no actions allowed

This patch also includes the file data/psdk.desktop which creates a
desktop icon when copied to ~/Desktop.

Signed-off-by: default avatarPeter Senna Tschudin <peter.senna@collabora.com>
parent 28661f4d
No related branches found
No related tags found
1 merge request!1WIP: adds interactive mode and desktop icon
[Desktop Entry]
Version=1.0
Name=Persistent Disk Setup
Exec=/usr/bin/psdk
Icon=drive-harddisk
Terminal=true
Type=Application
Categories=System
StartupNotify=false
......@@ -27,6 +27,8 @@ import errno
BKP_EXTENSION = ".PSDK"
DISK_LABEL = "sdk-persistent"
DISK_MIN_SIZE = 17 # 20 - 20*10% - 1
HELP_LINK = "https://developer.apertis.org/latest/sdk-usage.html"
MOUNT_POINT = "/run/media/persistent"
PERSISTENT_ETC_PREFIX = "/home"
......@@ -443,6 +445,57 @@ def scan_persistent_etc():
for line in result.stdout.decode().splitlines():
persistent_to_conf(line)
def menu(empty_disk_found=False, pdisk_found=False, pdisk_in_use=False):
"""Menu for user interaction"""
print("Persistent disk setup")
print("\nFor help visit:\n\t" + HELP_LINK)
print("\nStatus:")
if pdisk_in_use:
print("\tPersistent disk in use: {}".format(str(pdisk_in_use)))
print("\nThis SDK is currently using the persistent disk. No further action required.")
input("\nPress enter to exit")
return False
if (not pdisk_found) and (not empty_disk_found):
print("\nNo disk found to use as persistent storage.")
input("\nPress enter to exit")
return False
if empty_disk_found:
print("\tEmpty disk found: {}".format(str(empty_disk_found)))
answer = input("\nDo you want to initialize the empty disk {} ".format(empty_disk_found) +
"and configure the SDK to use it as persistent disk?\n" +
"(yes and press enter): ")
if answer == "yes":
disk = Disk(empty_disk_found, DISK_LABEL)
disk.initialize()
configure_sdk()
input("Disk initialization completed. Press enter to reboot the SDK.")
command = ["sudo", "reboot"]
_run(command)
return True
if pdisk_found:
print("\tPersistent disk in use: {}".format(str(pdisk_in_use)))
print("\tPersistent disk found: {}".format(str(pdisk_found)))
answer = input("\nDo you want to configure the SDK to use the persistent " +
"disk {}?\n".format(pdisk_found) +
"(yes and press enter): ")
if answer == "yes":
configure_sdk()
input("SDK configuration completed. Press enter to reboot the SDK.")
command = ["sudo", "reboot"]
_run(command)
return True
def persistent_disk_in_use():
"""Is the persistent disk in use?"""
......@@ -461,9 +514,50 @@ def persistent_disk_in_use():
return persistent_disk
def empty_disk(min_size=DISK_MIN_SIZE):
"""Find an empty disk with at least min_size"""
command = ["sudo", "fdisk", "-l"]
result = _run(command)
for line in result.stdout.decode().splitlines():
if "Disk /dev" in line:
disk = "/dev/" + re.findall(r"Disk /dev/([A-Za-z]+)", line)[0]
size = re.findall(r"Disk /dev/[A-Za-z]+\: ([0-9\.]+)", line)[0]
if disk_valid(disk) and disk_empty(disk):
size = int(float(size))
if size >= min_size:
return disk
return False
def probe_disks():
"""Look for disks that are currently available to check for empty_disk_found,
pdisk_found, and pdisk_in_use"""
empty_disk_found = empty_disk()
pdisk_in_use = persistent_disk_in_use()
# Persistent disk found?
pdisk_found = False
persistent_disk_link = "/dev/disk/by-label/" + DISK_LABEL
if os.path.islink(persistent_disk_link):
pdisk_found = os.readlink(persistent_disk_link)
pdisk_found = "/dev/" + os.path.split(pdisk_found)[1]
return empty_disk_found, pdisk_found, pdisk_in_use
def main():
"""good old main"""
if len(sys.argv) == 1:
# Interactive mode
empty_disk_found, pdisk_found, pdisk_in_use = probe_disks()
menu(empty_disk_found, pdisk_found, pdisk_in_use)
sys.exit()
parser = argparse.ArgumentParser()
etc_group = parser.add_argument_group("Configuration files management")
disk_group = parser.add_argument_group("Persistent disk management")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment