This commit is contained in:
Lance Edgar 2012-07-09 03:46:23 -05:00
commit 3b208904f8
15 changed files with 471 additions and 370 deletions

View file

@ -1,4 +1,33 @@
0.1a6
-----
- Fixed MANIFEST.in file.
0.1a5
-----
- Added :mod:`edbob.csv` module.
- Tweaked logging configuration and initialization semantics.
0.1a4
-----
- Fixed call to sleep() in filemon service.
0.1a3
-----
- Various tweaks to Pyramid code.
0.1a2
-----
- Add ``win32.send_data_to_printer()`` function.
- Various tweaks to Pyramid code.
0.1a1 0.1a1
----- -----

View file

@ -1,2 +1,18 @@
include *.txt include COPYING.txt README.txt CHANGES.txt
include ez_setup.py include ez_setup.py
include edbob/pyramid/static/favicon.ico
include edbob/pyramid/static/robots.txt
include edbob/pyramid/static/css/*.css
include edbob/pyramid/static/js/*.js
include edbob/scaffolds/edbob/CHANGES.txt
include edbob/scaffolds/edbob/+package+/pyramid/static/favicon.ico
include edbob/scaffolds/edbob/+package+/pyramid/static/robots.txt
recursive-include edbob/pyramid/static/img *.jpg *.png
recursive-include edbob/pyramid/templates *.mako
recursive-include edbob/scaffolds/edbob *.py
recursive-include edbob/scaffolds/edbob *_tmpl
recursive-include edbob/scaffolds/edbob/+package+/pyramid/templates *.mako

View file

@ -1 +1 @@
__version__ = '0.1a3' __version__ = '0.1a7'

View file

@ -70,15 +70,17 @@ class AppConfigParser(ConfigParser.SafeConfigParser):
file, and passes that to ``logging.config.fileConfig()``. file, and passes that to ``logging.config.fileConfig()``.
""" """
if self.getboolean(self.appname, 'basic_logging', default=False): if self.getboolean('edbob', 'basic_logging', default=False):
edbob.basic_logging(self.appname) edbob.basic_logging()
if self.getboolean('edbob', 'configure_logging', default=False):
path = edbob.temp_path(suffix='.conf') path = edbob.temp_path(suffix='.conf')
self.save(path) self.save(path)
try: try:
logging.config.fileConfig(path) logging.config.fileConfig(path, disable_existing_loggers=False)
except ConfigParser.NoSectionError: except ConfigParser.NoSectionError:
pass pass
os.remove(path) os.remove(path)
log.debug("Configured logging")
def get(self, section, option, raw=False, vars=None, default=None): def get(self, section, option, raw=False, vars=None, default=None):
""" """
@ -243,7 +245,6 @@ class AppConfigParser(ConfigParser.SafeConfigParser):
config.has_option('edbob', 'include_config')): config.has_option('edbob', 'include_config')):
include = config.get('edbob', 'include_config') include = config.get('edbob', 'include_config')
if include: if include:
log.debug("Including config: %s" % include)
for p in eval(include): for p in eval(include):
self.read_path(os.path.abspath(p)) self.read_path(os.path.abspath(p))
ConfigParser.SafeConfigParser.read(self, path) ConfigParser.SafeConfigParser.read(self, path)

View file

@ -71,7 +71,9 @@ def basic_logging():
handler = logging.StreamHandler() handler = logging.StreamHandler()
handler.setFormatter(logging.Formatter( handler.setFormatter(logging.Formatter(
'%(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s')) '%(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s'))
logging.getLogger().addHandler(handler) root = logging.getLogger()
root.addHandler(handler)
root.setLevel(logging.INFO)
def get_uuid(): def get_uuid():

71
edbob/csv.py Normal file
View file

@ -0,0 +1,71 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
################################################################################
#
# edbob -- Pythonic Software Framework
# Copyright © 2010-2012 Lance Edgar
#
# This file is part of edbob.
#
# edbob is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# edbob is distributed in the hope that it will be useful, but WITHOUT ANY
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
# more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with edbob. If not, see <http://www.gnu.org/licenses/>.
#
################################################################################
"""
``edbob.csv`` -- CSV File Utilities
"""
from __future__ import absolute_import
import codecs
import csv
class UTF8Recoder(object):
"""
Iterator that reads an encoded stream and reencodes the input to UTF-8.
.. note::
This class was stolen from the Python 2.7 documentation.
"""
def __init__(self, fileobj, encoding):
self.reader = codecs.getreader(encoding)(fileobj)
def __iter__(self):
return self
def next(self):
return self.reader.next().encode('utf_8')
class UnicodeReader(object):
"""
A CSV reader which will iterate over lines in a CSV file, which is encoded
in the given encoding.
.. note::
This class was stolen from the Python 2.7 documentation.
"""
def __init__(self, fileobj, dialect=csv.excel, encoding='utf_8', **kwargs):
fileobj = UTF8Recoder(fileobj, encoding)
self.reader = csv.reader(fileobj, dialect=dialect, **kwargs)
def __iter__(self):
return self
def next(self):
row = self.reader.next()
return [unicode(x, 'utf_8') for x in row]

View file

@ -109,7 +109,7 @@ class FileMonitorService(win32serviceutil.ServiceFramework):
while not file_is_free(path): while not file_is_free(path):
# TODO: Add configurable timeout so long-open files can't hijack # TODO: Add configurable timeout so long-open files can't hijack
# our prcessing. # our prcessing.
time.sleep(0.25) win32api.SleepEx(250, True)
for action in self.monitored[key].actions: for action in self.monitored[key].actions:
if isinstance(action, tuple): if isinstance(action, tuple):
func = action[0] func = action[0]

View file

@ -51,7 +51,6 @@ def main(global_config, **settings):
# Configure edbob. Note that this is done last, primarily to allow logging # Configure edbob. Note that this is done last, primarily to allow logging
# to leverage edbob's config inheritance. # to leverage edbob's config inheritance.
edbob.basic_logging()
edbob.init('{{package}}', os.path.abspath(settings['edbob.config'])) edbob.init('{{package}}', os.path.abspath(settings['edbob.config']))
return config.make_wsgi_app() return config.make_wsgi_app()

View file

@ -27,10 +27,7 @@ whatever = you like
use = egg:{{package}} use = egg:{{package}}
pyramid.reload_templates = true pyramid.reload_templates = true
pyramid.debug_authorization = false pyramid.debug_all = true
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.debug_templates = true
pyramid.default_locale_name = en pyramid.default_locale_name = en
pyramid.includes = pyramid.includes =
pyramid_debugtoolbar pyramid_debugtoolbar
@ -51,9 +48,6 @@ port = 6543
[edbob] [edbob]
include_config = ['%(here)s/production.ini'] include_config = ['%(here)s/production.ini']
[edbob.db]
sqlalchemy.url = sqlite:///{{package}}.sqlite
#################### ####################
# logging # logging
@ -62,8 +56,5 @@ sqlalchemy.url = sqlite:///{{package}}.sqlite
[logger_root] [logger_root]
level = INFO level = INFO
[logger_edbob]
level = INFO
[logger_{{package_logger}}] [logger_{{package_logger}}]
level = DEBUG level = DEBUG

View file

@ -21,10 +21,7 @@ whatever = you like
use = egg:{{package}} use = egg:{{package}}
pyramid.reload_templates = false pyramid.reload_templates = false
pyramid.debug_authorization = false pyramid.debug_all = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.debug_templates = false
pyramid.default_locale_name = en pyramid.default_locale_name = en
# Hack so edbob can find this file from within WSGI app. # Hack so edbob can find this file from within WSGI app.
@ -56,6 +53,8 @@ sqlalchemy.url = postgresql://user:pass@localhost/{{package}}
[edbob] [edbob]
init = edbob.time, edbob.db init = edbob.time, edbob.db
basic_logging = True
configure_logging = True
# shell.python = ipython # shell.python = ipython
[edbob.db] [edbob.db]
@ -82,7 +81,7 @@ timezone = US/Central
#################### ####################
[loggers] [loggers]
keys = root, edbob, {{package_logger}} keys = root, {{package_logger}}
[handlers] [handlers]
keys = file, console, email keys = file, console, email
@ -95,15 +94,10 @@ keys = generic, console
handlers = file, console handlers = file, console
level = WARNING level = WARNING
[logger_edbob]
qualname = edbob
handlers =
# level = INFO
[logger_{{package_logger}}] [logger_{{package_logger}}]
qualname = {{package}} qualname = {{package}}
handlers = handlers =
level = WARNING # level = NOTSET
[handler_file] [handler_file]
class = FileHandler class = FileHandler
@ -114,12 +108,10 @@ formatter = generic
class = StreamHandler class = StreamHandler
args = (sys.stderr,) args = (sys.stderr,)
formatter = console formatter = console
# level = NOTSET
[handler_email] [handler_email]
class = handlers.SMTPHandler class = handlers.SMTPHandler
args = ('mail.example.com', '{{package}}@example.com', ['support@example.com'], '[{{project}} error]', args = ('mail.example.com', '{{package}}@example.com', ['support@example.com'], '[{{project}} error]', ('user', 'pass'))
('user', 'pass'))
level = ERROR level = ERROR
formatter = generic formatter = generic

View file

@ -47,7 +47,7 @@ def init(config):
tz = config.get('edbob.time', 'timezone') tz = config.get('edbob.time', 'timezone')
if tz: if tz:
set_timezone(tz) set_timezone(tz)
log.debug("Timezone set to '%s'" % tz) log.info("Timezone set to '%s'" % tz)
else: else:
log.warning("No timezone configured; falling back to US/Central") log.warning("No timezone configured; falling back to US/Central")
set_timezone('US/Central') set_timezone('US/Central')

View file

@ -121,7 +121,7 @@ setup(
# #
# package # low high # package # low high
'alembic', # 0.2.1 'alembic', # 0.3.4
'py-bcrypt', # 0.2 'py-bcrypt', # 0.2
'SQLAlchemy', # 0.7.6 'SQLAlchemy', # 0.7.6
'Tempita', # 0.5.1 'Tempita', # 0.5.1