def perform_migrate_pages(args): redmine = RedmineClient(args.redmine_key, args.no_verify) redmine_project = RedmineProject(args.redmine_project_url, redmine) # Get copy of GitLab wiki repository wiki = WikiPageConverter(args.gitlab_wiki) # convert all pages including history pages = [] for page in redmine_project.get_all_pages(): print("Collecting " + page["title"]) start_version = page["version"] if args.no_history else 1 for version in range(start_version, page["version"] + 1): try: full_page = redmine_project.get_page(page["title"], version) pages.append(full_page) except: log.error("Error when retrieving " + page["title"] + ", version " + str(version)) # sort everything by date and convert pages.sort(key=lambda page: page["updated_on"]) for page in pages: wiki.convert(page)
def perform_migrate_pages(args): redmine = RedmineClient(args.redmine_key, args.no_verify) redmine_project = RedmineProject(args.redmine_project_url, redmine) if args.no_textile: textile_converter = NopConverter() else: textile_converter = TextileConverter() # Get copy of GitLab wiki repository wiki = WikiPageConverter(args.gitlab_wiki, textile_converter) # convert all pages including history pages = [] for page in redmine_project.get_all_pages(): print("Collecting " + page["title"]) start_version = page["version"] if args.no_history else 1 for version in range(start_version, page["version"] + 1): try: for i in range(5): try: full_page = redmine_project.get_page( page["title"], version) break except: sleep(1) else: full_page = redmine_project.get_page( page["title"], version) except Exception as e: log.error("Error when retrieving " + page["title"] + ", version " + str(version)) continue for attachment_key, attachment in enumerate( full_page['attachments']): full_page['attachments'][attachment_key] = wiki_attachment( attachment, args.redmine_key, wiki.repo_path) pages.append(full_page) # sort everything by date and convert pages.sort(key=lambda page: page["updated_on"]) for page in pages: wiki.convert(page)
def perform_migrate_pages(args): redmine = RedmineClient(args.redmine_key) redmine_project = RedmineProject(args.redmine_project_url, redmine) # Get copy of GitLab wiki repository wiki = WikiPageConverter(args.gitlab_wiki) # convert all pages including history pages = [] for page in redmine_project.get_all_pages(): print("Collecting " + page["title"]) start_version = page["version"] if args.no_history else 1 for version in range(start_version, page["version"]+1): try: full_page = redmine_project.get_page(page["title"], version) pages.append(full_page) except: log.error("Error when retrieving " + page["title"] + ", version " + str(version)) # sort everything by date and convert pages.sort(key=lambda page: page["updated_on"]) for page in pages: wiki.convert(page)
def perform_migrate_pages(args): redmine = RedmineClient(args.redmine_key, args.no_verify) redmine_project = RedmineProject(args.redmine_project_url, redmine) # create work dict work = {} for p in redmine_project.get_all_pages(): if 'parent' in p: work[p['title']] = p['parent']['title'] else: work[p['title']] = None # recursive function to parse the child/parent def parseTree(work, next = None): ret = {} for child,parent in work.copy().items(): if parent == next: work.pop(child) ret[child] = parseTree(work, child) if not ret: ret = None return ret wikitree = parseTree(work) # create a path tree def printTree(wikitree, ischild = ''): if wikitree and not len(wikitree) == 0: ret = {} for p,child in wikitree.items(): if p == 'WikiStart': p = 'home' if ischild != '': # create the tree folder structure if not os.path.exists(ischild): os.makedirs(ischild, exist_ok=True) ret[p] = os.path.join(ischild, p) else: ret[p] = p # has child if child and not len(child) == 0: dirpath = os.path.join(ischild, p) ret.update(printTree(child, dirpath)) return ret tree = printTree(wikitree) # create tree index.md file idxcont = "# Index\n\n" for k,e in tree.items(): spaces = '' indent = len(e.split('/')) if indent > 1: spaces = (4 * (indent-1)) * (' ') idxcont += spaces + "* ["+k+"]("+e+")\n" # write tree index file with open(args.gitlab_wiki + "/index.md", "w") as f: f.write(idxcont) # add tree index to git repo repo = Repo(args.gitlab_wiki) repo.index.add(['index.md']) repo.index.commit("add new index file") # convert all pages including history pages = [] for page in redmine_project.get_all_pages(): print("Collecting " + page["title"]) start_version = page["version"] if args.no_history else 1 for version in range(start_version, page["version"]+1): try: full_page = redmine_project.get_page(page["title"], version) if page["title"] == 'WikiStart': full_page['path'] = tree['home'] else: full_page['path'] = tree[page['title']] pages.append(full_page) except: log.error("Error when retrieving " + page["title"] + ", version " + str(version)) # sort everything by date and convert pages.sort(key=lambda page: page["updated_on"]) # Get copy of GitLab wiki repository wiki = WikiPageConverter(args.gitlab_wiki, tree=tree, textformat=args.textformat) for page in pages: wiki.convert(page)