Example #1
0
 def safeModeDeal(self, action, filename):
     if self.mode == 'safe':
         whiteNum = len(self.whiteList)
         flag = False
         for i in xrange(0, whiteNum):  # 判断是否在白名单里面
             if len(filename) > len(self.whiteList[i]):
                 if filename[:len(self.whiteList[i]
                                  )] in self.whiteList:  #在白名单里
                     flag = True
                     suffix = filename.find('.')  # 判断是否在黑名单里面
                     blackFlag = False
                     if suffix != -1:
                         suffix = filename[suffix + 1:]
                         for x in xrange(0, len(self.blackList)):
                             if self.blackList[x].lower() in suffix.lower():
                                 blackFlag = True
                     if blackFlag:  # 黑名单修复
                         self.repair(action, filename)
                     else:  # 百名单跳过
                         flag, bakPath = treedeal.bakIsExist(
                             filename, self.monitorPath, self.projectName,
                             self.bakPath, self.flagName)
                         if flag != 'fold':
                             self.qHeartHeats.put([action, filename, 0])
                     break
         if not flag:  # 不在白名单
             self.repair(action, filename)
     else:
         self.repair(action, filename)
Example #2
0
 def repair(self, action, filename):
     flag, bakPath = treedeal.bakIsExist(filename, self.monitorPath,
                                         self.projectName, self.bakPath,
                                         self.flagName)
     if action == 'Created' or action == 'Renamed to something':  #重命名:
         if flag == 'no':
             self.dealAndMessage(action, filename, 'delete')
         else:  # 计算md5值
             bakFileText = filedeal.getZipContent(flag, bakPath)
             if os.path.isdir(filename):  #判断file是否为文件夹
                 if not common.compareFoldStr(filename, bakFileText):
                     self.dealAndMessage(action, filename, 'restore')
             elif os.path.isfile(filename):  #判断是否为文件,是则进行压缩
                 with open(filename, 'rb') as f:
                     webFileText = f.read()
                 if not common.compareFileStr(webFileText, bakFileText):
                     self.dealAndMessage(action, filename, 'restore')
     elif action == 'Deleted' or action == 'Renamed from something':  #重命名:
         if flag != 'no':
             self.dealAndMessage(action, filename, 'restore')
     elif action == 'Updated':  #修改
         if flag != 'no':
             bakFileText = filedeal.getZipContent(flag, bakPath)
             if os.path.isdir(filename):  #判断file是否为文件夹
                 if not common.compareFoldStr(filename, bakFileText):
                     self.dealAndMessage(action, filename, 'restore')
             elif os.path.isfile(filename):  #判断是否为文件,是则进行压缩
                 with open(filename, 'rb') as f:
                     webFileText = f.read()
                 if not common.compareFileStr(webFileText, bakFileText):
                     self.dealAndMessage(action, filename, 'restore')
Example #3
0
 def _runRepair(self, targetPath):
     pList = os.listdir(targetPath)
     pList.sort()
     for i in pList:
         fold = os.sep.join([targetPath, i])
         flag, bakPath = treedeal.bakIsExist(special.decoding(fold),
                                             self.sessionDic['targetPath'],
                                             self.sessionDic['projectName'],
                                             self.bakTopPath,
                                             self.sessionDic['flagName'])
         if os.path.isdir(fold):
             if flag == 'fold':
                 self._runRepair(fold)
             else:
                 filedeal.delete(special.decoding(fold))
         elif os.path.isfile(fold):
             if flag != 'file':
                 filedeal.delete(special.decoding(fold))
         else:
             filedeal.delete(special.decoding(fold))