Skip to content

Commit

Permalink
More Python 2 / 3 compatibility changes
Browse files Browse the repository at this point in the history
  • Loading branch information
davilima6 committed Jan 30, 2018
1 parent 0b0a230 commit 7bab66e
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 52 deletions.
8 changes: 4 additions & 4 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ Breaking changes:

New features:

- *add item here*
- Imports are Python3 compatible. Add six into install_requires set and sort
each file's imports with the isort package.
[b4oshany]

Bug fixes:

- Imports are Python3 compatible.
Adds six into install_requires set and sorts each file's imports with the isort package.
[b4oshany]
- *add item here*


1.1.2 (2018-01-30)
Expand Down
2 changes: 1 addition & 1 deletion src/plone/app/robotframework/autologin.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def set_autologin_username(self, username):
raise Exception(u"Autologin is not enabled")
if len(self.acl_users.robot_login._domain_map) == 0:
raise Exception(u"Autologin is not enabled")
domain_map_key = self.acl_users.robot_login._domain_map.keys()[0]
domain_map_key = list(self.acl_users.robot_login._domain_map.keys())[0]
domain_map = self.acl_users.robot_login._domain_map[domain_map_key]
domain_map[0]['username'] = username
self.acl_users.robot_login._domain_map[domain_map_key] = domain_map
Expand Down
36 changes: 18 additions & 18 deletions src/plone/app/robotframework/reload.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def start(self):
registerHandler(signal.SIGTERM, self._exitHandler)

for path in self.paths:
print WAIT("Watchdog is watching for changes in %s" % path)
print(WAIT("Watchdog is watching for changes in %s" % path))
observer = Observer()
self.observers.append(observer)
observer.schedule(self, path=path, recursive=True)
Expand All @@ -62,16 +62,16 @@ def on_any_event(self, event):
break

if self.last_event + self.minimum_wait < time.time():
print WAIT("Watchdog got %s event on %s"
% (event_type, event_relpath))
print(WAIT("Watchdog got %s event on %s"
% (event_type, event_relpath)))
try:
self.forkloop.forkNewChild()
self.last_event = time.time()
except Exception as e:
print ERROR(str(e))
print(ERROR(str(e)))
else:
print WAIT("Watchdog skipped %s event on %s"
% (event_type, event_relpath))
print(WAIT("Watchdog skipped %s event on %s"
% (event_type, event_relpath)))


class ForkLoop(object):
Expand Down Expand Up @@ -132,7 +132,7 @@ def loop(self):

self.active = True

print WAIT("Fork loop now starting on parent process %i" % os.getpid())
print(WAIT("Fork loop now starting on parent process %i" % os.getpid()))
while True:
self.forking = False

Expand All @@ -147,12 +147,12 @@ def loop(self):
continue

if not self.killed_child:
print ERROR(
print(ERROR(
"Forked child process died on bootup. "
"Fix possible errors and save edits. "
"We are now paused until we detect the next file "
"change..."
)
))

# Child died because of unknown reason. Mark it as killed
# and go into pause mode.
Expand All @@ -175,7 +175,7 @@ def loop(self):

self.forking = False

print WAIT("Fork loop forked a new child process %i" % (os.getpid()))
print(WAIT("Fork loop forked a new child process %i" % (os.getpid())))

def forkNewChild(self):
"""STEP 1 (parent): New child process forking starts by killing the
Expand All @@ -201,7 +201,7 @@ def forkNewChild(self):
else:
# Ok, we already have sent the SIGINT the child, but asking for new
# child
print WAIT("Fork loop scheduling a new fork")
print(WAIT("Fork loop scheduling a new fork"))
self._scheduleFork()

self.killed_child = True
Expand All @@ -226,8 +226,8 @@ def _parentExitHandler(self, signum=None, frame=None):

while self.isChildAlive():
# XXX: Somehow this may get stuck if we don't print before kill
print WAIT("Fork loop is terminating its child process %s" %
self.child_pid)
print(WAIT("Fork loop is terminating its child process %s" %
self.child_pid))
self._killChild()
time.sleep(2)

Expand Down Expand Up @@ -259,14 +259,14 @@ def _waitChildToDieAndScheduleNew(self, signal=None, frame=None):
exit_flags.append("exited with code %d" % code)

if exit_status == 0:
print WAIT("Fork loop terminated child process %d" % pid)
print(WAIT("Fork loop terminated child process %d" % pid))

elif exit_flags:
print ERROR("Forked child process %d %s"
% (pid, ", ".join(exit_flags)))
print(ERROR("Forked child process %d %s"
% (pid, ", ".join(exit_flags))))
else:
print ERROR("Forked child process %d exited with code %s"
% (pid, exit_status))
print(ERROR("Forked child process %d exited with code %s"
% (pid, exit_status)))

except OSError:
# OSError: [Errno 10] No child processes
Expand Down
2 changes: 1 addition & 1 deletion src/plone/app/robotframework/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def run_keyword(self, name, args, kwargs={}):
result = {'error': '', 'return': ''}
try:
retval = func(*args, **kwargs)
except Exception, e:
except Exception as e:
result['status'] = 'FAIL'
result['error'] = str(e)
else:
Expand Down
8 changes: 4 additions & 4 deletions src/plone/app/robotframework/robotentrypoints.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import sys

from __future__ import print_function
from robot import run_cli
from robot import libdoc as ld

import pkg_resources
import sys

try:
pkg_resources.get_distribution('robotframework-ride')
Expand Down Expand Up @@ -47,7 +47,7 @@ def ride():
from robotide import main
main(*sys.argv[1:])
else:
print u"""\
print(u"""\
Package robotframework-ride was not found. Please, install
plone.app.robotframework with proper extras, like:
Expand All @@ -61,7 +61,7 @@ def ride():
wxPython installed, like:
/usr/bin/python bin/ride
"""
""")


def libdoc():
Expand Down
49 changes: 25 additions & 24 deletions src/plone/app/robotframework/server.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from __future__ import print_function
from plone.app.robotframework.remote import RemoteLibrary
from six.moves.xmlrpc_client import ServerProxy
from six.moves.xmlrpc_server import SimpleXMLRPCServer
Expand Down Expand Up @@ -37,12 +38,12 @@

def start(zope_layer_dotted_name):

print WAIT("Starting Zope 2 server")
print(WAIT("Starting Zope 2 server"))

zsl = Zope2Server()
zsl.start_zope_server(zope_layer_dotted_name)

print READY("Started Zope 2 server")
print(READY("Started Zope 2 server"))

listener = SimpleXMLRPCServer((LISTENER_HOST, LISTENER_PORT),
logRequests=False)
Expand All @@ -53,19 +54,19 @@ def start(zope_layer_dotted_name):
try:
listener.serve_forever()
finally:
print
print WAIT("Stopping Zope 2 server")
print()
print(WAIT("Stopping Zope 2 server"))

zsl.stop_zope_server()

print READY("Zope 2 server stopped")
print(READY("Zope 2 server stopped"))


def start_reload(zope_layer_dotted_name, reload_paths=('src',),
preload_layer_dotted_name='plone.app.testing.PLONE_FIXTURE',
extensions=None):

print WAIT("Starting Zope 2 server")
print(WAIT("Starting Zope 2 server"))

zsl = Zope2Server()
zsl.start_zope_server(preload_layer_dotted_name)
Expand All @@ -80,9 +81,9 @@ def start_reload(zope_layer_dotted_name, reload_paths=('src',),
forkloop.start()

if forkloop.exit:
print WAIT("Stopping Zope 2 server")
print(WAIT("Stopping Zope 2 server"))
zsl.stop_zope_server()
print READY("Zope 2 server stopped")
print(READY("Zope 2 server stopped"))
return

# XXX: For unknown reason call to socket.gethostbyaddr may cause malloc
Expand Down Expand Up @@ -110,14 +111,14 @@ def start_reload(zope_layer_dotted_name, reload_paths=('src',),
if 'Darwin' in platform.uname():
socket.gethostbyaddr = gethostbyaddr

print READY("Zope 2 server started")
print(READY("Zope 2 server started"))

try:
listener = SimpleXMLRPCServer((LISTENER_HOST, LISTENER_PORT),
logRequests=False)
except socket.error as e:
print ERROR(str(e))
print WAIT("Pruning Zope 2 server")
print(ERROR(str(e)))
print(WAIT("Pruning Zope 2 server"))
zsl.prune_zope_server()
return

Expand All @@ -132,7 +133,7 @@ def start_reload(zope_layer_dotted_name, reload_paths=('src',),
except select.error: # Interrupted system call
pass
finally:
print WAIT("Pruning Zope 2 server")
print(WAIT("Pruning Zope 2 server"))
zsl.prune_zope_server()


Expand Down Expand Up @@ -278,11 +279,11 @@ def zodb_setup(self, layer_dotted_name=None):
for layer in layers:
if hasattr(layer, 'testSetUp'):
if HAS_VERBOSE_CONSOLE:
print WAIT("Test set up {0}.{1}".format(
layer.__module__, layer.__name__))
print(WAIT("Test set up {0}.{1}".format(
layer.__module__, layer.__name__)))
layer.testSetUp()
if HAS_VERBOSE_CONSOLE:
print READY("Test set up")
print(READY("Test set up"))

def zodb_teardown(self, layer_dotted_name=None):
if layer_dotted_name:
Expand All @@ -294,11 +295,11 @@ def zodb_teardown(self, layer_dotted_name=None):
for layer in layers:
if hasattr(layer, 'testTearDown'):
if HAS_VERBOSE_CONSOLE:
print WAIT("Test tear down {0}.{1}".format(
layer.__module__, layer.__name__))
print(WAIT("Test tear down {0}.{1}".format(
layer.__module__, layer.__name__)))
layer.testTearDown()
if HAS_VERBOSE_CONSOLE:
print READY("Test torn down")
print(READY("Test torn down"))


setup_layers = {}
Expand All @@ -313,11 +314,11 @@ def setup_layer(layer, setup_layers=setup_layers):
if hasattr(layer, 'setUp'):
name = "{0}.{1}".format(layer.__module__, layer.__name__)
if HAS_VERBOSE_CONSOLE and name == 'plone.testing.z2.Startup':
print WAIT("Set up {0}.{1} (debug-mode={2})".format(
layer.__module__, layer.__name__, HAS_DEBUG_MODE))
print(WAIT("Set up {0}.{1} (debug-mode={2})".format(
layer.__module__, layer.__name__, HAS_DEBUG_MODE)))
elif HAS_VERBOSE_CONSOLE:
print WAIT("Set up {0}.{1}".format(layer.__module__,
layer.__name__))
print(WAIT("Set up {0}.{1}".format(layer.__module__,
layer.__name__)))
layer.setUp()
if HAS_DEBUG_MODE and name == 'plone.testing.z2.Startup':
import App.config
Expand All @@ -339,8 +340,8 @@ def tear_down(setup_layers=setup_layers):
try:
if hasattr(l, 'tearDown'):
if HAS_VERBOSE_CONSOLE:
print WAIT("Tear down {0}.{1}".format(l.__module__,
l.__name__))
print(WAIT("Tear down {0}.{1}".format(l.__module__,
l.__name__)))
l.tearDown()
except NotImplementedError:
pass
Expand Down

0 comments on commit 7bab66e

Please sign in to comment.