Skip to main content

Ralsina.Me — Roberto Alsina's website

Sometimes I am stupid. Then again, it doesn't matter, because I am lucky!

I am work­ing on chang­ing Bartle­Blog so it can be used from scratch. That may sound odd but be­cause I have been us­ing it since day 2 to post this blog, it has grown very or­gan­i­cal­ly, mean­ing there are things that on­ly work be­cause of the way I used it while de­vel­op­ing it.

So, I cre­at­ed a test user, and cre­at­ed a test blog there, and I am work­ing, and de­cide to do an­oth­er from-scratch test, and...

I delet­ed my pro­duc­tion copy.

Yes. The one that gen­er­ates this blog. So this blog dis­ap­peared. Be­cause I used the wrong ter­mi­nal win­dow.

And I had one-week old back­up­s.

So I felt very very stupid.

Be­cause un­delet­ing in Lin­ux is a joke.

So I was think­ing how to spend a few hours recre­at­ing the last week of post­s, and what­ev­er, when I no­ticed on the taskbar... bartle­blog was still run­ning.

Which means that the DB was still open by a process. Which mean­s...

[ralsina@monty bartleblog]$ ps ax | grep python
17063 pts/1    S     24:33 python bartleblog.py
17161 ?        S      0:04 konqueror [kdeinit] -mimetype text/html http://www.google.com/search?q=python+copy+file&ie=UTF-8&oe=UTF-8
17454 pts/1    D+     0:00 grep python
[ralsina@monty bartleblog]$ su
Password:
[root@monty bartleblog]# cd /proc/17063/fd
[root@monty fd]# ls
0  1  10  11  12  2  3  4  5  6  7  8  9
[root@monty fd]# ls -l
total 0
lrwx------ 1 ralsina users 64 2007-05-13 21:07 0 -> /dev/pts/1
lrwx------ 1 ralsina users 64 2007-05-13 21:07 1 -> /dev/pts/1
lrwx------ 1 ralsina users 64 2007-05-13 21:07 10 -> socket:[159486]
lrwx------ 1 ralsina users 64 2007-05-13 21:07 11 -> socket:[159488]
lrwx------ 1 ralsina users 64 2007-05-13 21:07 12 -> /mnt/centos/home/ralsina/.bartleblog/blog.db (deleted)
lrwx------ 1 ralsina users 64 2007-05-13 21:07 2 -> /dev/pts/1
lr-x------ 1 ralsina users 64 2007-05-13 21:07 3 -> /mnt/centos/home/ralsina/Desktop/proyectos/bartleblog/bartleblog/BartleBlog/ui/bartleblog.py
lr-x------ 1 ralsina users 64 2007-05-13 21:07 4 -> pipe:[159481]
l-wx------ 1 ralsina users 64 2007-05-13 21:07 5 -> pipe:[159481]
lr-x------ 1 ralsina users 64 2007-05-13 21:07 6 -> pipe:[159482]
l-wx------ 1 ralsina users 64 2007-05-13 21:07 7 -> pipe:[159482]
lr-x------ 1 ralsina users 64 2007-05-13 21:07 8 -> pipe:[159485]
l-wx------ 1 ralsina users 64 2007-05-13 21:07 9 -> pipe:[159485]
[root@monty fd]# cp 12 /root/db
[root@monty fd]# ls -l ~/db
-rw-r--r-- 1 root root 3582976 2007-05-13 21:07 /root/db
[root@monty fd]# sqlitebrowser ~/db
[root@monty fd]# cp ~/db /home/ralsina/.bartleblog/blog.db

And I got the data­base back.

If you don't un­der­stand how that worked.... here's the ex­pla­na­tion:

  • On unix, files are re­al­­ly un­linked (re­­moved from di­rec­­to­ries) when no process has them open. Even then, the da­­ta is not delet­ed, but find­­ing it is much hard­er.

  • On /proc/PID you can see the file de­scrip­­tors each process has open.

  • You can ac­­tu­al­­ly copy a file de­scrip­­tor.

So I went and copied the open file. And got it back. And this blog did­n't go away.

So I am luck­y! Stupid. But luck­y!

New Bartleblog Feature: Menu Editor

Took a while to im­ple­men­t, but Bartle­Blog fi­nal­ly got a func­tion­al menu ed­i­tor:

bartleblog12.png

Right now, it on­ly works with the mootool­s-based menu gad­get, but I will start work­ing on the ya­hoo menu ver­sion in a mo­men­t.

The on­ly thing not work­ing is the pre­view but­ton, be­cause it needs more sup­port on the back­end side.

Python Trick: Save anything in config files

The Python con­fig ob­jects are con­ve­nient and sim­ple, but they have a prob­lem: you can on­ly save strings. That means you need to store num­bers as strings and re­mem­ber to use the get­int()/get­float() meth­ods (or co­erce by hand!), which is er­ror prone and an­ti-python­ic. Stor­ing a list is even ugli­er.

You could store ascii pick­les, but those are pret­ty un­pleas­ant to read in some cas­es.

Here's my so­lu­tion: En­code it us­ing a JSON en­coder first! (I am us­ing demj­son)

Sil­ly ob­vi­ous code frag­men­t:

def getValue(section,key,default=None):
    try:
        return JSON().decode(conf.get (section,key))
    except:
        return default

def setValue(section,key,value):
    value=JSON().encode(value)
    try:
        r=conf.set(section,key,value)
    except ConfigParser.NoSectionError:
        conf.add_section(section)
        r=conf.set(section,key,value)
    f=open(os.path.expanduser('~/.bartleblog/config'),'w')
    conf.write(f)
    return r

With just a lit­tle ef­fort you can have a read­able ascii typed python con­fig file.

Today's first hour of hacking...

... has been all about UI.

I have al­ways had a prob­lem when writ­ing PyQt app­s: stock icon­s.

Which ones should I use? Where are they?

I usu­al­ly fished through the crys­talsvg icon set un­til I found one that seemed to be what I need­ed, and then copied it to my ap­p.

Sad­ly, that's an­noy­ing in sev­er­al ways:

  1. Since those are PNG icon­s, you need to find the right size.

  2. Not all icons are there for all sizes!

  3. Be­­cause of 2, I need to check three or four fold­ers to see all the icon­s.

So, I de­cid­ed to cut my loss­es, and see what else could be done. And here it is:

bartleblog11.png

I am now us­ing all SVG icon­s, from the rein­hardt set that will look equal­ly out of place in all OS­s, but which I like (and I think look awe­some with this re­laxed Domi­no the­me). And be­cause they are all SVG, I don't care about sizes, and they are all in the same place, and all is good.

And when­ev­er Oxy­gen is re­leased, all I need to do is switch the files around and that's that. Which is nice, too.

Of course there is a catch... it does look out of place, and I ex­pect many to find it ug­ly. So what, since I am the on­ly us­er of this ap­p! ;-)