I’ve been playing with XML files recently and have on the odd occasion needed to validate a file against an XML schema. This is surprisingly easy using lxml, the Swiss Army knife of Python XML processing. Allow me to demonstrate.
>>> from lxml import etree
>>> schema = etree.XMLSchema(etree.parse('schema_file_name.xsd'))
>>> xml_file = etree.parse('xml_file_name.xml')
Job done. If you are unlucky enough that your file doesn’t validate you can find out by checking the error_log attribute of your XMLSchema object.
Due to a recent accounting error (on my part and in my favour) I recently found myself in possession of a netbook. I know that makes me a luddite and I should have bought a tablet. Call me a throwback. In my defence it was half the price of an iPad and a lot more practical for me. The major deal breaker for me is that iPad’s don’t come with a command line client and can’t (to the best of my knowledge) run the only editor worth having. Also, iPad’s don’t run free software and that is becoming more important to me. So I bought a netbook.
As it came with Windows installed my first task was to install a decent operating system. I’m a fan of Xubuntu so I grabbed the latest release and then … stopped. Because my first thought was to burn the Xubuntu .iso file to a disk and install from that, but my netbook doesn’t have a CD drive. I’ve never installed from anything else in the past so I was a bit stuck.
The good news is that it is 2011 and Google came to the rescue. After a couple of false turns, and via Pendrivelinux.com, I found the rather wonderful LinuxLive USB Creator. Whilst it isn’t an exhaustive test, and don’t come to me with your problems, I simply installed and started LiLi, pointed it at my USB stick and the .iso file I had downloaded and 10 minutes later I had a bootable copy of Xubuntu.
Some words of praise, too, for the (X)ubuntu installer folks who have made getting their operating system on a new machine a complete breeze. Thanks everyone, top job.
Now all I’ve got to do is install all of the software that I rely on, configure the thing and I can start using it. At my pace that should only take a week or two. I’ll be back then.
I was going to write an informed and opinionated piece about the use of proper tools in corporate IT departments. In particular I was going to say that I found it interesting that smaller, more cost conscious teams (in startups or open source projects) use more modern and sophisticated tools for issue management, project planning and code management than the big IT departments that I have the pleasure to work in.
But, well, I’ve got to go and write a status report showing the break down of issues by status, and that is going to take me about three and a half hours. So I don’t have time to faff about on my blog.
Instead, I’ll just paraphrase JWZ (who was apparently in turn paraphrasing an older comment about sed) and say;
Some people, when confronted with a problem think “I know, I’ll use a SharePoint list.” Now they have two problems.
I mean, a SharePoint list for issue management? When we could use Jira or FogBugz? I give up.
Before starting on some of the big changes planned for version 0.5, and thanks to patches and suggestions from various people I’ve addressed a couple of issues with Gerald 0.4. This means that we now have release Gerald 0.4.1
What’s new in this release? Not much, just some bug fixes, documentation changes and (hopefully) an egg that is installable on all platforms. The .egg files available from PyPI (and soon to be available on SourceForge) should install without any errors and if my testing is correct will be usable on multiple platforms including Windows.
Downloads are available at the PyPI page and the SourceForge project page. As always, please send me an email with any problems or suggestions for improvement.
Take a look at this excellent single page web site – Python strftime reference. It does exactly what it says on the tin. Good work.
I’ve been revelling in the Python goodness this weekend at PyCon Australia. This has motivated me to fix the last couple of issues and then package and release Gerald 0.4
What’s new in this release? The most important changes are fixes to a number of issues identified by users of SQLPython. Gerald was appearing to take a long time to collect large schemas but was actually failing silently. I added test cases to show the problem and then fixed the code. This shouldn’t happen any more.
I applied a couple of patches supplied by Catherine Devlin to cope with columns without defined lengths and to not get DBA objects in Oracle schemas.
I slipped in some new features as well; I implemented the
compare methods on the
CodeObject class, and Gerald now supports views in MySQL (as long as you are running 5.1 or above).
Finally, I changed the project documentation to use Sphinx.
Downloads are available at the PyPI page and the SourceForge project page.
If you find any problems or want to contribute any code just send me an email.
I wanted to quickly and easily convert a series of reStructured text documents into HTML equivalents. For reasons too dull to discuss here I couldn’t just use rst2html.py and didn’t want to go to the trouble of remembering enough bash syntax to write a shell script.
So I thought that as long as docutils is written in Python it would only take a moment or two to knock up a script to do what I needed. Well yes, and no. The script itself is fairly simple;
from docutils import core
for file_name in glob.glob(name_pattern):
source = open(file_name, 'r')
file_dest = file_name[:-4] + '.html'
destination = open(file_dest, 'w')
core.publish_file(source=source, destination=destination, writer_name='html')
The most useful line being the one where I call core.publish_file. But it wasn’t immediately obvious from the docutils documentation what series of incantations would achieve my desired results. Luckily, after some time spent perusing the documents I came across this dissection of rst2html.py. This, in turn, lead me to the description of the Docutils Publisher, which lists the convenience functions available to work with the engine.
The end result isn’t particularly elegant but it does get the job done and I thought I would share it in case anyone else has a similar need in the future.
I have just released version 0.3.6 of Gerald. Gerald is a general purpose database schema toolkit written in Python.
This release was at the request of the sqlpython project and contains only one change. A new convenience method connect has been added to the Schema class. This enables a schema to be initiated and then later have a database connection associated with it. Because this changes the public API of gerald I’ve released this under a new version number.
Development, bug and issue tracking and the project wiki are available on the project Trac site. Source code and distribution files are available at the sourceforge page.
The next release will be 0.4. Exactly what will make up that release is still evolving, although it is likely to feature SQL Server support as I have just started a new job and all of the systems there use it. To see what else is in the release and to track progress take a look at the version 0.4 roadmap.
Dear lazyweb, I unsubscribed from the distutils-sig mailing list a while back and consequently I’m not up to date with the latest to-ings and fro-ings. But, I have a problem. As reported by someone today Gerald eggs won’t install on Windows.
Everything is fine on my Ubuntu virtual machine, but on my shiny new work laptop I have Python 2.6 and today I downloaded and installed setuptools version 06.c11. When I try and install Gerald I get an error complaining about a lack of a setup.py file;
(TEST) C:WorkvirtualenvsTEST>easy_install gerald
Searching for gerald
Best match: gerald 0.3.5
error: Couldn't find a setup script in c:docume~1andy~1.todlocals~1tempeasy_install-woqly0download
The only thing that I can find different is that my Ubuntu virtual machine is running version 0.6c9 of setuptools. Has the function changed between two release candidates?
Needless to say this means that Gerald won’t install under Windows using easy_install until I figure this out. All help and suggestions warmly received.
I’ve always said that the appeal of any operating system – for me – is that I can fire up a terminal window and tinker around. When I say that many people look at me like I’ve got rocks in my head. But I’m glad I am not alone.