Skip to content
Open

Py3 #14

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
23 changes: 16 additions & 7 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import sys
from setuptools import setup, find_packages

py3k = sys.version_info >= (3,)

version = '1.0b5-dev'

long_description = (
Expand All @@ -14,9 +16,19 @@
open('CHANGES.txt').read()
+ '\n')

tests_require = [
'unittest2',
'Cheetah'],
if py3k:
tests_require = []
requires = [
'setuptools',
]
else:
tests_require = [
'unittest2',
'Cheetah']
requires = [
'setuptools',
"Cheetah>1.0,<=2.2.1",
]

setup(name='templer.core',
version=version,
Expand Down Expand Up @@ -54,10 +66,7 @@
include_package_data=True,
platforms='Any',
zip_safe=False,
install_requires=[
'setuptools',
"Cheetah>1.0,<=2.2.1",
],
install_requires=requires,
tests_require=tests_require,
extras_require=dict(test=tests_require),
entry_points="""
Expand Down
31 changes: 18 additions & 13 deletions src/templer/core/base.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
from __future__ import print_function
import os
import sys
import pkg_resources
from copy import copy

from textwrap import TextWrapper
import ConfigParser
from ConfigParser import SafeConfigParser
#import ConfigParser
#from ConfigParser import SafeConfigParser
from templer.core.compat import (
ConfigParser,
SafeConfigParser,
)

from templer.core import pluginlib
from templer.core import copydir
Expand Down Expand Up @@ -39,8 +44,8 @@ def wrap_help_paras(wrapper, text):

for idx, para in enumerate(text.split("\n\n")):
if idx:
print
print wrapper.fill(para)
print()
print(wrapper.fill(para))


def get_zopeskel_prefs():
Expand Down Expand Up @@ -176,7 +181,7 @@ def read_vars(self, command=None):
def write_files(self, command, output_dir, vars):
template_dir = self.template_dir()
if not os.path.exists(output_dir):
print "Creating directory %s" % output_dir
print("Creating directory %s" % output_dir)
if not command.simulate:
# Don't let copydir create this top-level directory,
# since copydir will svn add it sometimes:
Expand Down Expand Up @@ -294,8 +299,8 @@ def print_subtemplate_notice(self, output_dir=None):
print_commands.append(' %s %s' %
(name, this_command.load().summary))
print_commands = '\n'.join(print_commands)
print '-' * 78
print """\
print('-' * 78)
print("""\
The project you just created has local commands. These can be used from within
the product.

Expand All @@ -304,8 +309,8 @@ def print_subtemplate_notice(self, output_dir=None):
Commands:
%s

For more information: paster help COMMAND""" % print_commands
print '-' * 78
For more information: paster help COMMAND""" % print_commands)
print('-' * 78)

def print_zopeskel_message(self, msg_name):
""" print a message stored as an attribute of the template
Expand All @@ -316,9 +321,9 @@ def print_zopeskel_message(self, msg_name):
initial_indent="** ",
subsequent_indent="** ",
)
print "\n" + '*'*74
print("\n" + '*'*74)
wrap_help_paras(textwrapper, msg)
print '*'*74 + "\n"
print('*'*74 + "\n")

def readable_license_options(self):
output = ["The following licenses are available:\n", ]
Expand Down Expand Up @@ -520,8 +525,8 @@ def check_vars(self, vars, cmd):
if response is not self.null_value_marker:
try:
response = var.validate(response)
except ValidationException, e:
print e
except ValidationException as e:
print(e)
response = self.null_value_marker
elif var.default is NoDefault:
errors.append('Required variable missing: %s'
Expand Down
15 changes: 15 additions & 0 deletions src/templer/core/compat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import sys
inPy3k = sys.version_info[0] == 3

if not inPy3k:
import ConfigParser
from ConfigParser import SafeConfigParser
import StringIO
maxint = sys.maxint
string_types = basestring
else:
import configparser as ConfigParser
from configparser import ConfigParser as SafeConfigParser
import io as StringIO
maxint = sys.maxsize
string_types = (str, bytes)
103 changes: 54 additions & 49 deletions src/templer/core/control_script.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
from __future__ import print_function
import sys
import os
import ConfigParser
import pkg_resources
from cStringIO import StringIO
from textwrap import TextWrapper

from templer.core.base import wrap_help_paras
from templer.core.create import CreateDistroCommand
from templer.core.ui import list_sorted_templates
from templer.core.compat import ConfigParser
try:
from cStringIO import StringIO
except ImportError:
from io import StringIO


try:
from templer.localcommands.command import TemplerLocalCommand
Expand Down Expand Up @@ -303,10 +308,10 @@ def __call__(self, argv):
"""
try:
template_name, output_name, args = self._process_args(argv)
except SyntaxError, e:
except SyntaxError as e:
self.usage()
msg = "ERROR: There was a problem with your arguments: %s\n"
print msg % str(e)
print(msg % str(e))
raise

rez = pkg_resources.iter_entry_points(
Expand All @@ -315,14 +320,14 @@ def __call__(self, argv):
rez = list(rez)
if not rez:
self.usage()
print "ERROR: No such template: %s\n" % template_name
print("ERROR: No such template: %s\n" % template_name)
return 1

template = rez[0].load()
print "\n%s: %s" % (template_name, template.summary)
print("\n%s: %s" % (template_name, template.summary))
help = getattr(template, 'help', None)
if help:
print template.help
print(template.help)

command = CreateDistroCommand()

Expand All @@ -339,59 +344,59 @@ def __call__(self, argv):
if output_name:
try:
self._checkdots(template, output_name)
except ValueError, e:
print "ERROR: %s\n" % str(e)
except ValueError as e:
print("ERROR: %s\n" % str(e))
raise
else:
ndots = getattr(template, 'ndots', None)
help = DOT_HELP.get(ndots)
while True:
if help:
print help
print(help)
try:
challenge = "Enter project name (or q to quit)"
output_name = command.challenge(challenge)
if output_name == 'q':
print "\n\nExiting...\n"
print("\n\nExiting...\n")
return 0
self._checkdots(template, output_name)
except ValueError, e:
print "\nERROR: %s" % e
except ValueError as e:
print("\nERROR: %s" % e)
raise
else:
break

print self.texts['help_prompt']
print(self.texts['help_prompt'])

try:
command.run(['-q', '-t', template_name] + args + special_args)
except KeyboardInterrupt:
print "\n\nExiting...\n"
print("\n\nExiting...\n")
return 0
except Exception, e:
print "\nERROR: %s\n" % str(e)
except Exception as e:
print("\nERROR: %s\n" % str(e))
raise
return 0

# Public API methods, can be overridden by templer-based applications
def show_help(self):
"""display help text"""
print self.texts['description'] % {'script_name': self.name}
print(self.texts['description'] % {'script_name': self.name})
return 0

def generate_dotfile(self):
"""generate a dotfile to hold default values
"""

cats = list_sorted_templates(scope=self.allowed_packages)
print self.texts['dotfile_header'] % {'script_name': self.name}
print(self.texts['dotfile_header'] % {'script_name': self.name})
for temp in sum(cats.values(), []):
print "\n[%(name)s]\n" % temp
print("\n[%(name)s]\n" % temp)
tempc = temp['entry'].load()
for var in tempc.vars:
if hasattr(var, 'pretty_description'):
print "# %s" % var.pretty_description()
print "# %s = %s\n" % (var.name, var.default)
print("# %s" % var.pretty_description())
print("# %s = %s\n" % (var.name, var.default))
return 0

def list_verbose(self):
Expand All @@ -402,31 +407,31 @@ def list_verbose(self):
cats = list_sorted_templates(scope=self.allowed_packages)
if cats:
for title, items in cats.items():
print "\n"+ title
print "-" * len(title)
print("\n"+ title)
print("-" * len(title))
# Hard-coded for now, since 'add' is the only one
if title == 'Local Commands':
print '\nadd: Allows the addition of further templates'\
' from the following list'
print ' to an existing package\n'
print '\nLocal Templates'
print '-----------------'
print('\nadd: Allows the addition of further templates'\
' from the following list')
print(' to an existing package\n')
print('\nLocal Templates')
print('-----------------')
for temp in items:
print "\n%s: %s\n" % (temp['name'], temp['summary'])
print("\n%s: %s\n" % (temp['name'], temp['summary']))
if temp['help']:
wrap_help_paras(textwrapper, temp['help'])
print
print()
else:
print self.texts['not_here_warning']
print(self.texts['not_here_warning'])

return 0

def show_version(self):
"""show installed version of packages listed in self.versions
"""
version_info = self._get_version_info()
print self._format_version_info(
version_info, "Installed Templer Packages")
print(self._format_version_info(
version_info, "Installed Templer Packages"))
return 0

def usage(self):
Expand All @@ -437,14 +442,14 @@ def usage(self):
if self.allowed_packages in ['all', 'local']:
local = '[<local-command>] '

print self.texts['usage'] % {'templates': templates,
print(self.texts['usage'] % {'templates': templates,
'local': local,
'script_name': self.name,
'dotfile_name': self.dotfile}
'dotfile_name': self.dotfile})
return 0

def no_locals(self):
print self.texts['no_localcommands_warning']
print(self.texts['no_localcommands_warning'])

# Private API supporting command-line flags
# should not need to be changed by templer-based applications
Expand All @@ -461,7 +466,7 @@ def _run_localcommand(self, args):
return result
else:
# situation 1, fail and report.
print self.texts['no_localcommands_warning']
print(self.texts['no_localcommands_warning'])
return 1

def _get_templer_packages(self):
Expand Down Expand Up @@ -490,12 +495,12 @@ def _format_version_info(self, version_info, header=None):
maxpkg = max([len(vi[0]) for vi in version_info])
maxver = max([len(vi[1]) for vi in version_info])
if header is not None:
print >>s, "\n| %s" % header
print >>s, "+" + ("-" * (maxpkg + maxver + 3))
print("\n| %s" % header, file=s)
print("+" + ("-" * (maxpkg + maxver + 3)), file=s)
for vi in version_info:
padding = maxpkg - len(vi[0])
values = [vi[0], ' ' * padding, vi[1]]
print >>s, "| %s:%s %s" % tuple(values)
print("| %s:%s %s" % tuple(values), file=s)
s.seek(0)
return s.read()

Expand All @@ -509,19 +514,19 @@ def _list_printable_templates(self):
templates = sum(cats.values(), []) # flatten into single list
max_name = max([len(x['name']) for x in templates])
for title, items in cats.items():
print >>s, "\n%s\n" % title
print("\n%s\n" % title, file=s)
# Hard-coded for now, since 'add' is the only one
if title == 'Local Commands':
print >>s, "| add: Allows the addition of further"\
" templates from the following list"
print >>s, " to an existing package\n"
print("| add: Allows the addition of further"\
" templates from the following list", file=s)
print(" to an existing package\n", file=s)
for entry in items:
print >>s, "| %s:%s %s\n" % (
print("| %s:%s %s\n" % (
entry['name'],
' '*(max_name-len(entry['name'])),
entry['summary']),
entry['summary']), file=s)
else:
print >>s, self.texts['not_here_warning']
print(self.texts['not_here_warning'], file=s)

s.seek(0)
return s.read()
Expand Down Expand Up @@ -610,7 +615,7 @@ def _context_awareness(self):
f = open(changes_txt, 'rb')
content = f.read()
f.close()
if 'Package created using templer' in content:
if b'Package created using templer' in content:
made_by_templer = True

(cwd, tail) = os.path.split(cwd)
Expand Down
Loading