首页 > 编程语言 > 详细

Python - 检测U盘烧录小工具

时间:2020-01-14 15:11:39      阅读:77      评论:0      收藏:0      [点我收藏+]

自己不从事开发工作,方便自己工作时写了个小工具。

准备后面写成GUI图形化工具,先把代码保存在这里

待完善...

import os
import string
import time


# 获取磁盘列表,返回list
def get_disklist():
    disk_list = []
    for i in string.ascii_uppercase:
        disk = i + :
        if os.path.isdir(disk):
            disk_list.append(disk)
    return disk_list


# 读取文件方法
def read_file():
    # 最后一个(新增的)盘符路径赋给t
    t = get_disklist()[-1]
    # sn为需要读取的文本名称(存放SN码的文件)
    c = t + r\sn
    with open(c, r) as files:
        str_num = files.read()
    return str_num


# 加密方法
def author(xin):
    #公司机密,不方便透露
    return str1


if __name__ == __main__:
    # 计数器
    a = 0
    while True:
        # 3为可变动数字,请改为未插入U盘前的磁盘分区数
        if len(get_disklist()) > 3:
            read_num = read_file()
            print(读取到的初始值为:{}.format(read_num))
            # 2d27572e
            if read_num == 2d27572e:
                print(sn为初始值,请使用树莓派启动此内存卡后再使用此脚本)
            else:
                # 调用author方法得到需要的结果值
                write_num = author(read_num)
                # print(write_num)
                w_way = get_disklist()[-1] + r\author
                # print(w_way)
                # 写入文件
                with open(w_way, w) as f:
                    f.write(write_num)
                    print(写入成功)
                print(写入值为:{}.format(write_num))
                # 烧写成功后计数器+1
                a += 1
                print(刚刚烧录的是第{}张内存卡.format(a))
                while True:
                    if len(get_disklist()) > 3:
                        print(请拔出U盘)
                        time.sleep(2)
                    else:
                        break
        else:
            print(请插入新的U盘)

        time.sleep(2)

Python - 检测U盘烧录小工具

原文:https://www.cnblogs.com/cxstudypython/p/12191961.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!