首先这里是最简单的将文件压缩成压缩文件:
		
				 #
				 -*- coding:utf-8 -*-
				#
				 -*- coding:utf-8 -*-
				
						
						 #
				=============================================================================================================
#
				=============================================================================================================
				
						
						 #
#
 #
				   brief   :    制作viruswall 的离线升级数据
#
				   brief   :    制作viruswall 的离线升级数据
				
						
						 #
#
 #
				   author  :    hechangmin
#
				   author  :    hechangmin
				
						
						 #
#
 #
				   date    :    2008.6
#
				   date    :    2008.6 
				
						
						 #
#
 #
				=============================================================================================================
#
				=============================================================================================================
				
						
						 
				
				
						
						 import
				 os
				
				import
				 os
 import
				 threading, zipfile
				import
				 threading, zipfile

 class
				 AsyncZip(threading.Thread):
				class
				 AsyncZip(threading.Thread):
 
    
 def
				 
				__init__
				(self, infile, outfile):
    
				def
				 
				__init__
				(self, infile, outfile):
 threading.Thread.
				__init__
				(self)
        threading.Thread.
				__init__
				(self)        
 self.infile 
				=
				 infile
        self.infile 
				=
				 infile
 self.outfile 
				=
				 outfile
        self.outfile 
				=
				 outfile
 def
				 run(self):
    
				def
				 run(self):
 state 
				=
				 
				'
				w
				'
        state 
				=
				 
				'
				w
				'
				
						
						 if
				 os.path.isfile(self.outfile) 
				==
				 True:
        
				if
				 os.path.isfile(self.outfile) 
				==
				 True:
 state 
				=
				 
				'
				a
				'
            state 
				=
				 
				'
				a
				'
				
						
						 f 
				=
				 zipfile.ZipFile(self.outfile, state, zipfile.ZIP_DEFLATED)
        f 
				=
				 zipfile.ZipFile(self.outfile, state, zipfile.ZIP_DEFLATED)
 f.write(self.infile)
        f.write(self.infile)
 f.close()
        f.close()
 print
				 
				'
				Finished background zip of: 
				'
				, self.infile
        
				print
				 
				'
				Finished background zip of: 
				'
				, self.infile
 
        
 def
				 zipDir(src,dst):
				def
				 zipDir(src,dst):
 
    
 initPath 
				=
				 os.getcwd()
    initPath 
				=
				 os.getcwd()
 
    
 tempDST 
				=
				  os.path.join(os.getcwd(),dst)
    tempDST 
				=
				  os.path.join(os.getcwd(),dst)
 tempSRC 
				=
				  os.path.join(os.getcwd(),src)
    tempSRC 
				=
				  os.path.join(os.getcwd(),src)
 os.chdir( tempSRC )
    os.chdir( tempSRC )
 files 
				=
				 os.listdir(os.curdir)
    files 
				=
				 os.listdir(os.curdir)
 print
				 files
    
				print
				 files
 for
				 file 
				in
				 files:
    
				for
				 file 
				in
				 files:
 background 
				=
				 AsyncZip(file,dst)
        background 
				=
				 AsyncZip(file,dst)
 background.start()
        background.start()
 background.join()    
				#
				 Wait for the background task to finish
        background.join()    
				#
				 Wait for the background task to finish
				
						
						 
				
				        
 os.chdir( initPath )
    os.chdir( initPath )
 print
				 os.getcwd()
    
				print
				 os.getcwd()
 #
				test ok
				#
				test ok
				
						
						 if
				 
				__name__
				 
				==
				 
				'
				__main__
				'
				:
				
				if
				 
				__name__
				 
				==
				 
				'
				__main__
				'
				:
 
    
 zipDir(
				"
				D:\\AutoUpdate\\DataDist\\viruswall\\Data\\KSVW-VirusDB\\
				"
				,
				"
				d:\\AutoUpdate\\DataDist\\viruswall\\Data\\update\\KSVW-VirusDB.tgz
				"
				)
    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 阅读(917) 
评论(0)  编辑  收藏  所属分类: 
python