Skip to content
This repository has been archived by the owner on Aug 28, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from zopefoundation/resurrection-python3
Browse files Browse the repository at this point in the history
Resurrection python3
  • Loading branch information
trollfot committed Aug 20, 2020
2 parents 2c91187 + 7f435d3 commit 8eeceba
Show file tree
Hide file tree
Showing 19 changed files with 162 additions and 113 deletions.
4 changes: 3 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
language: python
python:
- 2.6
- 2.7
- 3.5
- 3.6
- 3.7
install:
- python bootstrap.py
- bin/buildout
Expand Down
26 changes: 19 additions & 7 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
Simply run this script in a directory containing a buildout.cfg, using the
Python that you want bin/buildout to use.
Note that by using --find-links to point to local resources, you can keep
Note that by using --find-links to point to local resources, you can keep
this script from going over the network.
'''

Expand All @@ -59,6 +59,8 @@
parser.add_option("--allow-site-packages",
action="store_true", default=False,
help=("Let bootstrap.py use existing site packages"))
parser.add_option("--setuptools-version",
help="use a specific setuptools version")


options, args = parser.parse_args()
Expand All @@ -79,16 +81,20 @@

if not options.allow_site_packages:
# ez_setup imports site, which adds site packages
# this will remove them from the path to ensure that incompatible versions
# this will remove them from the path to ensure that incompatible versions
# of setuptools are not in the path
import site
# inside a virtualenv, there is no 'getsitepackages'.
# inside a virtualenv, there is no 'getsitepackages'.
# We can't remove these reliably
if hasattr(site, 'getsitepackages'):
for sitepackage_path in site.getsitepackages():
sys.path[:] = [x for x in sys.path if sitepackage_path not in x]

setup_args = dict(to_dir=tmpeggs, download_delay=0)

if options.setuptools_version is not None:
setup_args['version'] = options.setuptools_version

ez['use_setuptools'](**setup_args)
import setuptools
import pkg_resources
Expand Down Expand Up @@ -128,10 +134,15 @@
_final_parts = '*final-', '*final'

def _final_version(parsed_version):
for part in parsed_version:
if (part[:1] == '*') and (part not in _final_parts):
return False
return True
try:
return not parsed_version.is_prerelease
except AttributeError:
# Older setuptools
for part in parsed_version:
if (part[:1] == '*') and (part not in _final_parts):
return False
return True

index = setuptools.package_index.PackageIndex(
search_path=[setuptools_path])
if find_links:
Expand Down Expand Up @@ -176,3 +187,4 @@ def _final_version(parsed_version):

zc.buildout.buildout.main(args)
shutil.rmtree(tmpeggs)

21 changes: 17 additions & 4 deletions buildout.cfg
Original file line number Diff line number Diff line change
@@ -1,18 +1,31 @@
[buildout]
develop = .
parts = interpreter test
extends = https://raw.github.com/zopefoundation/groktoolkit/master/grok.cfg
parts = interpreter test omelette
extends =
https://raw.githubusercontent.com/zopefoundation/groktoolkit/master/grok.cfg
versions = versions
include-site-packages = false
extensions =
mr.developer

auto-checkout =

[versions]
grokui.admin =
grokui.admin =

[sources]
grokui.base = git ${buildout:github}/grokui.base pushurl=${buildout:github_push}/grokui.base branch=ressurection-python3

[interpreter]
recipe = zc.recipe.egg
eggs = grokcore.layout
eggs = grokui.admin
interpreter = python

[test]
recipe = zc.recipe.testrunner
eggs = grokui.admin [test]
defaults = ['--tests-pattern', '^f?tests$', '-v', '-c', '--package=grokui.admin']

[omelette]
recipe = collective.recipe.omelette
eggs = ${test:eggs}
23 changes: 15 additions & 8 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,32 @@
import os
from setuptools import setup, find_packages


tests_require = [
'zope.app.wsgi',
'zc.buildout',
'zope.exceptions',
'zope.fanstatic',
'zope.principalregistry',
'zope.security',
'zope.securitypolicy',
'zope.session',
'zope.testbrowser',
'zope.testing',
'zc.buildout',
]
]


def read(*rnames):
return open(os.path.join(os.path.dirname(__file__), *rnames)).read()


setup(name='grokui.admin',
version='0.13.dev0',
description="The Grok administration and development UI",
long_description=(
read(os.path.join('src', 'grokui', 'admin', 'README.txt')) +
'\n\n' +
read('CHANGES.txt')
),
),
classifiers=[
'Development Status :: 4 - Beta',
'Environment :: Web Environment',
Expand All @@ -43,17 +49,18 @@ def read(*rnames):
zip_safe=False,
namespace_packages=['grokui'],
install_requires=[
'ZODB3',
'BTrees',
'ZODB >= 5.0',
'grok >= 1.10',
'grokcore.site >= 1.6.1',
'grokui.base',
'persistent',
'setuptools',
'z3c.flashmessage',
'zope.applicationcontrol',
'zope.component',
'zope.configuration',
'zope.contentprovider',
'zope.exceptions',
'zope.i18nmessageid',
'zope.interface',
'zope.location',
Expand All @@ -62,7 +69,7 @@ def read(*rnames):
'zope.site',
'zope.size',
'zope.traversing',
],
],
tests_require = tests_require,
extras_require = dict(test=tests_require),
)
)
2 changes: 1 addition & 1 deletion src/grokui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
try:
import pkg_resources
pkg_resources.declare_namespace(__name__)
except ImportError, e:
except ImportError:
from pkgutil import extend_path
__path__ = extend_path(__path__, __name__)
2 changes: 1 addition & 1 deletion src/grokui/admin/applications.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class InstallableApplication(object):
def __init__(self, klass):
self.__name__ = klass.__name__
self.classname = ".".join((klass.__module__, klass.__name__))
self.description = unicode(getattr(klass, '__doc__', u'') or u'')
self.description = getattr(klass, '__doc__', '') or ''


class ApplicationInfo(grok.View):
Expand Down
24 changes: 16 additions & 8 deletions src/grokui/admin/security.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,24 @@
The machinery to do home-calling security notifications.
"""
import grok
import cgi
import time
import urllib2
import urlparse
import sys

from persistent import Persistent
from grokui.admin.interfaces import ISecurityNotifier
from grokui.admin.utilities import getVersion, TimeoutableHTTPHandler
from grokui.base import Messages, IGrokUIRealm

if sys.version_info >= (3, 3):
import urllib.request as urllib
from html import escape
from urllib.parse import urlparse, urljoin
else:
import urllib2 as urllib
from cgi import escape
from urlparse import urlparse, urljoin


MSG_DISABLED = u'Security notifications are disabled.'


Expand Down Expand Up @@ -106,16 +114,16 @@ def fetchMessage(self):
return
version = getVersion('grok')
filename = 'grok-%s.security.txt' % version
url = urlparse.urljoin(self.lookup_url, filename)
url = urljoin(self.lookup_url, filename)
# We create a HTTP handler with a timeout.
http_handler = TimeoutableHTTPHandler(timeout=self.lookup_timeout)
opener = urllib2.build_opener(http_handler)
req = urllib2.Request(url)
opener = urllib.build_opener(http_handler)
req = urllib.Request(url)
try:
message = opener.open(req).read()
self._message = cgi.escape(message)
self._message = escape(message.decode())
self._warningstate = True
except urllib2.HTTPError, e:
except urllib.HTTPError as e:
if e.code == 404:
# No security warning found, good message.
self._message = u''
Expand Down
8 changes: 4 additions & 4 deletions src/grokui/admin/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ def _getInfo(self, ri):

def _getUptime(self, ri):
# make a unix "uptime" uptime format
uptime = long(ri.getUptime())
uptime = int(ri.getUptime())
minutes, seconds = divmod(uptime, 60)
hours, minutes = divmod(minutes, 60)
days, hours = divmod(hours, 24)
Expand Down Expand Up @@ -212,7 +212,7 @@ def _getSize(self, db):
"""Get the database size in a human readable format.
"""
size = db.getSize()
if not isinstance(size, (int, long, float)):
if not isinstance(size, (int, float)):
return str(size)
return byteDisplay(size)

Expand All @@ -223,11 +223,11 @@ def pack(self, dbName, days):
self.flash('Error: Invalid Number')
return
db = getUtility(IDatabase, name=dbName)
print "DB: ", db, days
print("DB: ", db, days)
db.pack(days=days)
return
try:
db.pack(days=days)
self.flash('ZODB `%s` successfully packed.' % (dbName))
except FileStorageError, err:
except FileStorageError as err:
self.flash('ERROR packing ZODB `%s`: %s' % (dbName, err))
24 changes: 13 additions & 11 deletions src/grokui/admin/tests/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@
Applications management
=======================
>>> from zope.app.wsgi.testlayer import Browser
>>> from zope.testbrowser.wsgi import Browser
>>> browser = Browser()
>>> browser.handleErrors = True
>>> browser.addHeader('Authorization', 'Basic mgr:mgrpw')
We fetch the standard page, which should provide us a menu to get all
installable grok applications/components.
>>> browser.open("http://localhost/")
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...
... <legend>Add application</legend>
Expand All @@ -19,7 +20,7 @@
The opening screen should inform us, that there are no applications
installed yet:
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...
... Currently no working...applications are installed.
Expand All @@ -31,7 +32,7 @@
>>> subform.getControl(name='name').value = 'my-mammoth-manager'
>>> subform.getControl('Create').click()
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...
...<legend>Installed applications</legend>
Expand All @@ -42,10 +43,10 @@
Launch the added mammoth manager
>>> mylink = browser.getLink('my-mammoth-manager').click()
>>> print browser.contents
>>> print(browser.contents)
Let's manage some mammoths!
>>> print browser.url
>>> print(browser.url)
http://localhost/my-mammoth-manager
We can also rename applications. For this we choose the application we
Expand All @@ -56,9 +57,10 @@
>>> ctrl.getControl(value='my-mammoth-manager').selected = True
>>> browser.getControl('Rename').click()
We get a form were we can enter new names::
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...<legend> Rename applications: </legend>...
Expand All @@ -69,7 +71,7 @@
Our app was indeed renamed::
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...<legend>Installed applications</legend>
...<a href="http://localhost/my-new-mammoth-manager">
Expand All @@ -83,23 +85,23 @@
>>> subform.getControl(name='name').value = 'my-new-mammoth-manager'
>>> subform.getControl('Create').click()
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...Name `my-new-mammoth-manager` already in use.
...Please choose another name...
We are able to delete installed mammoth-managers
>>> browser.open("http://localhost/++grokui++/applications")
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...
... <legend>Installed applications</legend>
...
>>> ctrl = browser.getControl(name='items')
>>> ctrl.getControl(value='my-new-mammoth-manager').selected = True
>>> browser.getControl('Delete Selected').click()
>>> print browser.contents
>>> print(browser.contents)
<html xmlns="http://www.w3.org/1999/xhtml">
...
... Currently no working applications are installed.
Expand Down
Loading

0 comments on commit 8eeceba

Please sign in to comment.