Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add requirements.txt, allow wiki-only conversions without github credentials #4

Merged
merged 5 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Migrating a Trac project to GitHub is a relatively complex process involving fou
* Migrate issues and milestones
* Migrate wiki pages

This script takes care of the third bullet point.
This script takes care of the third and fourth bullet points.

Usage:

Expand All @@ -53,5 +53,6 @@ LGPL license version 3.0.
Requirements
==============

* Python 2 with xmlrpclib, requests, [PyGithub](https://github.com/PyGithub/PyGithub)
* Python 2 with xmlrpclib or Python 3; requests, [PyGithub](https://github.com/PyGithub/PyGithub),
see ```requirements.txt```
* Trac with [XML-RPC plugin](http://trac-hacks.org/wiki/XmlRpcPlugin) enabled
5 changes: 1 addition & 4 deletions migrate.cfg.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ url: https://example.com/xmlrpc
# optional path to trac instance used to convert some attachments
path: /path/to/trac/instance

# mapping file from git hashes to subversion revisions and branche names ("hash revision @branch" in each line)
# mapping file from git hashes to subversion revisions and branch names ("hash revision @branch" in each line)
svngitmap: /path/to/git_svn.map


Expand All @@ -24,9 +24,6 @@ usernames = {
'trac2': 'git2'
}

# project's path
project_name: foo/bar

# URL of the GitHub web API (default: https://api.github.com)
# url: https://api.github.com

Expand Down
22 changes: 14 additions & 8 deletions migrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,25 +763,31 @@ def convert_wiki(source, dest):
converted += ' * [' + name + '](' + url + ')\n'

# TODO we could use the GitHub API to write into the Wiki repository of the GitHub project
outfile = os.path.join(wiki_export_dir, pagename + '.md')
# For wiki page names with slashes
os.makedirs(os.path.dirname(outfile), exist_ok=True)
try :
open(os.path.join(wiki_export_dir, pagename + '.md'), 'w').write(converted)
open(outfile, 'w').write(converted)
except UnicodeEncodeError as e :
print ('EXCEPTION:', e)
print (' Context:', e.object[e.start-20:e.end+20])
print (' Retrying with UTF-8 encoding')
codecs.open(os.path.join(wiki_export_dir, pagename + '.md'), 'w', 'utf-8').write(converted)
codecs.open(outfile, 'w', 'utf-8').write(converted)


if __name__ == "__main__":
source = client.ServerProxy(trac_url)

dest = None
if github_token is not None :
github = Github(github_token, base_url=github_api_url)
else :
github = Github(github_username, github_password, base_url=github_api_url)
dest = github.get_repo(github_project)
gh_user = github.get_user()
gh_user = None

if must_convert_issues:
if github_token is not None :
github = Github(github_token, base_url=github_api_url)
else :
github = Github(github_username, github_password, base_url=github_api_url)
dest = github.get_repo(github_project)
gh_user = github.get_user()

if dest is not None :
for l in dest.get_labels() :
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pygithub
requests