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

Python 3: modernize run and changes made manually #21

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
1.3 (unreleased)
----------------

- Python 3 compatibility [ksuess]
- Fix ComponentLookupError (permission problem) on script launch : #16
[laulaz]

Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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']}

Expand Down Expand Up @@ -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 ::
Expand Down
4 changes: 2 additions & 2 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand All @@ -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'):
Expand Down
19 changes: 11 additions & 8 deletions mr/migrator/browser/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand All @@ -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
Expand All @@ -50,15 +53,15 @@ 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:
# let the @option line be used instead
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:])
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions mr/migrator/configure.zcml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
<include package="Products.CMFCore" file="permissions.zcml" />
<include package="collective.transmogrifier" file="meta.zcml" />

<include package=".browser" />
<i18n:registerTranslations directory="locales" />

<!-- BBB -->
Expand Down
4 changes: 2 additions & 2 deletions mr/migrator/profiles/default/actions.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0"?>
<object name="portal_actions" meta_type="Plone Actions Tool"
xmlns:i18n="http://xml.zope.org/namespaces/i18n">
<object name="folder_buttons" meta_type="CMF Action Category">
<object name="object" meta_type="CMF Action Category">
<object name="import" meta_type="CMF Action" i18n:domain="mr.migrator">
<property name="title" i18n:translate="">Import</property>
<property name="description" i18n:translate=""></property>
<property name="url_expr">string: ${object_url}/@@mr.migrator</property>
<property name="icon_expr"></property>
<property name="permissions">
<element value="mr.migrator: Import to folder" />
<element value="Manage portal" />
</property>
<property name="visible">True</property>
</object>
Expand Down
22 changes: 12 additions & 10 deletions mr/migrator/runner/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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",
Expand All @@ -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:
Expand Down