darkness

Monday, 30 April 2007

html2markdown updated

darkness @ 00:14:40

I just uploaded html2markdown 0.3. This changes list item indentations (hanging indent, indentation of multiple paragraphs in a list item) and hopefully handles raw HTML (i.e., HTML that is not possible to generate with “Markdown markup,” at least in Markdown.pl) better.

I’ve got a few things I want to do to html2markdown before I announce it on the Markdown list:

  • Make a setup.py for it
  • Maybe clean up test cases, since they’re currently rather non-standard in how they’re generated and run (maybe I could depend on python-markdown instead of Markdown.pl being in the path and executable)
  • Check to make sure it has a sane interface when used as a library (import html2markdown; print html2markdown.convert("---"))
  • Make a nicer web page for it

There may be a few more code cleanups too.

By the way, thanks to Karl Mowatt-Wilson for pointing out that html2markdown and python-markdown don’t get together too well sometimes. That led to the changes in indentation and maybe another fix or two in html2markdown, and I also filed several bugs with python-markdown where it differs from Markdown.pl.

Monday, 23 April 2007

A Pylons/Genshi skeleton from scratch

darkness @ 15:33:27

There are a billion other sites that tell you how to do this. Still, I hope this page will at least be useful to me in the future when I want to quickly make a “web application” with Pylons.

I use virtual-python.py to make a private Python installation. This way I don’t have to worry about touching system files, mucking up libraries other applications need, etc.

~ $ cd tmp
tmp $ wget --quiet http://peak.telecommunity.com/dist/virtual-python.py
tmp $ mkdir myapp
tmp $ cd myapp
myapp $ python ../virtual-python.py --prefix=$PWD/py
Creating /home/darkness/tmp/myapp/py/lib/python2.4
Creating /home/darkness/tmp/myapp/py/lib/python2.4/site-packages
Creating /home/darkness/tmp/myapp/py/include/python2.4
Creating /home/darkness/tmp/myapp/py/bin
Copying /usr/bin/python to /home/darkness/tmp/myapp/py/bin
You're now ready to download ez_setup.py, and run
/home/darkness/tmp/myapp/py/bin/python ez_setup.py

Install all the basics. easy_install is noisy, and Pylons pulls in a bunch of stuff, so I’ve trimmed the output considerably. (Also, I used ez_setup -U setuptools below because I’ve got the Fedora package python-setuptools installed, but it’s not the latest version (I think). You may or may not need -U; I don’t know if -U causes errors if the package isn’t already installed.)

myapp $ wget --quiet http://peak.telecommunity.com/dist/ez_setup.py
myapp $ py/bin/python ez_setup.py -U setuptools
Installed /home/darkness/tmp/myapp/py/lib/python2.4/site-packages/setuptools-0.6c5-py2.4.egg
myapp $ py/bin/easy_install Pylons Genshi Buffet
Installed /home/darkness/tmp/myapp/py/lib/python2.4/site-packages/Pylons-0.9.5-py2.4.egg
[ Omitted a bunch of packages installed for Pylons: Mako, nose,
  decorator, simplejson, FormEncode, Myghty, PasteScript, PasteDeploy,
  Paste, Beaker, WebHelpers, Routes, MyghtyUtils ]
Installed /home/darkness/tmp/myapp/py/lib/python2.4/site-packages/Genshi-0.4-py2.4.egg
Installed /home/darkness/tmp/myapp/py/lib/python2.4/site-packages/Buffet-1.0-py2.4.egg

Now I create my application.

myapp $ py/bin/paster create -t pylons myapp
Selected and implied templates:
  Pylons#pylons  Pylons application template

Variables:
  egg:      myapp
  package:  myapp
  project:  myapp
Creating template pylons
Creating directory ./myapp
[ ... whole bunch of stuff happens to install the template ... ]
myapp $ cd myapp

Note the directory structure is weird:

  • ~/tmp/myapp is where I made my virtual Python.
  • ~/tmp/myapp/myapp is the directory paster created. It is now basically the root of your project: it contains the configuration files, setup.py, ez_setup, and…
  • ~/tmp/myapp/myapp/myapp is your new web application as a Python package named myapp.

Now I want to set Genshi as the default template engine. http://docs.pythonweb.org/display/pylonscookbook/Genshi+templates has a good recipe for this (and more): edit myapp/config/middleware and add template_engine='genshi' to the config.init_app(...) call. (Remember myapp here refers to ~/tmp/myapp/myapp/myapp! Think myapp.config.middleware if it helps.)

To test this, I recommend a small modification to controllers/template.py. Make it read something like:

myapp $ cat myapp/controllers/template.py
from myapp.lib.base import *

class TemplateController(BaseController):
def view(self, url):
    """
    [omitted long docstring]
    """
    if g.pylons_config.app_conf.get("debug", True):
            return render_response(url)
    else:
            abort(404)

WARNING! This will happily try to display any template based on the path given in the HTTP request, if there is no better match (i.e., a controller)! It assumes debug is on if it’s not set! This seems to be the default behavior in Pylons in general (see development.ini which requires you to uncomment debug when you put an application into production). Feel free to change True to False and set debug = true in development.ini instead.

To see what I mean when I say it will “happy try to display any template,” lets make a Genshi template and view it. Your templates directory needs to be a Python package for Genshi to use it, hence the __init__.py.

myapp $ touch myapp/templates/__init__.py
myapp $ cat > myapp/templates/test.html
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/">
    <head>
        <title>This is a test</title>
    </head>
    <body>
        <p>
            This is a test: ${7 * 6} should be 42.
        </p>
    </body>
</html>
^D

We’ll start Pylons with the development.ini configuration file, and in auto-reload mode. This is how I use it most of the time when I’m hacking on a Pylons application. (I’m going to symlink the virtual Python root (py) into ~/tmp/myapp/myapp since ~/tmp/myapp isn’t real useful now. If I weren’t so lazy I’d just change ~/tmp/myapp/myapp to be ~/tmp/myapp.)

myapp $ ln -s ../py .
myapp $ py/bin/paster serve --reload development.ini
Starting subprocess with file monitor
Starting server in PID 29673.
serving on 0.0.0.0:5000 view at http://127.0.0.1:5000
# Elsewhere...
~ $ lynx --dump http://localhost:5000/test

   This is a test: 42 should be 42.

Note that, because of my changes to myapp.controllers.template, Pylons happily served up the template named test. So if you use the above changes to the template controller, be very careful who gets to hit the Pylons server when debug is not False.

Friday, 13 April 2007

Vista backup kind of sucks

darkness @ 13:19:40
clipped from www.pcpitstop.com

Unfortunately, this is where the feature-cleavers in Microsoft’s marketing department went crazy. Even though the Home Basic and Home Premium versions of Vista are backing up all files including user data files, users can’t access the backups of their own data. Want proof that the backups are there? Use Microsoft’s Windows Anytime Upgrade feature to upgrade from Home to Ultimate. When we did that, the Previous Versions tab appeared and revealed changes to data files that were made before the upgrade occurred.

There is perhaps one other option, suggested by my business partner Charlie “Knuckles” McGee: Windows Vista Document Ransom Edition. That would add just the Previous Versions feature, for a “minimal” fee. After all, you have such nice-looking documents…it would be a shame for anything to happen to them.

I played with Vista Ultimate on a new laptop the other day, and the first thing I wanted to do was to back up a system image. Come to find out, the built-in “complete PC backup” won’t backup to a network drive. Very useful. After that, and reading the above article, I just don’t expect I’ll ever bother with Vista’s built-in backup features, unless they receive a heavy dose of features and configurability in a future service pack.

Thursday, 12 April 2007

AACS in action

darkness @ 18:38:55
clipped from opinion.latimes.com

On Friday, Corel informed WinDVD users that they had to download a “security update” in order to continue playing high-definition discs. They’ll have about three months to do so; after that, all newly minted high-def discs will include a set of instructions that permanently disables the older, hacked version of the software. Users who put one of these new discs into their PC will not be unable to play that disc, but they’ll render the software incapable of playing any other high-def Hollywood movie — even the older ones in their personal collections. Ouch!

You can check out Wikipedia’s AACS entry if you want some more information on AACS. If I recall correctly, the way this works is that all computer drives that can read content (discs in this case) protected with AACS have to have some NVRAM in them. When a disc is inserted the drive–the actual hardware, mind you–scans a certain area of the disc to read a list of revoked player keys. Now, when the software player wants to talk to the disc drive, it has to identify itself with some encryption (and the drive also identifies itself back to the software, I think). So if you put a new disc in the drive, and that disc says your player’s key is revoked, that drive will never again speak to a software player that identifies itself with that revoked key. Pretty cool. (Assholes.)

Saturday, 07 April 2007

The perceived value of brevity

darkness @ 15:18:24
clipped from blog.guykawasaki.com

As a rule of thumb, if you can’t pitch your company in ten slides or pitch yourself in one page, your idea is stupid and you suck, respectively.

In many cases — most, even — I expect this is true. I suppose it’s humorous because Mr. Kawasaki does not admit the existence of great ideas that are simply hard to explain. (Maybe some physicists or molecular biologists or can chime in with exceptions to his rule.) (Attention physicists and molecular biologists: if you are reading this, you seem to be lost.)

(As an aside, I’m trying Clipmarks for posting all the little amusing or interesting things I find while perusing the Interpipes.)
Next Page »

Powered by WordPress