Skip to content

Instantly share code, notes, and snippets.

@582033
Last active December 5, 2016 01:55
Show Gist options
  • Save 582033/4744ebe345686eda85c1389807a826b2 to your computer and use it in GitHub Desktop.
Save 582033/4744ebe345686eda85c1389807a826b2 to your computer and use it in GitHub Desktop.
svnpub 一键部署代码脚本
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# https://gist.github.com/582033/4744ebe345686eda85c1389807a826b2
import requests
import json, re, sys
from bs4 import BeautifulSoup
from pprint import pprint
class Sign:
def __init__(self, username, password):
self.username = username
self.password = password
self.cas_auth()
#统一认证
def cas_auth(self):
#抑制ssl错误提示
requests.packages.urllib3.disable_warnings()
url = "https://cas.intra.leju.com/login"
r = requests.get(url, verify=False)
jsessionid = self._get_jsessionid(r.headers['Set-Cookie'])
html = BeautifulSoup(r.content, 'html.parser')
lt = html.find("input", {"name":"lt"})['value'].encode('utf-8')
login_data = {
'username' : self.username,
'domain' : 'leju.com',
'password' : self.password,
'lt' : lt,
'_eventId' : 'submit',
}
#print login_data
#sys.exit()
post_url = "%s;jsessionid=%s" % (url, jsessionid)
#获取cas认证信息完成
self.cas = requests.Session()
self.cas.post(post_url, data=login_data, verify=False)
#print self.cas.get(post_url).content
#sys.exit()
#获取测试线/正式线代码
def get_project(self, project_id, type='test'):
url = "http://svnpub.intra.leju.com/index_p.php?project_id=%s" % project_id
r = self.cas.get(url)
#print r.content
#sys.exit()
if type is 'test':
#获取测试代码
self.cas.get('http://svnpub.intra.leju.com/sandbox/getcode_svn.php?type=p&gtype=server&ReleaseServer=1')
if type is 'release':
#获取正式代码
self.cas.get('http://svnpub.intra.leju.com/sandbox/getcode_svn.php?type=p&gtype=server&ReleaseServer=2')
#self.deploy_all()
#进行部署操作,此为部署所有有文件
def deploy_all(self):
get_list_url = "http://svnpub.intra.leju.com/codelist.php"
r = self.cas.get(get_list_url)
html = BeautifulSoup(r.content, 'html.parser')
#print html.find(name="Filelist[]")
post_data = []
for input in html.find_all('input', {"name":"Filelist[]"}):
#print input['value']
post_data.append(('Filelist[]', input['value']))
#print post_data
result = self.cas.post('http://svnpub.intra.leju.com/release.php', data=post_data)
print result.content
def _get_jsessionid(self, cookie):
regex = r"[0-9A-Z]{32}"
match = re.search(regex, cookie)
if match:
return match.group()
else:
print "获取jsessionid错误"
sys.exit()
if __name__ == '__main__':
svnpub = Sign('username', 'password')
svnpub.get_project('project_id')
svnpub.deploy_all()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment