python操作jira
首先安装jira模块
$ pip install jira
导入jira模块
from jira import JIRA import xlrd # 导入xlrd,xlrd可以支持读取xls文件,不支持读取xlsx
编写添加模块代码
下面展示一些 内联代码片 。
def add_module_to_jira(jiraurl,username,password,modulename,projectKey):
myjira = JIRA(jiraurl, basic_auth=(username, password))
myjira.create_component(modulename,projectKey)
获取当前项目的模块信息
def get_project_compopents(jiraurl,username,password,projectKey):
myjira = JIRA(jiraurl, basic_auth=(username, password))
return myjira.project_components(projectKey)
从excel表读取信息
def read_xls(xls_path,sheetName):
worksheet = xlrd.open_workbook(xls_path) # 打开excel文件,参数为文件的路径
sheet_names = worksheet.sheet_names() # 获取excel文件的所有sheet页,返回名字列表,
# sheet_name=worksheet.sheet_by_name('Sheet1')#
print(sheet_names)
# print(sheet_name)
sheet = worksheet.sheet_by_name(sheetName) # 获取到sheet名称为Sheet1的sheet页
row = sheet.nrows # 获取文件行数
cow = sheet.ncols # 获取文件列数
scores = sheet.col_values(4, 1, row)
scoreslsit = []
for score in scores:
# scorelist = score.split('&')
# print(scorelist)
print(score)
scoreslsit.append(score)
return scoreslsit
主方法中调用添加模块等方法
ss=get_project_compopents(jiraurl,username,password,projectKey=projectkey)
module=[]
print(ss)
for one in ss:
print(one.name)
module.append(one.name)
print('ssss',len(ss))
print(module)
print("module:",len(module))
modunameList = read_xls(r'D:\test9.xls', 'Sheet1')
print(modunameList)
print("modulist的长度",len(modunameList))
modulenew=[]
moduleold=[]
for one in modunameList:
if one in module:
moduleold.append(one)
continue
else:
modulenew.append(one)
print("modulnew的内容如下:")
print(modulenew)
print("modulnew的长度是",len(modulenew))
print("moduleOld是------------")
print(moduleold)
print("moduleOld是------------")
for moduname in modulenew:
print(moduname)
add_module_to_jira(jiraurl=jiraurl,username=username,password=password,modulename=moduname,projectKey=projectkey)
|