diff --git a/CHANGES.rst b/CHANGES.rst index b9194c0..88e6115 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ Changelog 1.3 (unreleased) ---------------- +- Python 3 compatibility [ksuess] - Fix ComponentLookupError (permission problem) on script launch : #16 [laulaz] diff --git a/README.rst b/README.rst index 917e07f..d9c99a1 100644 --- a/README.rst +++ b/README.rst @@ -69,7 +69,7 @@ If you aren't using buildout you can will need to tell the runner which packages migrate --zcml=transmogrify.sqlalchemy,transmogrify.other -If you the blueprint package includes the following entry_point you can skip the zcml settings above :: +If the blueprint package includes the following entry_point you can skip the zcml settings above :: entry-points = {"z3c.autoinclude.plugin":['target = transmogrify']} @@ -134,12 +134,12 @@ The configuration options can either be given as part of the buildout part e.g. or the same option can be overridden via the command line :: - $> bin/migrate --crawler:url=http://www.whitehouse.gov + $> bin/migrate crawler:url=http://www.whitehouse.gov some options require multiple lines within a buildout part. These can be overridden via the commandline by repeating the same argument e.g. :: - $> bin/migrate --crawler:ignore=\.mp3 --crawler:ignore=\.pdf + $> bin/migrate crawler:ignore=\.mp3 crawler:ignore=\.pdf You use the commandline help to view the list of available options :: diff --git a/bootstrap.py b/bootstrap.py index a459921..689ef69 100644 --- a/bootstrap.py +++ b/bootstrap.py @@ -73,7 +73,7 @@ options, args = parser.parse_args() if options.version: - print("bootstrap.py version %s" % __version__) + print("bootstrap.py version {}".format(__version__)) sys.exit(0) @@ -83,7 +83,7 @@ try: from urllib.request import urlopen except ImportError: - from urllib2 import urlopen + from six.moves.urllib.request import urlopen ez = {} if os.path.exists('ez_setup.py'): diff --git a/mr/migrator/browser/helper.py b/mr/migrator/browser/helper.py index 7d9846b..d133295 100644 --- a/mr/migrator/browser/helper.py +++ b/mr/migrator/browser/helper.py @@ -21,7 +21,8 @@ from zope.schema import TextLine from zope.schema.vocabulary import SimpleVocabulary -import urllib +import six.moves.urllib.request, six.moves.urllib.parse, six.moves.urllib.error +import six groupforms = {} @@ -32,8 +33,10 @@ def formfactory(configname): return groupforms[configname] groups = [] config = _load_config(configname) + logger.info('config') + import pprint; pprint.pprint(config) sections = config['transmogrifier']['pipeline'].splitlines() - print sections + print("sections", sections) for section_id in sections: if not section_id: continue @@ -50,7 +53,7 @@ def formfactory(configname): if key.startswith('@'): key = key[1:] metavar, _, help = value.partition(':') - default = unicode(cparser.get(key, '')) + default = six.text_type(cparser.get(key, '')) help = value else: if '@' + key in cparser: @@ -58,7 +61,7 @@ def formfactory(configname): continue else: metavar = 'LINE' - default = unicode(value) + default = six.text_type(value) help = '' title = key.capitalize().replace('-', ' ').replace('_', ' ') # name = "%s:%s"%(section_id,key[1:]) @@ -87,11 +90,11 @@ def formfactory(configname): else: ftype = TextLine() ftype.__name__ = "%s-%s" % (section_id, key.replace('-', '_')) - ftype.title = unicode(title) - ftype.description = unicode(help) + ftype.title = six.text_type(title) + ftype.description = six.text_type(help) ftype.required = False ftype.default = default - print (key, value, ftype, default) + print(key, value, ftype, default) fields.append(ftype) if fields: g.fields = field.Fields(*fields) @@ -187,7 +190,7 @@ def handleSelect(self, action): return False self.request.RESPONSE.redirect( '%s/@@mr.migrator-run?form.widgets.%s' % - (self.context.absolute_url(), urllib.urlencode(data))) + (self.context.absolute_url(), six.moves.urllib.parse.urlencode(data))) MigratorConfigurationsFactory = MigratorConfigurations() diff --git a/mr/migrator/configure.zcml b/mr/migrator/configure.zcml index 163362b..c7c26ba 100644 --- a/mr/migrator/configure.zcml +++ b/mr/migrator/configure.zcml @@ -8,6 +8,7 @@ + diff --git a/mr/migrator/profiles/default/actions.xml b/mr/migrator/profiles/default/actions.xml index b5caefc..e3ecb1e 100644 --- a/mr/migrator/profiles/default/actions.xml +++ b/mr/migrator/profiles/default/actions.xml @@ -1,14 +1,14 @@ - + Import string: ${object_url}/@@mr.migrator - + True diff --git a/mr/migrator/runner/__init__.py b/mr/migrator/runner/__init__.py index 38718e6..9d35f1c 100644 --- a/mr/migrator/runner/__init__.py +++ b/mr/migrator/runner/__init__.py @@ -15,7 +15,7 @@ try: import configparser except ImportError: - import ConfigParser as configparser + import six.moves.configparser as configparser try: from Zope2.App.zcml import load_config except: @@ -38,10 +38,10 @@ def error(self): def runner(args={}, pipeline=None): - parser = OptionParser() + parser = OptionParser("usage: %prog [options]") parser.add_option("--pipeline", dest="pipeline", - help="Transmogrifier pipeline.cfg to use", + help="Transmogrifier pipeline to use. default: pipeline.cfg", metavar="FILE") parser.add_option("--show-pipeline", dest="showpipeline", action="store_true", @@ -50,13 +50,15 @@ def runner(args={}, pipeline=None): action="store", help="modules in the path to load zcml from") # Parse just the pipeline args - ispipeline = lambda arg: [ - a for a in [ - '--pipeline', - '--show-pipeline', - '--zcml'] if arg.startswith(a)] - pargs = [arg for arg in sys.argv[1:] if ispipeline(arg)] - (options, cargs) = parser.parse_args(pargs) + # ispipeline = lambda arg: [ + # a for a in [ + # '--pipeline', + # '--show-pipeline', + # '--zcml', + # '--help'] if arg.startswith(a)] + # pargs = [arg for arg in sys.argv[1:] if ispipeline(arg)] + # (options, cargs) = parser.parse_args(pargs) + (options, cargs) = parser.parse_args() if options.pipeline is not None: config = options.pipeline elif pipeline is not None: