Error at install on OSX

9 views
Skip to first unread message

bsergean

unread,
Sep 27, 2007, 12:46:00 AM9/27/07
to Posterity
Hi,

I installed a fresh python 2.5.1 on a Tiger machine, but I cannot run
the sole script I found in my path:

[benjadrine@ravioli benjadrine]$ posterity-admin
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/Current/bin/
posterity-admin", line 8, in <module>
load_entry_point('Posterity==0.5', 'console_scripts', 'posterity-
admin')()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/setuptools-0.6c7-py2.5.egg/pkg_resources.py",
line 277, in load_entry_point
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/setuptools-0.6c7-py2.5.egg/pkg_resources.py",
line 2179, in load_entry_point
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/setuptools-0.6c7-py2.5.egg/pkg_resources.py",
line 1912, in load
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/Posterity-0.5-py2.5.egg/posterity/admin/
__init__.py", line 3, in <module>
from posterity.admin.admin import AdminCommand
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/Posterity-0.5-py2.5.egg/posterity/admin/
admin.py", line 23, in <module>
from elixir import metadata, objectstore
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/Elixir-0.3.0-py2.5.egg/elixir/__init__.py",
line 24, in <module>
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/Elixir-0.3.0-py2.5.egg/elixir/entity.py", line
5, in <module>
ImportError: cannot import name deferred


Here are some infos about my python install:

[benjadrine@ravioli benjadrine]$ python -v
# installing zipimport hook
import zipimport # builtin
# installed zipimport hook
# /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
site.pyc matches /Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site.py
import site # precompiled from /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/site.pyc
# /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
os.pyc matches /Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/os.py
import os # precompiled from /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/os.pyc
import posix # builtin
# /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
posixpath.pyc matches /Library/Frameworks/Python.framework/Versions/
2.5/lib/python2.5/posixpath.py
import posixpath # precompiled from /Library/Frameworks/
Python.framework/Versions/2.5/lib/python2.5/posixpath.pyc
# /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
stat.pyc matches /Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/stat.py
import stat # precompiled from /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/stat.pyc
# /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
UserDict.pyc matches /Library/Frameworks/Python.framework/Versions/2.5/
lib/python2.5/UserDict.py
import UserDict # precompiled from /Library/Frameworks/
Python.framework/Versions/2.5/lib/python2.5/UserDict.pyc
# /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
copy_reg.pyc matches /Library/Frameworks/Python.framework/Versions/2.5/
lib/python2.5/copy_reg.py
import copy_reg # precompiled from /Library/Frameworks/
Python.framework/Versions/2.5/lib/python2.5/copy_reg.pyc
# /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
types.pyc matches /Library/Frameworks/Python.framework/Versions/2.5/
lib/python2.5/types.py
import types # precompiled from /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/types.pyc
import _types # builtin
# zipimport: found 78 names in /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/site-packages/setuptools-0.6c7-py2.5.egg
# zipimport: found 18 names in /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/site-packages/Elixir-0.3.0-py2.5.egg
# zipimport: found 124 names in /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/site-packages/SQLAlchemy-0.4.0beta6-
py2.5.egg
# zipimport: found 45 names in /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/site-packages/Genshi-0.4.4-py2.5.egg
# zipimport: found 8 names in /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/site-packages/selector-0.8.11-py2.5.egg
# zipimport: found 7 names in /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/site-packages/resolver-0.2.1-py2.5.egg
# /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
warnings.pyc matches /Library/Frameworks/Python.framework/Versions/2.5/
lib/python2.5/warnings.py
import warnings # precompiled from /Library/Frameworks/
Python.framework/Versions/2.5/lib/python2.5/warnings.pyc
# /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
linecache.pyc matches /Library/Frameworks/Python.framework/Versions/
2.5/lib/python2.5/linecache.py
import linecache # precompiled from /Library/Frameworks/
Python.framework/Versions/2.5/lib/python2.5/linecache.pyc
import encodings # directory /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/encodings
# /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
encodings/__init__.pyc matches /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/encodings/__init__.py
import encodings # precompiled from /Library/Frameworks/
Python.framework/Versions/2.5/lib/python2.5/encodings/__init__.pyc
# /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
codecs.pyc matches /Library/Frameworks/Python.framework/Versions/2.5/
lib/python2.5/codecs.py
import codecs # precompiled from /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/codecs.pyc
import _codecs # builtin
# /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
encodings/aliases.pyc matches /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/encodings/aliases.py
import encodings.aliases # precompiled from /Library/Frameworks/
Python.framework/Versions/2.5/lib/python2.5/encodings/aliases.pyc
# /Library/Frameworks/Python.framework/Versions/2.5/lib/python2.5/
encodings/ascii.pyc matches /Library/Frameworks/Python.framework/
Versions/2.5/lib/python2.5/encodings/ascii.py
import encodings.ascii # precompiled from /Library/Frameworks/
Python.framework/Versions/2.5/lib/python2.5/encodings/ascii.pyc
Python 2.5.1 (r251:54869, Apr 18 2007, 22:08:04)
[GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
dlopen("/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/lib-dynload/readline.so", 2);
import readline # dynamically loaded from /Library/Frameworks/
Python.framework/Versions/2.5/lib/python2.5/lib-dynload/readline.so

Please answer if you have any clue !

Thanks,
Benjamin.

Jonas Borgström

unread,
Sep 27, 2007, 3:44:58 AM9/27/07
to post...@googlegroups.com
bsergean wrote:
>
> Hi,
>
> I installed a fresh python 2.5.1 on a Tiger machine, but I cannot run
> the sole script I found in my path:
>

Hi Benjamin,

I think the problem is that you have SQLAlchemy-0.4.0beta6 installed but
Elixir currently is currently only compatible with SQLAlchemy 0.3.x. You
can run the following commands to downgrade:

easy_install -m SQLAlchemy
easy_install SQLAlchemy==0.3.10

Btw, I'm planning to release Posterity 0.6 in a few days (probably on
Monday). So trunk is pretty stable and contains a couple of new features
(filters and pop3 message downloading) so it might be a good idea to
give it a try. Trunk will also make sure the correct SQLAlchemy version
is installed.

A quickstart guide for trunk can be found here:
http://posterity.edgewall.org/wiki/Documentation/quickstart.html

And for Posterity 0.5:
http://posterity.edgewall.org/wiki/Documentation/0.5.x/quickstart.html

Cheers,
Jonas

bsergean

unread,
Sep 28, 2007, 11:12:23 AM9/28/07
to Posterity

On Sep 27, 12:44 am, Jonas Borgström <jo...@edgewall.com> wrote:
> bsergean wrote:
>
> > Hi,
>
> > I installed a fresh python 2.5.1 on a Tiger machine, but I cannot run
> > the sole script I found in my path:
>
> Hi Benjamin,
>
> I think the problem is that you have SQLAlchemy-0.4.0beta6 installed but
> Elixir currently is currently only compatible with SQLAlchemy 0.3.x. You
> can run the following commands to downgrade:
>
> easy_install -m SQLAlchemy
> easy_install SQLAlchemy==0.3.10
>

Thanks. It solved the issue.

Then I tried this:
$ posterity-admin account bsergean

and this:
$ posterity-admin serve

But it blows, because of the deploy module. Maybe a downgrade here too
would be usefull. It looks like using svn would be a good idea. I will
try it, especially because pop3 is a must have for me. (I might try
your package with my gmail account).

Thanks,
Benjamin.

ps: The error:

Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/Current/bin/
posterity-admin", line 8, in <module>
load_entry_point('Posterity==0.5', 'console_scripts', 'posterity-
admin')()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/

python2.5/site-packages/Posterity-0.5-py2.5.egg/posterity/admin/
admin.py", line 118, in main
run_admin(sys.argv)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/Posterity-0.5-py2.5.egg/posterity/admin/
admin.py", line 115, in run_admin
return cmd.run_command(args[2:])
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/Posterity-0.5-py2.5.egg/posterity/admin/
admin.py", line 96, in run_command
return self.run()
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/Posterity-0.5-py2.5.egg/posterity/admin/
serve.py", line 45, in run
server_runner(app, {}, host=self.options.host,
port=self.options.port)
File "/Library/Frameworks/Python.framework/Versions/2.5/lib/
python2.5/site-packages/Paste-1.4.2-py2.5.egg/paste/httpserver.py",
line 1285, in server_runner
from paste.deploy.converters import asbool
ImportError: No module named deploy.converters

Jonas Borgström

unread,
Sep 28, 2007, 11:35:43 AM9/28/07
to post...@googlegroups.com
bsergean wrote:
*snip*

> Then I tried this:
> $ posterity-admin account bsergean
>
> and this:
> $ posterity-admin serve
>
> But it blows, because of the deploy module. Maybe a downgrade here too
> would be usefull. It looks like using svn would be a good idea. I will
> try it, especially because pop3 is a must have for me. (I might try
> your package with my gmail account).
>
Oh, I'm sorry about that, I forgot to mention that earlier. In the 0.5
release I forgot to add PasteDeploy to the dependency list. Running
"easy_install PasteDeploy" should solve that problem.

But since you want to test the pop3 support the trunk version is your
only option until 0.6 is release.
Just keep in mind that the quickstart instructions are slightly
different:

http://posterity.edgewall.org/wiki/Documentation/quickstart.html

Cheers,
Jonas

bsergean

unread,
Sep 28, 2007, 2:34:00 PM9/28/07
to Posterity
Ok. I tried with the development version from work on a Mandriva box,
and everything works fine. Looks like I already have sqlite installed,
so I get a:

/usr/lib/python2.5/site-packages/SQLAlchemy-0.3.10-py2.5.egg/
sqlalchemy/databases/sqlite.py:167: RuntimeWarning: The installed
version of sqlite (3.3.8) is out-dated, and will cause errors in some
cases. Version 3.3.13 or greater is recommended.
warnings.warn(RuntimeWarning("The installed version of sqlite (%s)
is out-dated, and will cause errors in some cases. Version 3.3.13 or
greater is recommended." % self.dbapi.sqlite_version))

pop3:
I created a pop3 account, from the web interface. It worked fine, but
when I try to fetch mail here is what I get:

[bsergean@marge1 posterity-trunk]$ posterity-admin fetch


Traceback (most recent call last):

File "/usr/bin/posterity-admin", line 8, in <module>
load_entry_point('Posterity==0.6dev-r176', 'console_scripts',
'posterity-admin')()
File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 236,
in load_entry_point
return get_distribution(dist).load_entry_point(group, name)
File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 2097,
in load_entry_point
return ep.load()
File "/usr/lib/python2.5/site-packages/pkg_resources.py", line 1830,
in load
entry = __import__(self.module_name, globals(),globals(),
['__name__'])
File "/home/bsergean/src/posterity-trunk/posterity/admin/


__init__.py", line 3, in <module>
from posterity.admin.admin import AdminCommand

File "/home/bsergean/src/posterity-trunk/posterity/admin/admin.py",
line 27, in <module>
from posterity.core import PosterityInstance
File "/home/bsergean/src/posterity-trunk/posterity/core.py", line
32, in <module>
from posterity.web.middleware import CSRFMiddleware,
SessionMiddleware, \
File "/home/bsergean/src/posterity-trunk/posterity/web/
middleware.py", line 25, in <module>
from posterity.model import UserSession, Account
File "/home/bsergean/src/posterity-trunk/posterity/model.py", line
464, in <module>
Index('tag_name_unique_idx', Tag.c.account_id, Tag.c.name,
unique=True)
File "/usr/lib/python2.5/site-packages/SQLAlchemy-0.3.10-py2.5.egg/
sqlalchemy/util.py", line 226, in __getattr__
raise AttributeError(key)
AttributeError: account_id

Maybe this account_id refer to an identity. I just created one
(identity) from the web, and it didn't help, I still have this error
message...

Benjamin.

bsergean

unread,
Sep 28, 2007, 2:43:27 PM9/28/07
to Posterity
A small small stuff:

[bsergean@marge1 posterity-trunk]$ posterity-admin inject bsergean --
mbox -f Mail.mbox


/usr/lib/python2.5/site-packages/SQLAlchemy-0.3.10-py2.5.egg/
sqlalchemy/databases/sqlite.py:167: RuntimeWarning: The installed
version of sqlite (3.3.8) is out-dated, and will cause errors in some
cases. Version 3.3.13 or greater is recommended.
warnings.warn(RuntimeWarning("The installed version of sqlite (%s)
is out-dated, and will cause errors in some cases. Version 3.3.13 or
greater is recommended." % self.dbapi.sqlite_version))

Traceback (most recent call last):
File "/usr/bin/posterity-admin", line 8, in <module>
load_entry_point('Posterity==0.6dev-r176', 'console_scripts',
'posterity-admin')()

File "/home/bsergean/src/posterity-trunk/posterity/admin/admin.py",
line 128, in main
run_admin(sys.argv)
File "/home/bsergean/src/posterity-trunk/posterity/admin/admin.py",
line 125, in run_admin
return cmd.run_command(args[2:])
File "/home/bsergean/src/posterity-trunk/posterity/admin/admin.py",
line 99, in run_command
self.instance.run_in_transaction(self.run)
File "/home/bsergean/src/posterity-trunk/posterity/core.py", line
114, in run_in_transaction
callable()
File "/home/bsergean/src/posterity-trunk/posterity/admin/inject.py",
line 106, in run
fp = open(self.options.file, 'rb')
IOError: [Errno 2] No such file or directory: 'Mail.mbox'


[bsergean@marge1 posterity-trunk]$ svn diff
Index: posterity/admin/inject.py
===================================================================
--- posterity/admin/inject.py (revision 176)
+++ posterity/admin/inject.py (working copy)
@@ -11,6 +11,7 @@
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://posterity.edgewall.org/log/.

+import os
import re
import sys
import time
@@ -103,6 +104,8 @@
self.parser.error('Invalid/missing username: ' +
self.account)
injector = Injector(self.instance)
if self.options.file:
+ if not os.path.exists(self.options.file):
+ self.parser.error('No such file: %s' %
(self.options.file))
fp = open(self.options.file, 'rb')
else:
fp = sys.stdin

What do you think ?
Maybe self.parser.error is not really the good way to report error.
Are you using the logging class to do that ?

Benjamin.

bsergean

unread,
Sep 28, 2007, 3:02:18 PM9/28/07
to Posterity
I am playing a little bit with it. tag is working

I added a progress bar for the mbox importing, if you are
interested...

[bsergean@marge1 posterity-trunk]$ svn diff
Index: posterity/admin/inject.py
===================================================================
--- posterity/admin/inject.py (revision 176)
+++ posterity/admin/inject.py (working copy)
@@ -11,6 +11,7 @@
# individuals. For the exact contribution history, see the revision
# history and logs, available at http://posterity.edgewall.org/log/.

+import os
import re
import sys
import time

@@ -27,6 +28,7 @@
from posterity.model import Account, Msg
from posterity.util.mail import parse_rfc2822_date

+from posterity.util.progress_bar import ProgressMsg

class Injector(object):

@@ -55,10 +57,13 @@
else:
msgs = mbox

- for i, msg in enumerate(msgs):
+ progress = ProgressMsg(0, sys.stderr)
+ progress.target = len(msgs)
+
+ for msg in msgs:
self.inject_message(account, msg)
objectstore.flush()
- print i
+ progress.Increment()

def inject_message(self, account, message):
msg = Msg.parse_message(account, message)
@@ -103,6 +108,8 @@


self.parser.error('Invalid/missing username: ' +
self.account)
injector = Injector(self.instance)
if self.options.file:
+ if not os.path.exists(self.options.file):
+ self.parser.error('No such file: %s' %
(self.options.file))
fp = open(self.options.file, 'rb')
else:
fp = sys.stdin

Index: posterity/util/progress_bar.py
===================================================================
--- posterity/util/progress_bar.py (revision 0)
+++ posterity/util/progress_bar.py (revision 0)
@@ -0,0 +1,34 @@
+"""
+Progress bar class
+"""
+
+# Copyright (C) 2006, 2007 GPL
+# Written by Benjamin Sergeant <bser...@gmail.com>
+
+__revision__ = '$Id$ (C) 2007 GPL'
+
+import sys
+
+from colorterm import TerminalController, ProgressBar
+class ProgressMsg(object):
+ """ curses progress bar """
+ caption = 'Importing mailbox'
+
+ def __init__(self, target, output=sys.stdout):
+ #raise UnicodeDecodeError
+ self.counter = 0
+ self.target = target
+ self.term = TerminalController()
+ if output == sys.stderr:
+ return
+ self.pb = ProgressBar(self.term, self.caption)
+
+ def Increment(self):
+ if self.counter == 0:
+ self.pb = ProgressBar(self.term, self.caption)
+ self.pb.clear()
+ self.counter += 1
+ percent = self.counter / float(self.target)
+ self.pb.update(percent, '(%d processed out of %d)' \
+ % (self.counter, self.target))
+

Property changes on: posterity/util/progress_bar.py
___________________________________________________________________
Name: svn:keywords
+ Id

Index: posterity/util/colorterm.py
===================================================================
--- posterity/util/colorterm.py (revision 0)
+++ posterity/util/colorterm.py (revision 0)
@@ -0,0 +1,192 @@
+import sys, re
+
+class TerminalController:
+ """
+ A class that can be used to portably generate formatted output to
+ a terminal.
+
+ `TerminalController` defines a set of instance variables whose
+ values are initialized to the control sequence necessary to
+ perform a given action. These can be simply included in normal
+ output to the terminal:
+
+ >>> term = TerminalController()
+ >>> print 'This is '+term.GREEN+'green'+term.NORMAL
+
+ Alternatively, the `render()` method can used, which replaces
+ '${action}' with the string required to perform 'action':
+
+ >>> term = TerminalController()
+ >>> print term.render('This is ${GREEN}green${NORMAL}')
+
+ If the terminal doesn't support a given action, then the value of
+ the corresponding instance variable will be set to ''. As a
+ result, the above code will still work on terminals that do not
+ support color, except that their output will not be colored.
+ Also, this means that you can test whether the terminal supports
a
+ given action by simply testing the truth value of the
+ corresponding instance variable:
+
+ >>> term = TerminalController()
+ >>> if term.CLEAR_SCREEN:
+ ... print 'This terminal supports clearning the screen.'
+
+ Finally, if the width and height of the terminal are known, then
+ they will be stored in the `COLS` and `LINES` attributes.
+ """
+ # Cursor movement:
+ BOL = '' #: Move the cursor to the beginning of the
line
+ UP = '' #: Move the cursor up one line
+ DOWN = '' #: Move the cursor down one line
+ LEFT = '' #: Move the cursor left one char
+ RIGHT = '' #: Move the cursor right one char
+
+ # Deletion:
+ CLEAR_SCREEN = '' #: Clear the screen and move to home
position
+ CLEAR_EOL = '' #: Clear to the end of the line.
+ CLEAR_BOL = '' #: Clear to the beginning of the line.
+ CLEAR_EOS = '' #: Clear to the end of the screen
+
+ # Output modes:
+ BOLD = '' #: Turn on bold mode
+ BLINK = '' #: Turn on blink mode
+ DIM = '' #: Turn on half-bright mode
+ REVERSE = '' #: Turn on reverse-video mode
+ NORMAL = '' #: Turn off all modes
+
+ # Cursor display:
+ HIDE_CURSOR = '' #: Make the cursor invisible
+ SHOW_CURSOR = '' #: Make the cursor visible
+
+ # Terminal size:
+ COLS = None #: Width of the terminal (None for unknown)
+ LINES = None #: Height of the terminal (None for unknown)
+
+ # Foreground colors:
+ BLACK = BLUE = GREEN = CYAN = RED = MAGENTA = YELLOW = WHITE = ''
+
+ # Background colors:
+ BG_BLACK = BG_BLUE = BG_GREEN = BG_CYAN = ''
+ BG_RED = BG_MAGENTA = BG_YELLOW = BG_WHITE = ''
+
+ _STRING_CAPABILITIES = """
+ BOL=cr UP=cuu1 DOWN=cud1 LEFT=cub1 RIGHT=cuf1
+ CLEAR_SCREEN=clear CLEAR_EOL=el CLEAR_BOL=el1 CLEAR_EOS=ed
BOLD=bold
+ BLINK=blink DIM=dim REVERSE=rev UNDERLINE=smul NORMAL=sgr0
+ HIDE_CURSOR=cinvis SHOW_CURSOR=cnorm""".split()
+ _COLORS = """BLACK BLUE GREEN CYAN RED MAGENTA YELLOW
WHITE""".split()
+ _ANSICOLORS = "BLACK RED GREEN YELLOW BLUE MAGENTA CYAN
WHITE".split()
+
+ def __init__(self, term_stream=sys.stdout):
+ """
+ Create a `TerminalController` and initialize its attributes
+ with appropriate values for the current terminal.
+ `term_stream` is the stream that will be used for terminal
+ output; if this stream is not a tty, then the terminal is
+ assumed to be a dumb terminal (i.e., have no capabilities).
+ """
+ # Curses isn't available on all platforms
+ try: import curses
+ except: return
+
+ # If the stream isn't a tty, then assume it has no
capabilities.
+ if not term_stream.isatty(): return
+
+ # Check the terminal type. If we fail, then assume that the
+ # terminal has no capabilities.
+ try: curses.setupterm()
+ except: return
+
+ # Look up numeric capabilities.
+ self.COLS = curses.tigetnum('cols')
+ self.LINES = curses.tigetnum('lines')
+
+ # Look up string capabilities.
+ for capability in self._STRING_CAPABILITIES:
+ (attrib, cap_name) = capability.split('=')
+ setattr(self, attrib, self._tigetstr(cap_name) or '')
+
+ # Colors
+ set_fg = self._tigetstr('setf')
+ if set_fg:
+ for i,color in zip(range(len(self._COLORS)),
self._COLORS):
+ setattr(self, color, curses.tparm(set_fg, i) or '')
+ set_fg_ansi = self._tigetstr('setaf')
+ if set_fg_ansi:
+ for i,color in zip(range(len(self._ANSICOLORS)),
self._ANSICOLORS):
+ setattr(self, color, curses.tparm(set_fg_ansi, i) or
'')
+ set_bg = self._tigetstr('setb')
+ if set_bg:
+ for i,color in zip(range(len(self._COLORS)),
self._COLORS):
+ setattr(self, 'BG_'+color, curses.tparm(set_bg, i) or
'')
+ set_bg_ansi = self._tigetstr('setab')
+ if set_bg_ansi:
+ for i,color in zip(range(len(self._ANSICOLORS)),
self._ANSICOLORS):
+ setattr(self, 'BG_'+color, curses.tparm(set_bg_ansi,
i) or '')
+
+ def _tigetstr(self, cap_name):
+ # String capabilities can include "delays" of the form
"$<2>".
+ # For any modern terminal, we should be able to just ignore
+ # these, so strip them out.
+ import curses
+ cap = curses.tigetstr(cap_name) or ''
+ return re.sub(r'\$<\d+>[/*]?', '', cap)
+
+ def render(self, template):
+ """
+ Replace each $-substitutions in the given template string
with
+ the corresponding terminal control string (if it's defined)
or
+ '' (if it's not).
+ """
+ return re.sub(r'\$\$|\${\w+}', self._render_sub, template)
+
+ def _render_sub(self, match):
+ s = match.group()
+ if s == '$$': return s
+ else: return getattr(self, s[2:-1])
+
+#######################################################################
+# Example use case: progress bar
+#######################################################################
+
+class ProgressBar:
+ """
+ A 3-line progress bar, which looks like::
+
+ Header
+ 20% [===========----------------------------------]
+ progress message
+
+ The progress bar is colored, if the terminal supports color
+ output; and adjusts to the width of the terminal.
+ """
+ BAR = '%3d%% ${GREEN}[${BOLD}%s%s${NORMAL}${GREEN}]${NORMAL}\n'
+ HEADER = '${BOLD}${CYAN}%s${NORMAL}\n\n'
+
+ def __init__(self, term, header):
+ self.term = term
+ if not (self.term.CLEAR_EOL and self.term.UP and
self.term.BOL):
+ raise ValueError("Terminal isn't capable enough -- you "
+ "should use a simpler progress
dispaly.")
+ self.width = self.term.COLS or 75
+ self.bar = term.render(self.BAR)
+ self.header = self.term.render(self.HEADER %
header.center(self.width))
+ self.cleared = 1 #: true if we haven't drawn the bar yet.
+ self.update(0, '')
+
+ def update(self, percent, message):
+ if self.cleared:
+ sys.stdout.write(self.header)
+ self.cleared = 0
+ n = int((self.width-10)*percent)
+ sys.stdout.write(
+ self.term.BOL + self.term.UP + self.term.CLEAR_EOL +
+ (self.bar % (100*percent, '='*n, '-'*(self.width-10-n)))
+
+ self.term.CLEAR_EOL + message.center(self.width))
+
+ def clear(self):
+ if not self.cleared:
+ sys.stdout.write(self.term.BOL + self.term.CLEAR_EOL +
+ self.term.UP + self.term.CLEAR_EOL +
+ self.term.UP + self.term.CLEAR_EOL)
+ self.cleared = 1

Property changes on: posterity/util/colorterm.py
___________________________________________________________________
Name: svn:keywords
+ Id


bsergean

unread,
Sep 28, 2007, 3:03:49 PM9/28/07
to Posterity
I just added a progress bar, and a dummy test if the mbox to import is
not there. If you are interested ...

+from posterity.util.progress_bar import ProgressMsg

class Injector(object):

Jonas Borgström

unread,
Sep 29, 2007, 2:19:42 PM9/29/07
to post...@googlegroups.com

This is very weird. If I understood you correctly you get this traceback
when you run "posterity-admin fetch" but not "posterity-admin serve"?
But if I interpret the above traceback this exception is raised very
early on, during the import of "posterity-admin" entry point. So the
exact same code path should be shared by both the "serve" and "fetch"
admin commands...

Btw, I'm thinking about dropping the sqlite support since unlike
postgresql, mysql and most other databases sqlite doesn't support
foreign keys. The current database scheme relies on "ON DELETE CASCADE"
and "ON DELETE SET NULL" constraints. Sqlite is a very nice database,
especially since it's very easy to use, but I doubt that it's the best
choice for most people when it comes to hosting email accounts in a
production environment. Most people are probably better of using other
databases with better concurrency support. Does that sound reasonable?

(btw, the same goes for the mysql myisam database engine, which also
lacks foreign key support)

bsergean

unread,
Sep 29, 2007, 5:23:39 PM9/29/07
to Posterity

Maybe I run both command in two terminals ... I'll try again monday on
my work machine. The fetch worked here at home, maybe because there is
no firewall on the pop gmail port.

>
> Btw, I'm thinking about dropping the sqlite support since unlike
> postgresql, mysql and most other databases sqlite doesn't support
> foreign keys. The current database scheme relies on "ON DELETE CASCADE"
> and "ON DELETE SET NULL" constraints. Sqlite is a very nice database,
> especially since it's very easy to use, but I doubt that it's the best
> choice for most people when it comes to hosting email accounts in a
> production environment. Most people are probably better of using other
> databases with better concurrency support. Does that sound reasonable?
>

I don't know a lot about database so I'm sure you know better. Just
that there is no db admin with sqlite.

Reply all
Reply to author
Forward
0 new messages