Tao of the Machine

Programming, Python, my projects, card games, books, music, Zoids, bettas, manga, cool stuff, and whatever comes to mind.

Macros!

Kaa-macros, baby. Kaa-macros.

As seen on diveintomark... I present a stunning example of "me, too" software development. <wink> Inspired by the aforementioned post, I decided to hack up a simple macro system for Kaa. If MT can do it, so can we. Kaa-macros, baby. Kaa-macros. ;-)

As a test, I defined an acronym or two, which should now be included automatically. GPL is one such acronym. Position your mouse over it to see the effect of the <acronym> tag. (It works on IE5.5, at least.)

You can now define a file htmlmacros.txt with lines like this:

("GPL", "acronym", "title", "GNU General Public License")
("MT", "acronym", "title", "Movable Type")
Those are Python tuples, and will be treated as such upon loading.
See Mark Pilgrim's post for an explanation about how this works... it's basically the same, the 4-tuple consists of (literal, tag, attribute, value). After rendering all the HTML, Kaa loops over its macro list, replacing the literals with something like literal. Simple, but effective, although it doesn't always work well. Maybe I'll refine the code a bit, maybe I'll add another, more complex macro system, using regular expressions for example. A powerful macro system should be able to replace basically anything.

Of course, Python itself can be used for this as well. Just define a bunch of Python strings (or other values, but strings seem most appropriate), then use them like this:

<% foo %>
to expand them to the value of variable foo. This is useful for often-used URLs, strings, or anything else that you don't want to type over and over again. Trivial to add, too. Maybe in the next release...

Posted by Hans Nowak on 2002-08-16 01:14:21   {link}
Categories: Kaa

In visible silence

Interesting new features were added to Kaa today. First of all, I coded a basis for entry attributes. Right now it's still rudimentary; showing an entry's attributes just prints a dictionary to stdout, and the only attribute that can be set is visible.

The effects are kind of obvious... a message with the visible attribute set to 0 (or any value that evaluates as false, for that matter) becomes "invisible", i.e. it doesn't show up in HTML anymore. Not in archives, and not on the front page.
If the attribute isn't defined, visible == 1 is assumed, of course... we would not want all entries to be invisible by default. :-)

A nontrivial overhaul of some crucial code was necessary to make this work smoothly. More attributes will be added later. This feature will also pave the way for categories and such...

Posted by Hans Nowak on 2002-08-16 01:04:09   {link}
Categories: Kaa

New upload mechanism implemented

The new version is 0.6. It's not available for download yet... I have to test for bugs and stuff. But, it basically does what I described in the earlier message. No new files are generated if it's not necessary. And files older than the last publish_date are not uploaded.

Of course, you can disable these features by setting the appropriate options in the bloginfo dialog.

Posted by Hans Nowak on 2002-08-13 23:30:01   {link}
Categories: Kaa

time.struct_time

Just learned something new... in Python 2.2:
>>> import time
>>> time.struct_time
<type 'time.struct_time'>
>>> t = time.localtime(time.time())
>>> t
(2002, 8, 13, 23, 11, 54, 1, 225, 1)
>>> type(t)
<type 'time.struct_time'>
In Python 2.1, though:
>>> import time
>>> time.struct_time
Traceback (most recent call last):
  File "<pyshell#1>", line 1, in ?
    time.struct_time
AttributeError: 'time' module has no attribute 'struct_time'
>>> t = time.localtime(time.time())
>>> t
(2002, 8, 13, 23, 13, 3, 1, 225, 1)
>>> type(t)
<type 'tuple'>
Hmm. I didn't know this changed. I was under the impression that this was still just a 9-tuple. I wonder why it changed? No doubt the answer can be found in python-dev somewhere...

Posted by Hans Nowak on 2002-08-13 23:13:58   {link}
Categories: Python

An interesting problem...

I was going to restrict the number of uploaded files by using the following method:
  1. Don't generate a new file if the older version is exactly the same.
  2. Store the publish data somewhere.
  3. Any files newer than the publish date are uploaded.
In theory, this should work well... if the new file is still the same as the old one, then it's not overwritten, and thus it will have (keep) a date before the last publish date, and it will not be uploaded the next publishing round.
Of course, if you change the template, or the Kaa version changes, etc, then you're out of luck, because all pages will be different. But that should not happen too often.

In practice, I have code in my template that looks like

<#
import date
print date.Date().isodate() + "."
#>
The posting date is inserted, and of course this will be different every time something is posted. In other words, new files are generated all the time, cancelling out the possible benefits of the slick upload trick.

I guess the "solution" is, that I remove that date. Whoever wants something like this, can use it, but will not be able to have the upload benefit.

Posted by Hans Nowak on 2002-08-13 22:49:19   {link}
Categories: (unclassified)

State of the Kaa

Let's see how much Kaa can do compared to its peers... based on the comparison table from BlogComp. (I better use a smaller font, because this may be a lot of text... :-)

1. multiple blogs? Yes. You can make as many blogs as you like.
2. team blog? Not yet.
3. blog search? No. Kaa is client-based, and it would be difficult to implement something like that. Server-based programs have a leg up here. I know there are some services out there that can do a site search, but it's not something Kaa does.
4. templates? Of course. Unless they mean if the blogging tool comes with templates by default. Kaa does, but they're very terse and only meant as a sample. This may change in the future though.
5. multiple templates? Only two per blog. I have to find out what they mean here...
6. remote templates? No. Again, Kaa is client-based.
7. Post via browser? No. You post through the Tkinter client application.
8. Post via desktop? Yes.
9. One click posting? Not yet, but it's trivial to add, so we might as well make this as yes.
10. Blogger API? No.
11. MetaWeblog API? No.
12. Friendly links? Dunno, what are those?
13. Formatting buttons? Yes, and people can add custom ones.
14. Spell check? No, and there probably won't be one in the future.
15. Draft? Depends on what this means. If it means something like, posting and previewing before publishing, then the answer is yes.
16. Post to future? No. When an entry is posted, it gets the date of that moment.
17. Extended entries? What are those?
18. Excerpts? What are those?
19. Ping weblogs.com? No.
20. Email notification? No, and doesn't really make sense for a client-based blog.
21. Email entry? No. Although I suppose it would be possible to run Kaa continuously on a server and make it scan and pick up emails... but I digress... Kaa is not server based and probably never will be.
22. RSS generation? No. When I know more about RSS, I will be able to say something sensible about whether Kaa will/can grow it in the future.
23. Categories? Not yet, but I'm working on it.
24. Multiple categories? Ditto.
25. Comments? No, but those can be added with a rateyourmusic account.
26. IP banning? n/a
27. Karma voting? No voting whatsoever.
28. Polls? Ditto.
29. Daily archiving? That, and more.
30. Weekly archiving? Certainly.
31. Monthly archiving? Yes.
32. Individual entry archiving? Yes.
33. Archiving by category? Probably, once categories are supported.
34. Archiving by author? Ditto, once multiple authors are supported.
35. Automatic permalinks? Yes, if you add that to your template. The code is there (entry.anchor attribute).
36. Calendar? Not yet, but I'm thinking about it... but it's not high on my priority list.
37. Edit dates after post? You can't really edit a date, but when you update an entry, its modified_date is set.
38. International dates? Not directly, but you can give the date pretty much every format you want. Maybe I can add some custom routines for that later.
39. Timezone offset? No, the date is local time.
40. Registration? Nope.
41. Account activation? Nothing to do with accounts.
42. Access levels? No.
43. Member profiles? No.
44. Import from blogger? No. (How would we do that? Scan the Blogger-generated HTML files?)
45. Import from greymatter? No.
46. Import from Manila? No.
47. Export? Not yet, but I'm thinking of an option that dumps the entries in some kind of text file format... e.g. pickled, XML, or something else.
48. Backup? Sure, copy your db_ directory wherever you want. <0.1 wink>
49. Image posting? Not sure what they mean here, but you can upload any image by copying it to the html_ folder.
50. Automatic thumbnails? No.
51. Alternating post colors? Possibly if you write your template so that it uses a different color based on the entry.count attribute.
52. Mailing list? No.
53. Hit counter? No, unless you use one of those hit counter services in your template. Kaa doesn't do anything for it as-is. Again, it's client-based, so it doesn't have a clue who reads your blog, when, how many times, or what their IP is. If this is important for you, Kaa probably isn't the right choice. :-/

There's still a lot of work to do, but we're getting there...

Posted by Hans Nowak on 2002-08-11 00:43:14   {link}
Categories: (unclassified)

Uploading

Currently, everything in the HTML directory is uploaded. This feature is very handy; you simply throw in a file, and it's uploaded the next time you publish. It also has a drawback though: when your blog grows bigger, it becomes cumbersome and slow to upload all files again and again whenever you write a new entry.

So, what to do about that? It would be nice if only files that have changed were uploaded. Files that didn't change since "last time" should be ignored.
I don't know if I can make that work... how do we find out if the file on the FTP server and the local file are the same? Maybe I can check the date, but if that isn't possible, we have a problem. It defeats the purpose to download the file. :-) Checking on size alone is possible but not enough; that way, an updated file would not be uploaded if it happens to have the same size as the old one.

If a "post" command writes all the new files it generates, then they will all be uploaded. So, it needs to be more selective... if the generated HTML is exactly the same as an existing local file, then the new file should not be written.

Let's see if I can make this work...

[9:54 PM] Obviously it doesn't work. The dates on the server indicate when the file was written; they're not a copy of the dates of the local files. I should have known that.
A better solution might be, what Blogger does... or something like that. What if I offered two publish options: 1. publish all, and 2. publish only the first page and the latest archive? I do think that "post" should generate all files anew... even if you have a megabyte of blog text, that should only take a few seconds at most, probably less.

Later, there should be another publishing option, something that says, "make sure the files in the HTML directory are all uploaded, and any files on the server that are not present locally are removed". This should be useful for clearing out obsolete files and such.

Posted by Hans Nowak on 2002-08-10 21:39:28   {link}
Categories: (unclassified)

0.5.2

Kaa 0.5.2 is released under the GPL. Download it here (zip file).

I said it before and I'll say it again: At this stage, Kaa is not quite suitable for serious weblogging. Although it's getting there.

Version 0.5.2 has the following features:

  • Using Python, Tkinter, and gadfly database (included)
  • Archiving in various ways: per N days, per N entries, monthly
  • Everything in HTML directory is uploaded automagically
  • HTML editing allows for insertion of common and/or custom tags, URLs, quoting/unquoting HTML
  • Toolbar and keybindings can be customized; insert "macro" text or wrap your favorite HTML tags around something
  • Embed Python code in your messages and templates
More to come...

Posted by Hans Nowak on 2002-08-10 13:39:12   {link}
Categories: (unclassified)

En dan dit...

I also souped by my template today... I think it looks better, but YMMV...

Also added a list of archives. There's a nifty little method that generates this list, blog.archive_list(), but such a list can of course be generated by hand too.

Also added some new fields in the bloginfo options. You can now set the number of entries for the front page, and set a default author.

As it is, Kaa 0.5.2 (the current version, obviously) is already an acceptable blogging tool, methinks. If you're willing to settle for something that doesn't support multiple users or categories (yet), then it may be suitable for you, too. However, I still consider it pre-alpha (who knows what is going to change in the near future), so use with caution. I don't think the database is going to change anymore, but you never know...

Posted by Hans Nowak on 2002-08-10 00:21:13   {link}
Categories: (unclassified)

Anchors

In many blogs, people can link to messages directly. Kaa now supports this as well. Of course, it's all a matter of putting the right things in the template.

First, create a HTML anchor. For any message, Kaa expects the anchor to be "e" + the id of the message. Like this:

<a name="e<% entry.blogentry_id %>"></a>
Then, use entry.anchor to make a clickable link to the anchor:
<a href="<% entry.anchor %>">#</a>
That's all. For an entry in the archives, the .anchor attribute points to itself. For an entry in the first page, it points to the archive (if any), otherwise it points to itself. The latter is not very useful since the link may disappear with the message. Any external links to that message will then become invalid.

All this isn't thoroughly tested yet... I don't know exactly if it all works with other archive methods (like by ID), or no archives.

Posted by Hans Nowak on 2002-08-10 00:06:48   {link}
Categories: (unclassified)

--
Generated by Firedrop2.