$ python
Python 2.5.2 (r252:60911, Dec 1 2008, 17:47:46)
[GCC 4.3.1 20080507 (prerelease) [gcc-4_3-branch revision 135036]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import this
The Zen of Python, by Tim Peters
Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
>>>
Wednesday, March 11, 2009
import this
Tuesday, March 10, 2009
Magazine Heaven
My favorite Linux magazine, Linux Format (out of the UK) has some interesting news:
- A very nice podcast, which can be found at Tux Radar. Three editors talk about a wide range of Linux subjects. I have been finding it very entertaining, even if they don't have their RSS feed tags quite set up correctly.
- They offered up a free download of their issue 116, the KDE issue. The zip file with the 3 torrents (hires, lowres, and ISO) for it is here. Very nice job!
- And most excitingly, as they announced at the end of their latest podcast, a deal on the subscription! It's hard to justify the US$130 in these tough economic times, even if it is the best Linux magazine going. But if you follow this link, you can subscribe for "only" US$95, which is a pretty good deal for 13 issues. Linux Format sub deal
Every issue is just jammed packed with great info, from news to in depth technical tutorials. I love the mix of articles, and I love the layout. Very clean look, well edited and good stories. I highly recommend it!
Linux Journal also recently had a special ($12 for 12 issues) but I'm pretty sure that was just a day long one. However, they do have a contest to give out some free subscriptions to the digital version. You can get more details here.
Thursday, February 26, 2009
Stale Lock
I did a bad thing the other day and have just barely lived to tell about it. I turned of my Linux box without shutting down. All you Linux & Unix veterans know my horror when I realized what I had just done. I hit the shutdown button and, when the screen briefly blanked out before going into the shutdown graphic, I hit the power button on my power strip to turn it all off. Oh oh, says I...
Now, I never used to shut off my machine(s). The only time I have ever had a hardware problem (he says, knocking on wood), is when I was turning on a machine. Given that, and some daemons that like to run in the background at night, I usually left my computers turned on.
But I have started to get more worried about power consumption, including 'zombie' electronic devices, I have started to power down all the computers in the house before I head to bed. It makes me feel all virtuous and green. But the other night I nearly paid dearly for my greeness.
When I turn the computer on the next morning, it booted to a text screen. Somehow, I just wasn't surprised. But I couldn't figure out why. dmesg told me nothing, nor did /var/log/messages. But when I tried to 'startx', I got a complaint about .X0.lock and a "stale NFS handle". How odd, as I don't use NFS at all.
Well, this file proved to be very difficult to get rid of. See, when your X server starts up, it creates this file to prevent X from running twice. So at startup, it checks to see if /tmp/.X0.lock exists. If it doesn't, X will create it and carry on its merry way. If it does, it assumes X is already running and will complain, albeit in a very obscure fashion. The usual solution, if you're sure there isn't a X server already running, is to just delete it. But 'stale NFS handle' files are a real pain to delete, especially if they aren't really NFS handles!
I had an inkling that I needed to run fsck on the partition, but that's a problem on the root partition. Luckily, I have several other Linux partitions I can boot into, so I just booted up my openSUSE 11.1 and tried fsck from there. Haven't made the jump to 11.1 yet, as too many of my packages don't quite work right, or I don't like the newer versions (I'm talking to you, Eclipse Ganymede and Amarok 2). But fsck
didn't find anything wrong either, so I was stuck for ideas.
But then I read about the force option for e2fsck, so I ran that. Voila! A few odd errors, but most especially an odd error with .X0.lock. So I mounted the filesystem while still in 11.1 and was finally able to delete the .X0.lock file. And the reboot back into my 11.0 openSUSE went swimmingly!
So the lessons learned:
- If X won't start, try removing the lock file found at /tmp/.X0.lock
- If you can't remove a file because there is a bogus 'stale NFS handle' error (and believe me, it doesn't let you do anything with it), try forcing an fsck on the partition
Wednesday, February 25, 2009
Big Bad SATA
So Best Buy had the much maligned Seagate 7200.11 Barracuda 1.5 terabyte hard drive on sale for a mere US$130. Given a couple of Best Buy rebates, I just couldn't resist picking it up for just a little of US$120 - incredible! I immediately went to the Seagate page to see if my drive had a firmware update, but luckily(?) it didn't so I was all set to install it.
Man, I just love the SATA connectors! Gone are the days of bending one of the gazillion little pins, or, even worse, getting it plugged in backwards. And no more slave/master settings either. Slid it into my tower, plugged two small cables into it and fired up the machine. It was immediately noticed and so now I needed to figure out how to partition it.
I created one 650gb partition for backups. I really truly am going to get a backup strategy implemented, especially now that my wife has her own laptop and is working from home. I'm going to run a Bacula server on my machine and Bacula clients on my box, my work box (WinXP) and my wife's Vista laptop. So I want to have plenty of room for storing select backups. I created this as an ext3 partition, with no access time tracking (for performance reasons), using YasT2's very easy Partitioner.
The other partition was a little more problematic. I want it to be the home for all our media - songs, movies, pictures. And I'll run a media server here. I have had real good luck with Mediatomb but Andrew Wafaa convinced me to try Coherence, a true DLNA/UPnP framework. It looks pretty neat - great, just what I need another project!
I wanted my media partition to be readable by WinXP as well as my openSUSE (and, in general, Linux) boots. I just checked so I know differently now, but I also thought that sharing a volume via Samba would require it to be a Windows partition as well. Turns out, that is a by now obvious bad conclusion, as Samba will share Linux partitions just fine. But as I wanted to use it natively as well, I still needed a Windows partition.
I was shying away from an NTFS partition, as I just wasn't sure how stable the NTFS-3G implementation was, so I started with a FAT32 partition. The biggest drawback with FAT32 is its 4gb max file size. It is also, I think, less efficient than NTFS in its structure, so it would use more space for such a large (nearly 750gb) partition. Once again, the Yast Partitioner worked great and was nearly instantaneous for FAT32 (or vfat) partition.
Now I wanted to move my ripped music CDs over to the new "mediax" partition (I couldn't use /media, as KDE uses that). As I wanted to preserve the time information, I used rsync:
$ rsync -auv Music /mediax
[lots and lots of]
/bin/cp: preserving times for `/mediax/Music/podcasts': Operation not permitted
That was odd. So without thinking about it too much, I decided to take the plunge and try out NTFS, as openSUSE 11 comes with read/write support "out of the box". So I reformatted it as NTFS (after rebooting into Windows, as Partitioner doesn't format NTFS) and tried again.
This time, it worked pretty well. openSUSE uses the "standard" NTFS-3G driver. There is an odd caveat about a slowdown with Amarok, my prefer music player, but it seems to have to do with writing, not reading, which I don't do much, so no big deal.
But I ran into a problem because of my change of heart. Because I had originally formated it with FAT32 (vfat) using the Partioner in YaST (openSUSE's graphical admin tool), and because Partioner doesn't support NTFS formating, I forgot to change the /etc/fstab file, so on reboot, it didn't work correctly. I then compounded errors by changing the 3rd column to being merely 'ntfs', which meant I was still getting the weird cp "Operation not permitted" error, which had me really confused. But I checked out swerdna's page on using NTFS on Linux and finally the light dawned on Marblehead. I changed the filetype to 'ntfs-3g' and now all is good and I can use my music collection whether I'm in Linux or (shudder) have to reboot into Windows.
Monday, January 26, 2009
Feeding The Monster
I have many different Web 2.0 personas and I'd love to pull together all the various postings and updates I do into one stream and display that. Of course, this all has a name and it is Lifestreaming. Personally, I think it is a dumb name. I like the web, and do a lot of things on the web, but trust me, it ain't my life. I prefer to call it "Webstreaming".
For the most part, Webstreaming is based on RSS feeds. But it's a complicated thing to do, as nearly every feed has some customization required to get it to display correctly. There are links, text, microblogs, audio, video, etc. There are s few sites that try to do it for you, but of course for us geeks, it has to be self hosted.
So I downloaded and installed Sweetcron, a PHP-based blog software. There are some really interesting implementations of this, most especially Tom Beardshaw, who does a lot of work on it. Unfortunately, it does require a lot of customization, done all in PHP, which is no longer a favorite language of mine. I used to like it, but now find it too idiosyncratic and prone to code breakage. I do have a rough version of it running on my new domain, IHieronym.us (I use the nom de plume Hieronymus on a few Web 2.0 sites).
As I really would rather do something in Python or, even better, Django, I went on a quest. As I said, most social media sites will report activity via an RSS stream, so I needed to find a python-based RSS parser and the most common one seems to be the Universal Feed Parser, which can deal with nearly any kind of RSS / Atom feed.
But on top of that I found Feedjack, a full blown feed "aggregator" built using both Django and Feedparser! Pretty cool stuff, although installation is a very strange thing. I'm not intimately familiar with python or Django installation issues, and found it weird how the feedjack page talks about "your Django", as Django is a library, not an installation. But what they really mean is "your Django project". So, after getting Feedparser and Feedjack installed (for openSUSE, I installed Feedparser via YaST & Feedjack via the python setup.py install
process, while I on my FreeBSD box I was able to find both of them in the ports), I did the following basic steps to get a Feedjack site up and running:
$ django-admin.py startproject ihieronymus
$ cd ihieronymus
$ ls
__init__.py manage.py settings.py urls.py
__init__.pyo manage.pyo settings.pyo urls.pyo
[ after editing setting.py and urls.py as suggested here to add the admin site ]
$ python manage.py syncdb
Creating table auth_permission
Creating table auth_group
Creating table auth_user
Creating table auth_message
Creating table django_content_type
Creating table django_session
Creating table django_site
Creating table django_admin_log
You just installed Django's auth system, which means you don't have any superusers defined.
Would you like to create one now? (yes/no): yes
Username (Leave blank to use 'jdarnold'):
E-mail address: jdarnold@buddydog.org
Password:
Password (again):
Superuser created successfully.
Installing index for auth.Permission model
Installing index for auth.Message model
Installing index for admin.LogEntry model
$ sudo python manage.py runserver 207.22.41.217:80
Password:
Validating models...
0 errors found
Django version 1.1 pre-alpha, using settings 'ihieronymus.settings'
Development server is running at http://207.22.41.217:80/
Quit the server with CONTROL-C.
[26/Jan/2009 13:05:31] "GET / HTTP/1.1" 404 1921
^C
$
So at this point, we have a very basic djano site with the admin part all setup. Now we need to add in the Feedjack values into the settings.py file:
MEDIA_ROOT = '/www/data/'
MEDIA_URL = 'http://www.myserver.com'
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.admin',
'feedjack',
)
Now I need to create a link to Feedjack's static images on my 'regular' web server. Remember, the builtin Django debug server doesn't serve up static images and pages, so you need host them somewhere else. Also, on many Apache sites, it won't allow serving up pages outside of the Apache folders, so you may have to copy the folder into the Apache data folder rather than just using a symbolic link.
$ sudo ln -s /usr/local/lib/python2.5/site-packages/Feedjack-0.9.16-py2.5.egg/feedjack/static/feedjack /www/data/feedjack
Now we should be able to run syncdb to add in Feedjacks db files:
$ python manage.py syncdb
Traceback (most recent call last):
File "manage.py", line 11, in
execute_manager(settings)
File "/usr/local/lib/python2.5/site-packages/django/core/management/__init__.py", line 340, in execute_manager
utility.execute()
File "/usr/local/lib/python2.5/site-packages/django/core/management/__init__.py", line 295, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python2.5/site-packages/django/core/management/base.py", line 195, in run_from_argv
self.execute(*args, **options.__dict__)
File "/usr/local/lib/python2.5/site-packages/django/core/management/base.py", line 221, in execute
self.validate()
File "/usr/local/lib/python2.5/site-packages/django/core/management/base.py", line 249, in validate
num_errors = get_validation_errors(s, app)
File "/usr/local/lib/python2.5/site-packages/django/core/management/validation.py", line 28, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/usr/local/lib/python2.5/site-packages/django/db/models/loading.py", line 128, in get_app_errors
self._populate()
File "/usr/local/lib/python2.5/site-packages/django/db/models/loading.py", line 57, in _populate
self.load_app(app_name, True)
File "/usr/local/lib/python2.5/site-packages/django/db/models/loading.py", line 72, in load_app
mod = __import__(app_name, {}, {}, ['models'])
File "/usr/local/lib/python2.5/site-packages/Feedjack-0.9.7-py2.5.egg/feedjack/models.py", line 19, in
class Link(models.Model):
File "/usr/local/lib/python2.5/site-packages/Feedjack-0.9.7-py2.5.egg/feedjack/models.py", line 20, in Link
name = models.CharField(maxlength=100, unique=True)
TypeError: __init__() got an unexpected keyword argument 'maxlength'
$
Darn, not quite there. This 'maxlength' problem is usually indicative of some kind of Django version mismatch. And yup, the Freebsd ports version of Feedjack is 0.9.7, while the Django version is 1.1 pre-alpha. So I grabbed and installed Feedjack v0.9.16 and now:
$ python manage.py syncdb
Creating table feedjack_link
Creating table feedjack_site
Creating table feedjack_feed
Creating table feedjack_tag
Creating table feedjack_post
Creating table feedjack_subscriber
Installing index for feedjack.Post model
Installing index for feedjack.Subscriber model
$
Spot on! Now when I run the server and go to the admin web page, I see Feedjacks new entries. Next is to try and decipher the obscure references for how to grab new feeds, as Feedjack is pretty tied to its paradigm of grabbing feeds from other People. First you add a "Site", which basically defines what your site is going to look like. Then you add some feeds, giving it the RSS url. Unfortunately, it isn't nearly as good at figuring out the correct RSS URL as is Sweetcron and many Web 2.0 sites make it far too hard to track it down. Then you need to add a "Subscriber", which links the Site to the Feed. All of this is because you can have multiple "Planets" hosted with a single Feedjack installation, but it seems to me to be overkill, as most sites, including all the ones I looked at in their links, only have one.
Now that you have a few sites, you run the feedjack_update.py
script to go get the RSS feeds and drag them in. This requires a little bit of environment dancing around, as otherwise it can't find the Django info it needs:
$ pwd
/home/jdarnold/django/ihieronymus
$ export PYTHONPATH=/home/jdarnold/django
$ export DJANGO_SETTINGS_MODULE=ihieronymus.settings
$ feedjack_update.py
* BEGIN: 2009-01-26 14:43:49.014353
[2] Processing feed http://anaze.tumblr.com/rss
[2] Processed http://anaze.tumblr.com/rss in 0:00:00.341290 [ok] [new=0 updated=0 same=20 error=0]
[1] Processing feed http://linuxlove.tumblr.com/rss
[1] Processed http://linuxlove.tumblr.com/rss in 0:00:00.528515 [ok] [new=0 updated=0 same=20 error=0]
* END: 2009-01-26 14:43:49.941449 (no threadpool module available, no parallel fetching)
Oh, and you should probably get memcached running, as it really helps speed the database access. feedjack does a good job of using the cache. You can also install threadpool, as discussed on the web site, but I haven't tried that yet.
Next, of course, is the never ending customization battle. First though, I need to decide if this is the path I want to go down. Feedjack comes with two "themes", neither of which is as expressive as I want, especially for my music feeds like blip.fm and last.fm. And especially after I came across soup.io, which looks like it might already do all I need. Check out my page here: hieronymus.soup.io.
Thursday, December 4, 2008
Boxee redux
Trying to rebuild the latest Boxee and run into these problems:
1] AppManager.h:52 - change "static bool CAppManager::RunInBG(InstallOrUpgradeAppBG* pJob);" to "static bool RunInBG(InstallOrUpgradeAppBG* pJob);". g++ doesn't like the redundant qualification. Wonder what version of g++ the XBMC crew uses, as that's a common error I see alot from code coming over from Windows.
2] LinuxFileSystem.cpp:188 Change
shares.strName += " (" + g_localizeStrings.Get(51350) + ")";
to
share.strName += " (" + g_localizeStrings.Get(51350) + ")";
A very strange and impossible bug - it was using the Vector, not the CMediaShare. Maybe we shouldn't be doing HAL?
3] I got an error about missing libtxml.a. Needs tinyxml:
$ cd xbmc/lib/libBoxee
$ tar xzvf tinyxml_2_5_3.tar.gz
Not sure why it wasn't in there. Then I had to add a target to the Makefile found in xbmc/lib/libBoxee:
all: libBoxee.a libtxpath.a libtxml.a
libtxml.a:
make -C tinyxml
$(AR) $(ARFLAGS) libtxml.a tinyxml/*.o
ranlib libtxml.a
And that finally compiled. A lot cleaner and faster compiler than the previous version. This creates a ./Boxee. Now another problem cropped up - I can't seem to find any sort of script to create a new installation, like I create before. And there is no plugins folder, like there used to be. But I just faked it, using my make-boxee.sh script and copying in plugins folder from my previous install.
So I copy the create opt/boxee folder into /opt/boxee. And try to run it. It sort of worked, although I had to try a few times to log in, as it kept complaining of an invalid password. I assume that is just because the server is getting pounded due to all the people trying out the new version.
But even once I got logged in, it still wasn't very stable. Whenever the left menu would try to come up, Boxee locked up hard, requiring me to Ctrl-Alt-F2 to a text console and killing the process. Trying to play anything just crashes it. And I can't seem to find any log file :( Oh well.
Sunday, November 23, 2008
Media PC Mania
Boxee has me so excited about a home theater computer that I have begun to spec out building a new one to add to my home theater set up. Coincidentally enough, ASUS has recently come out with a new motherboard complete with HDMI out and 7.1 hi def audio, so here's what my list looks like:
- P5N7A-VM - looks like they did this one up right. Plenty of connectors, including HDMI, DVI, Display Port and VGA (you can use two at a time), plus Optical SPDIF, 6 jack audio, etc. Includes the latest nVidia 9300 mobile GPU (I guess it is the equivalent of the 8200 card; I have an 8600 in the openSUSE box). A microATX form factor means I can use a "home theater" designed case.
- Speaking of cases, it looks like I could go a few different ways. High end would be the Antec Fusion series, a real sweet "home theater" (replete with dials and guages) box. But at around $200, it seems like overkill. Slightly cheaper is the nMediaPC HTPC 1000, at around $100, although some reviews have been unkind. Cheaper still is the Apex DM series, which isn't really all the "home theater" looking, but is still pretty small and about $50, albeit with a pretty wimpy powersupply.
- Intel Core 2 Duo E6550 chip - ExtremeTech suggests this chip and given that we aren't going to do much besides render video streams, this mid-level chip should be enough. It should go for about US$160. Although given that the Core 2 Quad Q6600 I have in my main box goes for only about $20 more, maybe I should step up here.
- An optional enhancement would be a BluRay DVD player, which runs about US$100. In the beginning, a regular DVD player, which I have all over the place here, would suffice, as I already have a BluRay player with my PS3.
- And then add in a Samsung 1TB hard drive for about US$100 and a couple gigs of DDR2-800 RAM for US$20.
So all told, it would start at about US$500 for the box, plus the US$100 for the BluRay player. Very tempting. I would also probably run a UPnP server like MediaTomb to serve up my media. The costs look like this:
Motherboard | ASUS P5N7A-VM | $140 |
Case | Apex DM | $75 |
CPU | E6600 | $160 |
Memory | DDR2-800 2gb | $30 |
SATA Harddrive | 1TB Samsung HD103UJ | $100 |
BluRay Player | Lite-On | $100 |
I don't really need a media PC, as my regular PC works just fine. Of course, it is a real PC in a real case, and I have to unplug it and carry it over to my home theater setup, but how bad is that? Still, I can scheme for one, can't I?