Yann's Blog - Software and hardware

January 22, 2009

yyafl 0.2.1 is now available

Filed under: Python,Software — Yann @ 9:59 pm

yyafl, a Python web form library operating on domain objects, now has version 0.2.1 available for download. This release includes numerous fixes for decorators, including the ability to attach multiple decorators to a form field or the wildcard ‘*’ field.

An example is given below, in the context of a CherryPy handler. This example is available in the download as

examples/layout02.py
import cherrypy
import yyafl
import yyafl.layout
from yyafl import fields
from yyafl.widgets import HiddenInput
 
# This example covers the user of custom decorators for required form fields
 
class Form1(yyafl.Form):
    name = fields.CharField(label = "User name", required = True)
    email = fields.CharField(label = "Your e-mail address", required = True)
    optional = fields.CharField(label = "Optional field", required = False)
    hidden = fields.CharField(widget = HiddenInput, default = "123")
    _layout = yyafl.layout.TableLayout()
 
class RequiredDecorator(yyafl.layout.NullDecorator):
    """ Draw a * next to all required fields """
    def extra_markup_widget(self, field, rendered_text):
        if field.required:
            return rendered_text + " * "
        return rendered_text
 
class FormTest(object):
 
    @cherrypy.expose
    def index(self, **kwargs):
        f = Form1(data = kwargs)
        # Add a global decorator
        f.layout().add_decorator('*', RequiredDecorator())
        content = ""
        content += "<html><body>"
 
        if f.is_valid() == False:
            content += "Errors: "
            for error in f.errors:
                content += error + " : " + f.errors[error] + "<br />"
        elif f.is_bound() and f.is_valid():
            content += "Thanks for the data!"
 
 
        content += "<p><form method=\"GET\" action=\"/\">"
 
        # Render using the layout specified in _layout above.
        content += f.render()
        # Or invoke the layout explicitly
        # l = yyafl.layout.TableLayout()
        # l.render(f)
 
        content += "<br /> <input type='submit' value='Submit' /></form>"
        return content
 
 
if __name__ == '__main__':
    cherrypy.quickstart(root = FormTest())

January 19, 2009

Current EVE-Central feature request list in Bugzilla

Filed under: EVE-Central — Yann @ 12:01 pm

I’ve been moving any e-mailed feature requests over to the bugzilla install over at bugs.stackfoundry.org. It helps me track the pile of e-mails into something others can view as well.

Feel free to continue to e-mail me any feature requests and bugs, or if you’d like you can enter them into bugzilla yourself. For status, if an item is RESOLVED it is fixed in code but not yet deployed on the production site. A CLOSED bug is deployed on the site.

If you don’t see your feature request here, feel free to send it to me again. Its obvious it fell into the wrong spot in my mailbox, and is now lost forever. :)

January 14, 2009

ptee – tee with shell expressions instead of files

Filed under: Software — Yann @ 11:53 pm

Have you ever wanted to use the UNIX shell utility tee, but instead of simply dumping to a file, invoke a series of subcommands that would run inside the pipeline? If so, I give you ptee, now available in version 1.0.

Edit: As people have pointed out, apparently you can do this in bash already (and this is specific to bash, lighter shells such as dash do not support it), using tee file redirects in subshells (tee >(subshell ) >(subshell ) ). Whoda-thunk. I guess its time for me to turn in my bash scripting license at the door. Either way, its here for your pleasure, if you’d like to use it with other shells beyond the much heavier weight bash :)

ptee extends the idea of tee by allowing not just filenames, but a whole shell expression (or command). For instance:

... | ptee "grep foo | zcat > outfile" | ...

The expression in quotes is passed to a new instance of the active shell (expressed by $SHELL), and the standard input to ptee is duplicated, both to normal standard output and to this new sub-shell (and any number of commands given to ptee). In effect, the sub-shell is running in parallel with the normal shell pipeline. The simplest case of running ptee is with no arguments, where it acts as an expensive version of the “|” operator. ptee accepts any realistic number of command line arguments, which are all launched and will receive a copy of the pipeline data.

There are of course some restrictions. The sub-shell standard output is thrown away; its simply not generically possible to try re-weaving it with the normal data flow. Also, ptee does not buffer large amounts of data internally, meaning the shell pipeline will run at the speed of the slowest sub-shell (if the slowest command is stalled, the whole pipeline will be stalled). ptee is however tolerant of sub-shells aborting early, and will continue passing data to any remaining outputs. Finally, sub-shell exit codes are ignored and not propagated to the main ptee exit code.

Now, there are likely to be bugs in this 1.0 release, but in some heavy processing tasks I’ve performed it has done admirably. ptee will compile on most POSIX like systems; I have tested both Linux (Ubuntu 8.04) and FreeBSD (7.1).

Feel free to grab the download here (available as a .tar.gz). The very simple C code is made available under an MIT license. It launches very quickly, and is very light weight, perfect for shell scripting.

I’d like to hear ideas you have for using ptee in your normal shell scripting activities. I know I am going to be cleaning up some ugly git post-receive hooks I have created in the past. How about you?

January 7, 2009

yyafl version 0.2.0 available for download

Filed under: Python,Software — Yann @ 12:56 am

Version 0.2.0 of Yann’s Yet Another Form Library is now available for download. I have been using this code in product for at least a month and felt it is pretty stable. You can grab it from the main site at stackfoundry.com or from the PyPI page.

yyafl is a partial reimplementation and adaptation of the Django ‘newforms’ library allowing it to exist outside of the Django infrastructure. It can be used in other frameworks such as CherryPy and Pylons. YYAFL provides:

  • Pluggable and skinnable forms, use either pure Python code or a compatible templating engine (such as Mako). Attach on the fly decorators (such as the ubiquitous red star to required form fields) or even apply whole layouts to forms.
  • Default properties can be added to the form object – for example, a default rendering layout can be chosen.
  • Comprehensive validation framework for many data types (which is easy to grow, similar in style to newforms)
  • Comprehensive widget collection, which is easy to grow, tweak, or extend for your application’s needs. (currently doesn’t support multi-widgets well, this wart will be fixed soon however)
  • Soon! Automatic CSRF managed forms – pass it a session store object and it can handle the rest by preventing cross site requests.

YYAFL uses some large chunks of the form-model and metaclass system that newforms used, and as such uses the same license as Django. Work is being done to refactor portions of this code to add some flexibility for multi-widget data fields (such as Date being split amongst several form fields), which were somewhat unclean in Django’s implementation.

Powered by WordPress