def import_project(source, target, project):
    log_step("Import project " + project[u'name'])

    import_user(target, project[u'owner'])
    project_id = str(project[u'id'])
    try:
        target.getProject(project_id)
    except YouTrackException, e:
        target.createProjectDetailed(project_id, project[u'name'],
            project[u'description'], project[u'owner'][u'userName'])

    last_page = False
    current_page = 1
    log_step("Import project roles")
    while not last_page:
        roles = source.get_project_roles(project_id, current_page)
        if current_page == roles[u'totalPages']:
            last_page = True
        for role in roles[u'items']:
            import_role(target, project_id, role)
        current_page += 1
    last_page = False
    current_page = 1
    log_step("Import project phases")
    while not last_page:
        phases = source.get_project_phases(project_id, current_page)
        if current_page == phases[u'totalPages']:
            last_page = True
        for phase in phases[u'items']:
            import_phase(target, project_id, phase)
        current_page += 1
    last_page = False
    current_page = 1
    max_story_id = 0
    existing_tags = set()
    log_step("Import stories")
    while not last_page:
        stories = source.get_stories_for_project(project_id, current_page)
        if current_page == stories[u'totalPages']:
            last_page = True
        stories_to_import = []
        items = stories[u'items']
        for story in items:
            story_id = story[u'id']
            yt_issue = to_yt_issue(target, project_id, story)
            if story_id > max_story_id:
                max_story_id = story_id
            stories_to_import.append(yt_issue)
            #            if len(source.get_attachments(project_id, str(story_id))[u'items']):
            #                print 'Attachments found!'
            # here we just collect tags, not actually import them to find tags that are prefixes of other tags
            if u'tags' in story:
                existing_tags |= set([t[u'name'] for t in story[u'tags']])
        target.importIssues(project_id, project_id + " assignees", stories_to_import)
        current_page += 1

    log_step("Import tags")
    import_tags(source, target, project_id, existing_tags)
    #now iterate again through stories to import tasks
    last_page = False
    current_page = 1
    log_step("Import tasks")
    while not last_page:
        stories = source.get_stories_for_project(project_id, current_page)
        if current_page == stories[u'totalPages']:
            last_page = True
        for story in stories[u'items']:
            tasks = [to_yt_sub_task(target, project_id, story, task) for task in
                     story['tasks']] if u'tasks' in story else []
            if len(tasks):
                for task in tasks:
                    max_story_id += 1
                    task.numberInProject = str(max_story_id)
                result = target.importIssues(project_id, project_id + " assignees", tasks)
                items = minidom.parseString(result).getElementsByTagName("item")
                issue_links_to_import = []
                for item in items:
                    link = Link()
                    link.typeName = "Subtask"
                    link.target = "%s-%s" % (project_id, item.attributes['id'].value)
                    link.source = "%s-%d" % (project_id, story[u'id'])
                    issue_links_to_import.append(link)
                target.importLinks(issue_links_to_import)
        current_page += 1


#        for parent_id, tasks in tasks_to_import:
#            import_result = target.importIssues(project_id, project_id + " assignees", tasks)
#
dataset/ETHPy150Open JetBrains/youtrack-rest-python-library/python/agilezen2youtrack.py/import_project/original