Esempio n. 1
0
 def combineMain(self, ip):
     #合并主列表
     self.outfile = self.tmpdir + 'main_' + ip
     self.corefile = self.tmpdir + 'core_' + ip
     #操作信息
     mainfile = self.dir + self.outfile + self.fileext
     print("Preparing main tempfile: '%s'" % (mainfile))
     
     outstream = open(self.dir + self.outfile + self.fileext, 'w')
     mods = self.modules
     mods.append(self.corefile)
     for module in mods:
         modfile = self.dir + module + self.fileext
         #反馈状态
         print("%s -> %s" % (modfile, mainfile))
         instream = open(modfile, 'r')
         lines = instream.readlines()
         for line in lines:
             outstream.write(line.decode(self.coding).encode(self.coding, 'ignore'))
         instream.close()
         outstream.write('\n')
     outstream.close()
     
     #规范编码及换行符
     convertfile(mainfile)
     
     # Core文件删除信息
     print("remove corefile: '%s'" % (self.corefile))
     
     mods.remove(self.corefile)                                      #删除自有模块
     os.remove(self.dir + self.corefile + self.fileext)              #删除核心文件
     print('')
Esempio n. 2
0
 def combineCore(self, ip):
     #合并核心列表
     
     #设定模块
     mods = []
     mods.append(self.sharedir + self.sharemods[0])
     for mod in self.coremods:
         mods.append(ip + self.coredir + mod)
     mods.append(self.sharedir + self.sharemods[1])
     
     self.corefile = self.tmpdir + 'core_' + ip
     #操作信息
     corefile = self.dir + self.corefile + self.fileext
     print("Preparing corefile: '%s'" % (corefile))
     
     outstream = open(corefile, 'w')
     
     #合并操作
     for module in mods:
         modfile = self.dir + module + self.fileext
         #反馈状态
         print("%s -> %s" % (modfile, corefile))
         instream = open(modfile, 'r')
         lines = instream.readlines()
         for line in lines:
             outstream.write(line.decode(self.coding).encode(self.coding, 'ignore'))
         instream.close()
         outstream.write('\n')
     outstream.close()
     print('')
     #规范编码及换行符
     convertfile(corefile)
Esempio n. 3
0
 def export(self, subdir, ip, coding, ADflag = True):
     #生成文件
     if os.path.exists(self.rawdir + subdir) == False:
         os.mkdir(self.rawdir + subdir)
     outstream = open(self.rawdir + subdir + 'hosts', 'w')
     #写主文件
     instream = open(self.dir + self.tmpdir + self.mainfile_pre + ip + self.fileext, 'rU')
     lines = instream.readlines()
     for line in lines:
         outstream.write(line.decode(self.coding).encode(coding, 'ignore'))
     instream.close()
     #写ADBlock文件
     if ADflag:
         instream = open(self.dir + self.tmpdir + self.adfile + self.fileext, 'rU')
         lines = instream.readlines()
         for line in lines:
             outstream.write(line.decode(self.coding).encode(coding, 'ignore'))
     outstream.close()
     if coding == 'utf-8':
         convertfile(self.rawdir + subdir + 'hosts')
Esempio n. 4
0
 def combineAdblock(self):
     #合并广告屏蔽列表
     adfile = self.dir + self.tmpdir + self.adfile + self.fileext
     print("Preparing ADblock tempfile: '%s'" % (adfile))
     
     outstream = open(adfile, 'w')
     outstream.write('# region adblock\n\n')
     mods = self.admods
     for module in mods:
         modfile = self.dir + self.adsubdir + module + self.fileext
         #反馈状态
         print("%s -> %s" % (modfile, adfile))
         instream = open(modfile, 'r')
         lines = instream.readlines()
         for line in lines:
             outstream.write(line.decode(self.coding).encode(self.coding, 'ignore'))
         instream.close()
         outstream.write('\n')
         
     outstream.write('# endregion')
     outstream.close()
     print('')
     #规范编码及换行符
     convertfile(adfile)