#coding=utf-8
'''
Created on 2016年5月30日

@author: mario
'''
import os
import os.path
import shutil
import time,  datetime

class FileOperation:
    def __init__(self):
        pass
    
    def __del__(self):
        pass
        
    def copyFiles(self, sourceDir,  targetDir): 
        if sourceDir.find(".svn") > 0: 
            return 
        for file in os.listdir(sourceDir): 
            sourceFile = os.path.join(sourceDir,  file) 
            targetFile = os.path.join(targetDir,  file) 
            if os.path.isfile(sourceFile): 
                if not os.path.exists(targetDir):  
                    os.makedirs(targetDir)  
                if not os.path.exists(targetFile) or(os.path.exists(targetFile) and (os.path.getsize(targetFile) != os.path.getsize(sourceFile))):  
                    open(targetFile, "wb").write(open(sourceFile, "rb").read()) 
            if os.path.isdir(sourceFile): 
                First_Directory = False 
                self.copyFiles(sourceFile, targetFile)
                
    def removeFileInFirstDir(self, targetDir): 
        for file in os.listdir(targetDir): 
            targetFile = os.path.join(targetDir,  file) 
            if os.path.isfile(targetFile): 
                os.remove(targetFile)
                
    def deleteFile(self, fileName):
        targetFile = os.path.join("./" , fileName)
        if os.path.isfile(targetFile):
            os.remove(targetFile)
                
    def coverFiles(self, sourceDir,  targetDir): 
        for file in os.listdir(sourceDir): 
            sourceFile = os.path.join(sourceDir,  file) 
            targetFile = os.path.join(targetDir,  file) 
            #cover the files 
            if os.path.isfile(sourceFile): 
                open(targetFile, "wb").write(open(sourceFile, "rb").read())
                
    def moveFileto(self, sourceDir,  targetDir): 
        shutil.copy(sourceDir,  targetDir)
        
    def writeVersionInfo(self, targetDir): 
        open(targetDir, "wb").write("Revison:")
        
    def getCurTime(self): 
        nowTime = time.localtime() 
        year = str(nowTime.tm_year) 
        month = str(nowTime.tm_mon) 
        if len(month) < 2: 
            month = '0' + month 
        day =  str(nowTime.tm_yday) 
        if len(day) < 2: 
            day = '0' + day 
        return (year + '-' + month + '-' + day)
    
if __name__ == "__main__":
    print "Start(S) or Quilt(Q) \n" 
    deleteFile = FileOperation()
    deleteFile.deleteFile('test.txt')