自動打包,不過目前無法完成 7z 打包
# -*- encoding: utf8 -*-
import os
import tempfile
import shutil
import subprocess
userDir = os.path.expanduser('~')
a7zDir = r'C:\Program Files\7-Zip\7z.exe'
projDir = r'C:\Users\master\Documents\Visual Studio 2015\Projects\Project1'
outDir = userDir + r'\Desktop\oop'
index = 13
outName = 'B10301045-許文誠-A' + str(index) + '.7z'
# 拷貝專案
parentDir, projName = os.path.split(projDir)
tmpDir = tempfile.gettempdir()
os.chdir(tmpDir)
if os.path.exists(projName):
shutil.rmtree(projName)
shutil.copytree(projDir, projName)
# Page 8,只留下 Project
for x in os.listdir(projName):
if x!=projName and x!=projName+'.sln':
fileName = projName + '\\' + x
if os.path.isdir(fileName):
shutil.rmtree(fileName)
else:
os.remove(fileName)
# hack python 2.7.11 bug
x, y = os.path.split(projDir)
dirName = tmpDir + '\\' + y + '\\' + y + '\\Debug'
# Page 9,刪除 Debug
if os.path.exists(dirName):
shutil.rmtree(dirName)
# 打包
a, b = os.path.split(a7zDir)
os.chdir(a)
print 'cd ' + a
cmd = b + ' a ' + outDir + '\\' + outName + ' ' + tmpDir + '\\' + y
print 'cd ' + a + ' && ' + cmd