Python3.x - ify

This commit is contained in:
Daniel Lenski 2020-12-21 14:53:21 -08:00
parent fa546f7b6a
commit 64da0d6b3e
2 changed files with 26 additions and 20 deletions

View File

@ -1,7 +1,13 @@
#!/usr/bin/env python #!/usr/bin/env python3
from __future__ import print_function
import sys, os, re, subprocess as sp import sys, os, re, subprocess as sp
from distutils.core import setup
try:
from setuptools import setup
except ImportError:
from distutils.core import setup
if sys.version_info < (3,):
sys.exit("Python 2.x is not supported; Python 3.x is required.")
######################################## ########################################

View File

@ -1,11 +1,9 @@
#!/usr/bin/env python2 #!/usr/bin/env python3
from __future__ import print_function
from sys import stderr, stdout, platform from sys import stderr, stdout, platform
import argparse import argparse
import mwclient import mwclient
import subprocess as sp import subprocess as sp
import urlparse import urllib.parse as urlparse
import os, locale, time import os, locale, time
from .version import __version__ from .version import __version__
@ -67,7 +65,7 @@ def main():
print('Connected to %s://%s%s' % (scheme, host, path), file=stderr) print('Connected to %s://%s%s' % (scheme, host, path), file=stderr)
# Find the page # Find the page
page = site.pages[args.article_name.decode(locale_encoding)] page = site.pages[args.article_name]
if not page.exists: if not page.exists:
p.error('Page %s does not exist' % args.article_name) p.error('Page %s does not exist' % args.article_name)
fn = sanitize(args.article_name) fn = sanitize(args.article_name)
@ -91,14 +89,14 @@ def main():
# Output fast-import data stream to file or git pipe # Output fast-import data stream to file or git pipe
with fid: with fid:
fid.write('reset refs/heads/master\n') fid.write(b'reset refs/heads/master\n')
for rev in page.revisions(dir='newer', prop='ids|timestamp|flags|comment|user|userid|content|tags'): for rev in page.revisions(dir='newer', prop='ids|timestamp|flags|comment|user|userid|content|tags'):
id = rev['revid'] id = rev['revid']
text = rev.get('*','').encode('utf8') text = rev.get('*','')
user = rev.get('user','').encode('utf8') user = rev.get('user','')
user_ = user.replace(' ','_') user_ = user.replace(' ','_')
comment = rev.get('comment','').encode('utf8') or '<blank>' comment = rev.get('comment','') or '<blank>'
tags = (['minor'] if 'minor' in rev else []) + [tag.encode('utf8') for tag in rev['tags']] tags = (['minor'] if 'minor' in rev else []) + rev['tags']
ts = time.mktime(rev['timestamp']) ts = time.mktime(rev['timestamp'])
if rev.get('userid'): if rev.get('userid'):
@ -107,7 +105,7 @@ def main():
committer = '%s <>' % user committer = '%s <>' % user
print((" >> %sRevision %d by %s at %s: %s" % (('Minor ' if 'minor' in rev else ''), id, rev.get('user',''), print((" >> %sRevision %d by %s at %s: %s" % (('Minor ' if 'minor' in rev else ''), id, rev.get('user',''),
time.ctime(ts), rev.get('comment',''))).encode('ascii','xmlcharrefreplace'), file=stderr) time.ctime(ts), comment)), file=stderr)
summary = '{comment}\n\nURL: {scheme}://{host}{path}index.php?oldid={id:d}\nEditor: {scheme}://{host}{path}index.php?title=User:{user_}'.format( summary = '{comment}\n\nURL: {scheme}://{host}{path}index.php?oldid={id:d}\nEditor: {scheme}://{host}{path}index.php?title=User:{user_}'.format(
comment=comment, scheme=scheme, host=host, path=path, id=id, user_=user_) comment=comment, scheme=scheme, host=host, path=path, id=id, user_=user_)
@ -115,12 +113,14 @@ def main():
if tags: if tags:
summary += '\nTags: ' + ', '.join(tags) summary += '\nTags: ' + ', '.join(tags)
fid.write('commit refs/heads/master\n') summary = summary.encode()
fid.write('committer %s %d +0000\n' % (committer, ts)) text = text.encode()
fid.write('data %d\n%s\n' % (len(summary), summary)) fid.write(b'commit refs/heads/master\n')
fid.write('M 644 inline %s.mw\n' % fn) fid.write(b'committer %s %d +0000\n' % (committer.encode(), ts))
fid.write('data %d\n%s\n' % (len(text), text)) fid.write(b'data %d\n%s\n' % (len(summary), summary))
fid.write('done\n') fid.write(b'M 644 inline %s.mw\n' % fn.encode())
fid.write(b'data %d\n%s\n' % (len(text), text))
fid.write(b'done\n')
if args.doimport: if args.doimport:
pipe.communicate() pipe.communicate()