首先這里是最簡單的將文件壓縮成壓縮文件:

          # ?-*-?coding:utf-8?-*-
          #
          =============================================================================================================
          #
          #
          ???brief???:????制作viruswall?的離線升級數據
          #
          #
          ???author??:????hechangmin
          #
          #
          ???date????:????2008.6?
          #
          #
          =============================================================================================================

          import ?os
          import ?threading,?zipfile

          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)
          ????
          print ?files
          ????
          for ?file? in ?files:
          ????????background?
          = ?AsyncZip(file,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 " )
          ????

          顯然這里壓縮成功了,但是壓縮采用的是zip算法。
          還希望是采用 tar+ GZIP 的方式。。。。。
          posted on 2008-06-26 09:39 -274°C 閱讀(911) 評論(0)  編輯  收藏 所屬分類: python

          常用鏈接

          留言簿(21)

          隨筆分類(265)

          隨筆檔案(242)

          相冊

          JAVA網站

          關注的Blog

          搜索

          •  

          積分與排名

          • 積分 - 916817
          • 排名 - 40

          最新評論

          主站蜘蛛池模板: 遂平县| 迁西县| 长岛县| 济宁市| 正安县| 凉城县| 武宣县| 吉林省| 岑巩县| 墨脱县| 四子王旗| 仙居县| 靖宇县| 上饶市| 沭阳县| 虎林市| 福州市| 射阳县| 诸暨市| 和田市| 开封县| 宜阳县| 晋江市| 克拉玛依市| 伊金霍洛旗| 栾城县| 天全县| 惠安县| 长寿区| 化德县| 吉安市| 资中县| 疏附县| 荆州市| 犍为县| 汉阴县| 沧州市| 富裕县| 蚌埠市| 修武县| 鹤壁市|