加入tar中間過程:

          # ?-*-?coding:utf-8?-*-
          #
          =============================================================================================================
          #
          #
          ???brief???:????制作viruswall?的離線升級數(shù)據
          #
          #
          ???author??:????hechangmin
          #
          #
          ???date????:????2008.6?
          #
          #
          ???notice??:????先變成tar?文件
          #
          =============================================================================================================

          import ?os
          import ?threading,?zipfile
          import ?tarfile

          class ?AsyncZip(threading.Thread):
          ????
          ????
          def ? __init__ (self,?infile,?outfile):
          ????????threading.Thread.
          __init__ (self)????????
          ????????self.infile?
          = ?infile
          ????????self.outfile?
          = ?outfile
          ????
          def ?run(self):
          ????????state?
          = ? ' w '
          ????????
          if ?os.path.isfile(self.outfile)? == ?True:
          ????????????state?
          = ? ' a '
          ????????f?
          = ?zipfile.ZipFile(self.outfile,?state,?zipfile.ZIP_DEFLATED)
          ????????f.write(self.infile)
          ????????f.close()
          ????????
          print ? ' Finished?background?zip?of:? ' ,?self.infile
          ????????
          def ?zipDir(src,dst):
          ????
          ????initPath?
          = ?os.getcwd()
          ????
          ????tempDST?
          = ??os.path.join(os.getcwd(),dst)
          ????tempSRC?
          = ??os.path.join(os.getcwd(),src)
          ????os.chdir(?tempSRC?)
          ????files?
          = ?os.listdir(os.curdir)
          ????tar?
          = ?tarfile.open( " temp.tar " , " w " )
          ????
          for ?file? in ?files:
          ????????tar.add(file)
          ????tar.close()
          ????background?
          = ?AsyncZip( " temp.tar " ,dst)
          ????background.start()
          ????background.join()????
          # ?Wait?for?the?background?task?to?finish
          ????????
          ????os.chdir(?initPath?)
          ????
          print ?os.getcwd()
          # test?ok
          if ? __name__ ? == ? ' __main__ ' :
          ????
          ????zipDir(
          " D:\\AutoUpdate\\DataDist\\viruswall\\Data\\KSVW-VirusDB\\ " , " d:\\AutoUpdate\\DataDist\\viruswall\\Data\\update\\KSVW-VirusDB.tgz " )
          ????

          當然還不夠,因為這里雖然加入了tar環(huán)節(jié),但是最后還是zip壓縮。
          posted on 2008-06-26 09:52 -274°C 閱讀(566) 評論(0)  編輯  收藏 所屬分類: python

          常用鏈接

          留言簿(21)

          隨筆分類(265)

          隨筆檔案(242)

          相冊

          JAVA網站

          關注的Blog

          搜索

          •  

          積分與排名

          • 積分 - 916110
          • 排名 - 40

          最新評論

          主站蜘蛛池模板: 酉阳| 响水县| 曲靖市| 元氏县| 腾冲县| 衡南县| 乌兰浩特市| 盘锦市| 黎川县| 炉霍县| 尚义县| 佳木斯市| 公安县| 大余县| 溧阳市| 盱眙县| 霍州市| 务川| 会泽县| 武汉市| 柳河县| 文化| 凤山县| 南城县| 达尔| 那曲县| 大丰市| 定西市| 长沙市| 睢宁县| 武定县| 句容市| 海南省| 彰化县| 南阳市| 宁明县| 安宁市| 玛纳斯县| 柳林县| 安吉县| 霞浦县|