本文整理匯總了Python中youtrack.connection.Connection類的典型用法代碼示例。如果您正苦於以下問題:Python Connection類的具體用法?Python Connection怎麽用?Python Connection使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Connection類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: jira2youtrack
def jira2youtrack(source_url, source_login, source_password, target_url, target_login, target_password, project_id):
print("source_url : " + source_url)
print("source_login : " + source_login)
print("source_password : " + source_password)
print("target_url : " + target_url)
print("target_login : " + target_login)
print("target_password : " + target_password)
print("project_id : " + project_id)
source = JiraClient(source_url, source_login, source_password)
target = Connection(target_url, target_login, target_password)
#
# target.createProjectDetailed(project_id, project_id, "", target_login)
#
# for i in range(0, 5500):
# try:
# jira_issues = source.get_issues(project_id, i * 10, (i + 1) * 10)
# target.importIssues(project_id, project_id + " assignees",
# [create_yt_issue_from_jira_issue(target, issue, project_id) for issue in
# jira_issues])
# for issue in jira_issues:
# process_labels(target, issue)
# process_attachments(source, target, issue)
# except BaseException, e:
# print(str(e))
for i in range(0, 5500):
jira_issues = source.get_issues(project_id, i * 50, (i + 1) * 50)
links = []
for issue in jira_issues:
process_links(target, issue, links)
print(target.importLinks(links))
示例2: main
def main(argv):
project_name = ''
project_id = ''
project_desc = ''
project_usr = 'root'
project_pwd = 'Sarasa12'
svn_cli = pysvn.Client()
svn_working_path = '/tmp'
youtrack_url = 'http://localhost:80'
try:
opts, args = getopt.getopt(argv,"hp:i:d:",["project_name=","project_id=", "project_desc="])
except getopt.GetoptError:
print 'test.py -p <project_name> -i <project_id> -d <project_desc>'
sys.exit(2)
for opt, arg in opts:
if opt == '-h':
print 'test.py -p <project_name> -i <project_id> -d <project_desc>'
sys.exit()
elif opt in ("-p", "--project_name"):
project_name = arg
elif opt in ("-i", "--project_id"):
project_id = arg
elif opt in ("-d", "--project_desc"):
project_desc = arg
#yt = Connection('http://v-rot-mne-nogi.myjetbrains.com/youtrack', 'root', 'root')
#, proxy_info = httplib2.ProxyInfo(socks.PROXY_TYPE_HTTP, 'localhost', 8888))
yt = Connection(youtrack_url, project_usr, project_pwd)
#def createProjectDetailed(self, projectId, name, description, projectLeadLogin, startingNumber=1)
print yt.createProjectDetailed(project_id, project_name, project_desc, project_usr, 1)
示例3: jira2youtrack
def jira2youtrack(source_url, source_login, source_password,
target_url, target_login, target_password,
projects, flags, field_mappings, value_mappings):
print 'source_url : ' + source_url
print 'source_login : ' + source_login
print 'target_url : ' + target_url
print 'target_login : ' + target_login
source = JiraClient(source_url, source_login, source_password)
target = Connection(target_url, target_login, target_password)
issue_links = []
chunk_size = 10
for project in projects:
project_id, start, end = project
try:
target.createProjectDetailed(project_id, project_id, '', target_login)
except YouTrackException:
pass
while True:
_end = start + chunk_size - 1
if end and _end > end:
_end = end
if start > _end:
break
print 'Processing issues: %s [%d .. %d]' % (project_id, start, _end)
try:
jira_issues = source.get_issues(project_id, start, _end)
start += chunk_size
if not (jira_issues or end):
break
# Filter out moved issues
jira_issues = [issue for issue in jira_issues
if issue['key'].startswith('%s-' % project_id)]
if flags & FI_ISSUES:
issues2import = []
for issue in jira_issues:
issues2import.append(
to_yt_issue(target, issue, project_id,
field_mappings, value_mappings))
if not issues2import:
continue
target.importIssues(
project_id, '%s assignees' % project_id, issues2import)
except YouTrackException, e:
print e
continue
for issue in jira_issues:
if flags & FI_LINKS:
process_links(target, issue, issue_links)
if flags & FI_LABELS:
process_labels(target, issue)
if flags & FI_ATTACHMENTS:
process_attachments(source, target, issue,
flags & FI_REPLACE_ATTACHMENTS > 0)
if flags & FI_WORK_LOG:
process_worklog(source, target, issue)
示例4: agilezen2youtrack
def agilezen2youtrack(source_url, source_token, target_url, target_login, target_password, project_names_to_import):
source = Client(source_url, source_token)
target = Connection(target_url, target_login, target_password)
last_page = False
current_page = 1
try:
target.createCustomFieldDetailed("State", "state[1]", False, True, True, {"attachBundlePolicy": "2"})
except YouTrackException, e:
print str(e)
示例5: submit
def submit(self):
try:
connection = Connection(settings.YOUTRACK_URL, settings.YOUTRACK_LOGIN, settings.YOUTRACK_PASSWORD)
response, content = connection.createIssue(self.project, assignee=None,
summary=u'Issue from feedback form',
description=self.cleaned_data['description'])
print response
issue_id = response['location'].split('/')[-1]
connection.executeCommand(issue_id, 'Customer email ' + self.cleaned_data['email'])
return True
except YouTrackException:
return False
示例6: add_tags
def add_tags(tag_file,target_url, target_login, target_password):
"""
Add tags from the tag file (run after known creation)
:param tag_file:
:return:
"""
target = Connection(target_url, target_login, target_password)
with open(tag_file) as tag_o_file:
reader = csv.reader(tag_o_file)
for row in reader:
issue = row[0]
for t in row[1:]:
print "executing tag for %s" %(issue)
target.executeCommand(issue, "tag %s" % (t))
示例7: process_commits
def process_commits(secret=None):
if context_secret and secret != context_secret:
abort(403)
yt = Connection(yt_url, yt_login, yt_password)
try:
cmd_pattern = re.compile(
r'#((?:%s)-\d+)(?:\s+(.+))?' % '|'.join(yt.getProjects().keys()),
re.IGNORECASE | re.MULTILINE)
except YouTrackException:
app.logger.warning('Cannot get projects from YT')
cmd_pattern = re.compile(r'#([A-z]+-\d+)(?:\s+(.+))?', re.MULTILINE)
payload = json.loads(request.form.get('payload'))
commits_url_template = get_commits_url_template(payload)
for commit in payload['commits']:
message = commit['message'].encode('utf-8')
issue_refs = cmd_pattern.findall(message)
if not issue_refs:
continue
commit_node = commit['node']
commit_url = commits_url_template % commit['raw_node']
timestamp = commit['utctimestamp']
author = commit['author'].encode('utf-8')
match = re.search(r'<(.+?)>', commit['raw_author'])
if not match:
app.logger.error("Cannot get author's email address.")
abort(400)
users = yt.getUsers(params={'q': match.group(1)})
if not users:
app.logger.error('Cannot find user with email ' + match.group(1))
abort(400)
if len(users) != 1:
app.logger.error('Not unique email address ' + match.group(1))
abort(400)
comment = "Commit [%s %s] made by '''%s''' on ''%s''\n{quote}%s{quote}" \
% (commit_url, commit_node, author, timestamp, message)
cmd_exec_result = True
for issue_id, command in issue_refs:
if command is None:
command = ''
try:
app.logger.info("Adding commit %s to issue %s (command: %s)" %
(commit_node, issue_id, command))
yt.executeCommand(issue_id, command, comment, run_as=users[0].login)
except YouTrackException as e:
cmd_exec_result = False
app.logger.error('Failed to add commit %s to issue %s: %s' %
(commit_node, issue_id, e.message))
if not cmd_exec_result:
abort(500)
return 'success'
示例8: submit
def submit(self):
try:
connection = Connection(settings.YOUTRACK_URL, settings.YOUTRACK_LOGIN, settings.YOUTRACK_PASSWORD)
response, content = connection.createIssue(self.project, assignee=None,
summary=self.get_summary().encode('utf-8'),
description=self.cleaned_data['description'].encode('utf-8'))
issue_id = response['location'].split('/')[-1]
commands = ''
if self.subsystem is not None:
commands += ' Subsystem %s' % self.subsystem
commands += ' Customer email ' + self.cleaned_data['email']
connection.executeCommand(issue_id, commands)
return True
except YouTrackException:
return False
示例9: main
def main():
target_url, target_login, target_password, issue_source = sys.argv[1:5]
target = Connection(target_url, target_login, target_password)
if os.path.exists(issue_source): #"treat as a file of issues to delete"
issues = open(issue_source).readlines()
else:
issues = []
issues.append(issue_source)
for issue in issues:
if str(issue).strip() == "": continue
print "deleting %s" % (issue,)
try:
result = target._req("DELETE", "/issue/%s" % (str(issue).strip(),))
print result
except Exception as e:
print e
示例10: youtrack2youtrack
def youtrack2youtrack(source_url, source_login, source_password, target_url, target_login, target_password,
project_ids, query = ''):
if not len(project_ids):
print "You should sign at least one project to import"
return
source = Connection(source_url, source_login, source_password)
target = Connection(target_url, target_login,
target_password) #, proxy_info = httplib2.ProxyInfo(socks.PROXY_TYPE_HTTP, 'localhost', 8888)
print "Import issue link types"
for ilt in source.getIssueLinkTypes():
try:
print target.createIssueLinkType(ilt)
except youtrack.YouTrackException, e:
print e.message
示例11: jira2youtrack
def jira2youtrack(source_url, source_login, source_password, target_url, target_login, target_password, project_id,
issues_count, skip_count):
print("source_url : " + source_url)
print("source_login : " + source_login)
print("target_url : " + target_url)
print("target_login : " + target_login)
print("project_id : " + project_id)
print("issues_count : ", issues_count)
print("skip_count : ", skip_count)
first_chunk = skip_count / 10
last_chunk = issues_count / 10
if issues_count % 10:
last_chunk += 1
source = JiraClient(source_url, source_login, source_password)
target = Connection(target_url, target_login, target_password)
try:
target.createProjectDetailed(project_id, project_id, "", target_login)
except YouTrackException:
pass
for i in range(first_chunk, last_chunk):
start = i * 10 + 1
end = (i + 1) * 10 + 1
if start <= skip_count: start = skip_count + 1
if end > issues_count + 1: end = issues_count + 1
try:
jira_issues = source.get_issues(project_id, start, end)
target.importIssues(project_id, project_id + " assignees",
[create_yt_issue_from_jira_issue(target, issue, project_id) for issue in
jira_issues])
for issue in jira_issues:
try:
process_labels(target, issue)
except YouTrackException, e:
print e
try:
process_attachments(source, target, issue)
except YouTrackException, e:
print e
try:
process_worklog(source, target, issue)
except YouTrackException, e:
print e
示例12: googlecode2youtrack
def googlecode2youtrack(project_name, source_login, source_password, target_url, target_login, target_password,
project_id):
target = Connection(target_url, target_login, target_password)
try:
target.getProject(project_id)
except YouTrackException:
target.createProjectDetailed(project_id, project_name, "", target_login)
for field_name, field_type in googleCode.FIELD_TYPES.items():
create_and_attach_custom_field(target, project_id, field_name, field_type)
start = 1
max = 30
while True:
source = gdata.projecthosting.client.ProjectHostingClient()
source.client_login(source_login, source_password, source="youtrack", service="code")
print "Get issues from " + str(start) + " to " + str(start + max)
query = gdata.projecthosting.client.Query(start_index=start, max_results=max)
issues = source.get_issues(project_name, query=query).entry
start += max
if len(issues) <= 0:
break
target.importIssues(project_id, project_name + " assignees",
[to_yt_issue(target, project_id, issue, source.get_comments(project_name, issue_id(issue)).entry) for issue
in issues])
for issue in issues:
import_tags(target, project_id, issue)
import_attachments(target, project_id, project_name, issue, target_login)
示例13: main
def main(args):
""" Add / Update / Remove items from the specified bundle
"""
enum_dest = EnumValueDest
cnx = Connection(args.youtrack, args.yusername, args.ypassword)
enum_bundle = cnx.getEnumBundle(args.bundle)
list_items = {}
for i in enum_bundle.values:
list_items[v.element_name] = v.description
enum_src = EnumValueSrc(args)
for name, desc_data in enum_src.get_src_values():
desc = build_desc(args.desc, desc_data)
if name in list_items.keys():
if not (desc == list_items[name]):
pass
pass
else:
print("%s: %s" % (name, str(desc_data)))
示例14: import_attachments_only
def import_attachments_only(source_url, source_login, source_password,
target_url, target_login, target_password,
project_ids):
if not project_ids:
print 'No projects to import. Exit...'
return
start = 0
max = 20
source = Connection(source_url, source_login, source_password)
target = Connection(target_url, target_login, target_password)
user_importer = UserImporter(source, target, caching_users=True)
for projectId in project_ids:
while True:
try:
print 'Get issues from %d to %d' % (start, start + max)
issues = source.getIssues(projectId, '', start, max)
if len(issues) <= 0:
break
for issue in issues:
print 'Process attachments for issue %s' % issue.id
attachments = issue.getAttachments()
users = set([])
for a in attachments:
author = a.getAuthor()
if author is not None:
users.add(author)
user_importer.importUsersRecursively(users)
for a in attachments:
print 'Transfer attachment of %s: %s' % (issue.id, a.name.encode('utf-8'))
try:
target.createAttachmentFromAttachment(issue.id, a)
except BaseException, e:
print 'Cannot import attachment [ %s ]' % a.name.encode('utf-8')
print repr(e)
except Exception, e:
print 'Cannot process issues from %d to %d' % (start, start + max)
traceback.print_exc()
raise e
start += max
示例15: receive_hook
def receive_hook():
payload = request.json
user_name = payload['user_name']
repo_url = payload['repository']['url']
app.logger.debug('Received payload for a push by %s on repository %s', user_name, repo_url)
for commit in payload['commits']:
app.logger.debug('Processing commit %s by %s (%s) in %s', commit['id'], commit['author']['name'], commit['author']['email'], commit['url'])
commit_time = dateutil.parser.parse(commit['timestamp'])
refs = re.findall(app.config['REGEX'], commit['message'], re.MULTILINE)
if not refs:
app.logger.info('''Didn't find any referenced issues in commit %s''', commit['id'])
else:
app.logger.info('Found %d referenced issues in commit %s', len(refs), commit['id'])
yt = Connection(app.config['YOUTRACK_URL'], app.config['YOUTRACK_USERNAME'], app.config['YOUTRACK_PASSWORD'])
user = app.config['DEFAULT_USER']
users = yt.getUsers({ 'q': commit['author']['email'] })
if not users:
app.logger.warn('''Couldn't find user with email address %s. Using default user.''', commit['author']['email'])
elif len(users) > 1:
app.logger.warn('''Found more than one user with email address %s. Using default user.''', commit['author']['email'])
else:
user = users[0]['login']
for ref in refs:
app.logger.info('Processing reference to issue %s', ref)
try:
issue = yt.getIssue(ref)
comment_string = 'Commit [%(url)s %(id)s] made by %(author)s on %(date)s\n{quote}%(message)s{quote}' % {'url': commit['url'], 'id': commit['id'], 'author': commit['author']['name'], 'date': str(commit_time), 'message': commit['message']}
app.logger.debug(comment_string)
yt.executeCommand(issueId=ref, command='comment', comment=comment_string, run_as=user)
except YouTrackException:
app.logger.warn('''Couldn't find issue %s''', ref)
return Response('Payload processed. Thanks!', mimetype='text/plain')