def checkFileExists(self, fileuniquekey, toDir, complete): outDir = self.filespath; if toDir != None: outDir = self.filespath + os.sep + toDir; Utils.createDir(outDir); outfile = outDir + os.sep + fileuniquekey; if os.path.isfile(outfile) and os.path.getsize(outfile) > 0: complete(True); else: complete(False);
def check(self): #url urlParseResult = urlparse.urlsplit(self.url) if urlParseResult == None: self.error("Config.url配置错误") self.scheme = urlParseResult.scheme self.host = urlParseResult.netloc if not Utils.isValidStr(self.scheme) or not Utils.isValidStr( self.host): self.error("Config.url配置错误") #outPath if not Utils.isValidStr(self.outPath): self.error("Config.outPath配置错误") if not os.path.isdir(self.outPath): if not Utils.createDir(self.outPath): self.error("Config.outPath配置错误") from src.utils import Log Log.setOutPath(self.outPath) self.tmpPath = self.outPath + os.sep + ".tmp" if not os.path.isdir(self.tmpPath): if not Utils.createDir(self.tmpPath): self.error("Config.outPath配置错误") #parser if self.parserName != "YbduParser": self.error("Config.parserName配置错误") #storge if self.storgeName != "FileStorge" and self.storgeName != "QiniuStorge" and self.storgeName != "AWSStorge": self.error("Config.storgeName配置错误") if self.storgeName == "QiniuStorge": if not Utils.isValidStr(self.qnAK) or not Utils.isValidStr( self.qnSK) or not Utils.isValidStr(self.qnBK): self.error("未配置七牛云的 access key,secret key,bucketname") elif self.storgeName == "AWSStorge": if not Utils.isValidStr(self.awsBK): self.error("未配置AWS的bucketname") #aescode if self.aesCode != None and not Utils.isValidStr(self.aesCode): self.error("Config.aesCode配置错误") #parserType if self.parseType != "all" and self.parseType != "single": self.error("Config.parsetType配置错误") #数据库 if not Utils.isValidStr(self.dbUser) or not Utils.isValidStr( self.dbPwd) or not Utils.isValidStr(self.dbName): self.error("未配置mysql的用户名,密码或数据库名称")
def pushContent(self, content, fileuniquekey, toDir, complete): if content == None: if complete != None: complete(False); return; outDir = self.filespath; if toDir != None: outDir = self.filespath + os.sep + toDir; Utils.createDir(outDir); outfile = outDir + os.sep + fileuniquekey; succ = Utils.writeFile(outfile, content, "w"); if not succ: if complete != None: complete(False); return; if complete != None: complete(True);
def __init__(self, outPath): Log.D("[I] FileStorge inited"); super(FileStorge, self).__init__(outPath); self.filespath = self.outPath + os.sep + "files"; Utils.createDir(self.filespath);