Beispiel #1
0
def select_disk_to_remove():

    disk_logs = json.loads(open(all_log_disks_file).read())

    try:
        plugged_disks = json.loads(safe_read(plugged_disks_file))
    except FileNotFoundError:
        serials = []
    else:
        serials = [key for key in plugged_disks.keys()]

    print("请选择要移除的移动存储设备:")
    print()
    for serial in serials:
        friendly_name = None
        for one in disk_logs:
            if one["serial"] == serial:
                friendly_name = one["friendly_name"]

        print("  %d - %s" % (serials.index(serial) + 1, friendly_name or serial))
    print()
    print("(直接回车刷新)")
    print("选择:", end="")
    choose = input()
    if choose.lower() in ("e", "q"):
        exit()

    try:
        return serials[int(choose) - 1]
    except (ValueError, IndexError):
        return None
Beispiel #2
0
def main():
    while True:
        disk_logs = json.loads(open(all_log_disks_file).read())
        print()
        os.system("clear")
        print(head())

        serial = select_disk_to_remove()

        if serial is not None:
            print("=>正在卸载资源...", end="")
            safe_write(serial, need_remove_disk_file)

            time.sleep(5)
            try:
                s = safe_read(remove_disk_done_file)
            except FileNotFoundError:
                continue
            if s == serial:
                print("完成!")
                time.sleep(1)
                print("=>请现在移除移动存储设备, 然后按下回车键返回主界面:", end="")
                input()