#coding:utf-8
import time
import datetime
import re
import urlparse
class Tools(object):
@staticmethod
def num_to_timestr(num):
return time.strftime('%Y-%m-%d %H:%M:%S',time.localtime(num))
@staticmethod
def timestr_to_num(time_str):
return time.mktime(time.strptime(time_str,'%Y-%m-%d %H:%M:%S'))
@staticmethod
def get_today_zero_num():
return int(time.mktime(datetime.date.today().timetuple()))
@staticmethod
def get_yesterday_zero_num():
return int(time.mktime(datetime.date.today().timetuple())) -86400
@staticmethod
def ReFindall(Re_Rule,content):
return re.findall(Re_Rule,content,re.M|re.I)
@staticmethod
def get_current_timestamp():
return int(time.time())
@staticmethod
def juge_jenkins_url_correct(url):
# print 'juge_jenkins_url_correct',url
# url = Tools.ReFindall("http:\/\/\d+\.\d+\.\d+\.\d+:\d+\/jenkins\/[^' '\n\t\r\"\']{1,120}",url)
url = Tools.ReFindall("http:\/\/\d+\.\d+\.\d+\.\d+:\d+\/[^' '\n\t\r\"\']{1,120}",url)
# print 'juge_jenkins_url_correct2',url
if not url :
return False
return True
# 因为本地的master和实际的master地址差一个jenkins的uri所以这里需要更改。
@staticmethod
def get_params_use_url(url):
# print Tools.juge_jenkins_url_correct(url)
if Tools.juge_jenkins_url_correct(url):
result = urlparse.urlparse(url)
# print result
# url_master = ''.join([result.scheme,'://',result.netloc,'/jenkins'])
url_master = ''.join([result.scheme,'://',result.netloc,'/jenkins'])
parame_list = result.path.strip('/').split('/')
job_name = ''
buildnumber = ''
if len(parame_list) >=4 :
job_name = parame_list[2]
buildnumber = parame_list[3]
elif len(parame_list) ==3:
job_name = parame_list[2]
elif len(parame_list) <3 :
print '入参url错误:{0}'.format(url)
exit(0)
else :
print '入参url错误:{0}'.format(url)
exit(0)
# print buildnumber
buildnumber = int(buildnumber) if buildnumber else 0
return url_master,job_name,buildnumber
|