Exemple #1
0
 def CheckUsb(self):
     """检查USB"""
     path = self.FilesLists[0]
     usb = FiveFileParser.getcomments(path, ('usb', ))['usb']
     if usb != []:  #如果存在usb残留则删除记录
         FiveFileParser.removeComments(path, ['usb'])
     FiveFileParser.writeComments(path, ['usb*'])
     tempusb = 'None'  #暂存usb的路径
     usbPATH = '/media/pi'  #"/media/pi"#树莓派的Usb路径更改处
     if os.path.exists(usbPATH):
         if len(os.listdir(usbPATH)) != 0:
             for i in os.listdir(usbPATH):
                 if os.path.exists(os.path.join(usbPATH, i)):
                     tempusb = os.path.join(usbPATH, i)
                     self.usb = tempusb
                     break
     tempusb = self.Savepath if tempusb == 'None' else tempusb
     FiveFileParser.updateComments(path, {'usb': r'{}'.format(tempusb)})
Exemple #2
0
 def CheckFiles(self):
     """检查文件是否存在"""
     try:
         for index, files in enumerate(self.FilesLists):
             files = os.path.normpath(files)
             if not os.path.exists(files):
                 with open(files, "w") as f:
                     self.log.info("create file:{}".format(files))
                     if index == 0:  #"setting.txt"
                         FiveFileParser.writeComments(
                             files, [r'saving*{}'.format(files)])
                     if index == 1:
                         table = {
                             "省份名": "工厂名",
                         }
                         FiveFileParser.insertTable(table, 'regions', files,
                                                    0)
                     if index == 2:
                         table = {
                             "参数表名": "0",
                             "电厂": "0",
                             '阀门型号': "0",
                             '整定压力': "0",
                             '弹簧刚度': "0",
                             '密封面内径': "0",
                             '密封面外径': "0",
                             '整调螺母方数': "0",
                         }
                         FiveFileParser.insertTable(table, 'MUBAN0', files,
                                                    0)
             else:
                 if index == 0:  #"setting.txt"
                     FiveFileParser.updateComments(
                         files, {'usb': r'{}'.format(self.Savepath)})
         return True
     except Exception as e:
         return False