赞
踩
autoStart.py
# encoding: utf-8
# -*- coding: utf-8 -*-
import sys
import os
import ctypes
import subprocess
default_encoding = 'utf-8'
if sys.getdefaultencoding() != default_encoding:
reload(sys)
sys.setdefaultencoding(default_encoding)
##########################################################################
def setAutoOpenUnity():
# 使用Unity命令行打开项目
cmd = ur'C:\"Program Files"\\Unity2018.2.0f2\Editor\\Unity.exe -projectPath D:\proj'
try:
subprocess.Popen(cmd.encode('gbk'),stdin=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)
except subprocess.CalledProcessError as err:
msg = err.output.replace('\r\n','').decode('gbk')
print msg
def setAutoOpenVS():
# 使用VS命令行打开项目
cmd = ur'C:\"Program Files (x86)"\"Microsoft Visual Studio"\2017\Enterprise\Common7\IDE\devenv.exe D:\proj\proj.sln'
try:
subprocess.Popen(cmd.encode('gbk'),stdin=subprocess.PIPE, stderr=subprocess.PIPE,shell=True)
except subprocess.CalledProcessError as err:
msg = err.output.replace('\r\n','').decode('gbk')
print msg
def updateSvn():
projPaths = [ur'D:\proj1',ur'D:\proj2']
for path in projPaths:
if svn_cmd_isSvnPath(path):
returncode,svnmsg = svn_cmd_update(path)
if returncode:
if returncode == 1 or returncode == 3:
msg = u'[error] %s\r' % svnmsg
print(msg)
elif returncode == 2:
msg = u'[warning] %s\n' % svnmsg
print(msg)
else:
print(u'svn update succuss!')
PATH_CUR = u''
if getattr(sys, 'frozen', False):
PATH_CUR = os.path.dirname(sys.executable)
elif __file__:
PATH_CUR = os.path.dirname(__file__)
# svn_cmd_line命令行工具所在路径
SVN_CMD_LINE_PATH = os.path.join(PATH_CUR.decode('gbk'),ur'svn_cmd_line/bin/')
def _judgeSvnCmdExist():
if not os.path.exists(SVN_CMD_LINE_PATH+'svn.exe'):
outstr=u'[error] cannot find svn_cmd_line! path = %s\n'%SVN_CMD_LINE_PATH
printRed(outstr)
return False,outstr
else:
return True,''
def svn_cmd_isSvnPath(path):
if _judgeSvnCmdExist()[0]:
cmd = ur'%ssvn info %s --show-item revision' % (SVN_CMD_LINE_PATH,path)
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
si.wShowWindow = subprocess.SW_HIDE
returncode=subprocess.call(cmd.encode('gbk'),startupinfo=si)
return returncode == 0 and True or False
return False
def svn_cmd_update(path):
cmdok,msg = _judgeSvnCmdExist()
if not cmdok:
return (1,msg)
# svn update冲突 不会引发异常,retruncode==0;
# 这里通过分析output字符串行中‘C ’前缀 判断是否出现冲突
returnItems = [
(0,u''), #没有获取到新内容
(1,u'svn更新出错! '),
(2,u'从svn获取到了新的变更,请确认!'),
(3,u'svn更新遇到了冲突项,请手动处理!')
]
# svn update path -r:版本号 --accept postpone:冲突延迟处理
cmd = ur'%ssvn update %s -r HEAD --accept postpone' % (SVN_CMD_LINE_PATH,path)
try:
si = subprocess.STARTUPINFO()
si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
si.wShowWindow = subprocess.SW_HIDE
output = subprocess.check_output(cmd.encode('gbk'),stdin=subprocess.PIPE, stderr=subprocess.PIPE,startupinfo=si)
output = output.strip('\r\n')
if output and str(output):
print output
lines = output.split('\r\n')
noNew = lines and len(lines)<=2 and True or False
if noNew:
return returnItems[0]
for line in lines:
ret = re.match(r'^C\s+\S+',line.strip())
if ret:
return returnItems[3]
return returnItems[2]
return returnItems[0]
except subprocess.CalledProcessError as err:
msg = err.output.replace('\r\n','').decode('gbk')
return (returnItems[1][0],returnItems[1][1]+msg)
##########################################################################
if __name__ == '__main__':
print(u'[1] update svn.')
updateSvn()
print(u'[2] open unity proj.')
setAutoOpenUnity()
print(u'[3] open vs proj.')
setAutoOpenVS()
print(u'--- End ---')
exit(0)
autoStart.bat
@echo off
python D:\program\autoStart\autoStart.py
pause
autoStart.bat 放到开机启动目录下
开机启动目录:C:\Users\xxx\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。