下沙污水管道清洗:oday 压缩文件解压工具------python版 - 独木的日志 - 网易博客

来源:百度文库 编辑:中财网 时间:2024/04/29 23:57:10

oday 压缩文件解压工具------python版

python 2007-04-04 14:03:39 阅读76 评论0   字号: 订阅

原来使用batch来调用WinRAR,解压oday 压缩文件,总是有些问题。后来学习python,就将程序改了一下,修正一些bug。

#!/usr/bin/python
# -*- coding: UTF-8 -*-

#  demo of the usage of python
#
#
#

"""Test code

Suggested usage: import MyUnrar
"""
__decription__ = "Batch Unrar Kit"
__version__ = "0.1"
__date__ = " Mar.28th.2007"
__author__ = "hu "
__license__ = "Licensed under the GPLv2, see the file LICENSE in this tarball."
__copyright__= "Copyright (C) 2007 by hu ."

from time import sleep
import string
import os
from os.path import join, getsize, abspath, exists, splitext

__WinRAR__="C:\\Program Files\\WinRAR\\WinRAR.exe"

exec_rar= '\"'+__WinRAR__ + '\"'
urar_chm =""" IF EXIST *.rar """ + exec_rar +"""  e -o- -y *.rar *.chm """
urar_pdf = """IF EXIST *.rar """ + exec_rar + """  e -o- -y *.rar *.pdf"""

class MyUnrar:
###
    def __init__ (self, path=os.getcwd()):
        self.path = path
        self.count = 0

###
    def checkRAR(self):
        if exists(__WinRAR__):
            print "WinRAR is OK!"       
        else:
            print "WinRAR is not there!"
       
   
###
    def unrar(self):
        print self.count
        for f in os.listdir( self.path ) :
            (filename, ext) = splitext(f)
            if ext.lower() == ".zip":
                command =exec_rar + ' e -o- -y ' + f + ' *.r*'
                os.system( command )
               
            if ext.lower() == ".rar":
                os.system( urar_chm )
                os.system( urar_pdf )
        self.count = self.count + 1
       
    def unrar(self, path):
        print self.count
        for f in os.listdir( path ) :
            (filename, ext) = splitext(f)
            if ext.lower() == ".zip":
                command =exec_rar +' e -o- -y ' + path + '\\' + f + ' *.r*'
            #    print command
                os.system( command )
               
            if ext.lower() == ".rar":
                os.system( urar_chm )
                os.system( urar_pdf )
        self.count = self.count + 1
       
    def deleteRAR(self):
        for f in os.listdir( self.path ) :
            (filename, ext) = splitext(f)
            if ext.lower().find(".r") != -1:
                os.remove(f)
               
###
    def run(self):
        print "==============================="
        print __decription__
        print 'version:', __version__
        print __license__
        print __copyright__
        print "==============================="
        self.checkRAR();

        for root, dirs, files in os.walk( self.path ):
            for name in dirs:
                    fullpath = join(root, name)
                    print fullpath
                    self.unrar(fullpath)
                    os.system( urar_chm )
                    os.system( urar_pdf )
                    self.deleteRAR()

       
       
###
if __name__=="__main__":
    ur = MyUnrar()
    ur.run()
    sleep(5)