def _import_one_user_with_groups(source, target, login): print 'Starting user importing' user_importer = UserImporter(source, target, caching_users=False) users_to_import = [source.getUser(login)] if _check_login(login): user_importer.importUsersRecursively(users_to_import) print 'User was successfully imported' else: print 'User login ' + str(login) + ' contains prohibited chars'
def _import_all_users(source, target): print 'Starting user importing' user_importer = UserImporter(source, target, caching_users=False) start = 0 imported_number = 0 users_to_import = source.getUsersTen(start) while len(users_to_import): refined_users = [source.getUser(user.login) for user in users_to_import] imported_number += user_importer.importUsersRecursively(refined_users) start += 10 users_to_import = source.getUsersTen(start) if imported_number % 500 == 0: print 'Imported ' + str(imported_number) + ' users' print 'Finished. Total number of imported users: ' + str(imported_number)
def _import_all_users(source, target, import_groups): print 'Starting user importing' user_importer = UserImporter( source, target, caching_users=True, import_groups=import_groups) start = 0 imported_number = 0 users_to_import = source.getUsersTen(start) while len(users_to_import): refined_users = [source.getUser(user.login) for user in users_to_import] imported_number += user_importer.importUsersRecursively(refined_users) start += 10 users_to_import = source.getUsersTen(start) if imported_number % 20 == 0: print 'Imported ' + str(imported_number) + ' users' print 'Finished. Total number of imported users: ' + str(imported_number)
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
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 user_importer = UserImporter(source, target, caching_users=True) link_importer = LinkImporter(target) #create all projects with minimum info and project lead set created_projects = [] for project_id in project_ids: created = create_project_stub(source, target, project_id, user_importer) created_projects.append(created) #save created project ids to create correct group roles afterwards user_importer.addCreatedProjects( [project.id for project in created_projects]) #import project leads with group they are included and roles assigned to these groups user_importer.importUsersRecursively( [target.getUser(project.lead) for project in created_projects])
def import_attachments_only(source_url, source_login, source_password, target_url, target_login, target_password, project_ids, params=None): if not project_ids: print 'No projects to import. Exit...' return if params is None: params = {} 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=params.get('enable_user_caching', 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 existing_attachments = dict() try: for a in target.getAttachments(issue.id): existing_attachments[a.name + '\n' + a.created] = a except youtrack.YouTrackException, e: if e.response.status == 404: print "Skip importing attachments because issue %s doesn't exist" % issue.id continue raise e attachments = [] users = set([]) for a in issue.getAttachments(): if a.name + '\n' + a.created in existing_attachments and not params.get('replace_attachments'): print "Skip attachment '%s' (created: %s) because it's already exists" \ % (a.name.encode('utf-8'), a.created) continue attachments.append(a) 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) continue if params.get('replace_attachments'): try: old_attachment = existing_attachments.get(a.name + '\n' + a.created) if old_attachment: print 'Deleting old attachment' target.deleteAttachment(issue.id, old_attachment.id) except BaseException, e: print "Cannot delete attachment '%s' from issue %s" % (a.name.encode('utf-8'), issue.id) print e
return if params is None: params = {} 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 user_importer = UserImporter(source, target, caching_users=params.get('enable_user_caching', True)) link_importer = LinkImporter(target) #create all projects with minimum info and project lead set created_projects = [] for project_id in project_ids: created = create_project_stub(source, target, project_id, user_importer) created_projects.append(created) #save created project ids to create correct group roles afterwards user_importer.addCreatedProjects([project.id for project in created_projects]) #import project leads with group they are included and roles assigned to these groups user_importer.importUsersRecursively([target.getUser(project.lead) for project in created_projects]) #afterwards in a script any user import imply recursive import cf_names_to_import = set([]) # names of cf prototypes that should be imported
def import_attachments_only(source_url, source_login, source_password, target_url, target_login, target_password, project_ids, params=None): if not project_ids: print 'No projects to import. Exit...' return if params is None: params = {} 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=params.get( 'enable_user_caching', 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 existing_attachments = dict() try: for a in target.getAttachments(issue.id): existing_attachments[a.name + '\n' + a.created] = a except youtrack.YouTrackException, e: if e.response.status == 404: print "Skip importing attachments because issue %s doesn't exist" % issue.id continue raise e attachments = [] users = set([]) for a in issue.getAttachments(): if a.name + '\n' + a.created in existing_attachments and not params.get( 'replace_attachments'): print "Skip attachment '%s' (created: %s) because it's already exists" \ % (a.name.encode('utf-8'), a.created) continue attachments.append(a) 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) continue if params.get('replace_attachments'): try: old_attachment = existing_attachments.get( a.name + '\n' + a.created) if old_attachment: print 'Deleting old attachment' target.deleteAttachment( issue.id, old_attachment.id) except BaseException, e: print "Cannot delete attachment '%s' from issue %s" % ( a.name.encode('utf-8'), issue.id) print e