Skip to main content

Ralsina.Me — Roberto Alsina's website

Making a unique application using python and DBUS

No, not unique in the sense "o­h, this app is a spe­cial snowflake", but unique in the sense "y­ou can on­ly run one copy of this ap­pli­ca­tion".

I tried googling for it and I al­ways found the same an­swer, "use dbus, try to own the name, if it ex­ists al­ready, then a copy is al­ready run­ning".

What I could not find is one work­ing ex­am­ple of this, or at least not some­thing con­ve­nient­ly la­beled "here is how you do a unique ap­pli­ca­tion us­ing dbus and python".

So, here is how you do a unique ap­pli­ca­tion us­ing dbus and python:

Sup­pos­ing your ap­pli­ca­tion is called uRSSus (mine is):

session_bus = dbus.SessionBus()
try:
    session_bus.get_object("org.urssus.service", "/uRSSus")
    # This is the second copy, make the first one show instead
    # TODO: implement
except dbus.DBusException: # No other copy running
    # This will 'take' the DBUS name
    name = dbus.service.BusName("org.urssus.service", bus=session_bus)
    # Now, start your app:
    window=MainWindow()
    object = UrssusServer(window,name)
    :
    :
    :
    etc, etc

And that's it. No, it's not hard, but since the DBUS docs seem to be... rather they seem al­most not to be some­times, ev­ery lit­tle bit may help.

DBUS-reactor, or AsusOSD must die!

How to write a tiny python app (less than 50 lines) that re­acts to events on the DBUS bus­es. For ex­am­ple, dis­play­ing a no­ti­fi­ca­tion when you press one of your key­board­s' spe­cial keys.

Read all about it

I knew not doing it was smarter, or how HTML5 and Qt do my work for me.

I wrote a while ago a RSS pro­gram called uRSSus. I ex­pect I am the on­ly us­er of it be­cause it has some prob­lems (all of them my fault ;-) but I re­al­ly like it.

For a while now I have want­ed it to have pod­cast sup­port. The thing is... that al­ways seemed like a lot of work. Sure, us­ing phonon I can cre­ate an au­dio play­er and ev­ery­thing, but...

I am us­ing a HTML wid­get to dis­play the post­s, so I would have to find a way to add the au­dio play­er to the UI and ... too much work.

So, to­day I woke up and thought... wait a minute... Qt's HTML wid­get is based on We­bkit. And We­bkit sup­ports HTM­L5. And HTM­L5 has an "au­dio" tag.

So, if I fixed uRSSus to fetch the en­clo­sure links, and added them in the database, and then added this to the post tem­plate:

<?py for enclosure in  post.enclosures: ?>
  <audio autobuffer="Yes" controls="controls" src=#{enclosure.href}></audio><br>
<?py #end ?>

Would­n't that ac­tu­al­ly work? Well, yeah!

urssus26

So there you have it, I was right not to im­ple­ment it, be­cause the eas­i­est way is to let Qt do it ;-)

Rant: Being annoying is not a way to make me your customer

I have been a cus­tomer of Fib­er­tel for my broad­band needs for sev­er­al years. Their ser­vice has not sucked bad, even if I had a few prob­lems in the past.

How­ev­er, a month ago, I de­cid­ed to switch to a com­pet­ing ser­vice for a good rea­son: it's much much much cheap­er 1

Since I am not stupid, I can­celed late with Fib­ertel, so I would have a full month of over­lap­ping ser­vice. I thought hey, maybe I would come back if the new ser­vice sucks 2

What hap­pened next has been in­creas­ing­ly an­noy­ing.

First Fib­er­tel called the per­son who con­tract­ed the ser­vice (not me). That's rea­son­able.

Then they called me to ask me why I was can­celling. I exlained that the oth­er ser­vice is (all things con­sid­ered) about 75% cheap­er for the same per­for­mance. I sup­pose that's rea­son­able too.

What start­ed be­com­ing less and less rea­son­able are the next 5 call­s, each of­fer­ing cheap­er rates, but still more ex­pen­sive than my new ser­vice.

What was not rea­son­able was that they start­ed call­ing to tell me tech­ni­cal­ly un­sound bull­shit to scare me in­to their ser­vice again.

What is def­i­nite­ly not rea­son­able is that they called me 6 times, even af­ter I told them to stop call­ing me in the third cal­l.

What is in­cred­i­bly stupid and an­noy­ing was that they de­cid­ed to block my in­ter­net ac­cess in or­der to show me an ad about the same of­fers I AL­READY DE­CLINED and un­til I clicked that ad I could not use the In­ter­net.

What is freak­ing nuts is that be­cause I have an ac­cess point I could­n't see the sa­tan-­damned ad, so I was left with­out in­ter­net un­til:

  • I re­­moved the ac­cess point

  • Hooked my note­­book to the ca­ble mo­­dem

  • Got re­­jec­t­ed by it

  • Hooked back the AP

  • Got the MAC from it

  • Faked my note­­books MAC

  • Clicked the Cthul­hu-pissed ads

  • Hooked back the AP

  • Un-­­faked my MAC

So, I need­ed to spend an hour do­ing this.

There­fore, dear Fib­ertel, your com­pa­ny al­so pro­vides ca­ble TV. I am pissed at you. I have de­cid­ed to buy ser­vice from Di­recTV ex­clu­sive­ly to piss you of­f.

Yup, I, who have been pay­ing you ev­ery month $230 for years, will pay you $0 next month. I could have paid you $100, but no, you had to be ass­es about it. You could­n't let me go. Well, I do not like be­ing pestered. I do not like that you act­ed like a spurned 17-year old 3

Fib­ertel, I kin­da liked you, but my opin­ion of you has gone low­er.

Al­so, any Fib­er­tel cus­tomers out there: if you ask to can­cel the ser­vice say­ing you switch be­cause of the price, they will of­fer you 3Mbps for a year for $79. If you say no, they will of­fer you 3 free month­s.

That's a $600 sav­ing, so go ahead and take their mon­ey.

1

$130 a month ver­sus $79 a month for the same band­width, plus it in­cludes phone ser­vice with free lo­cal phone call­s.

2

Since it stil may suck, I am not say­ing who they are, they have not earned an en­dorse­ment yet.

3

Would you go out with me? How about we go see Twi­light? No? How about we go to the fair? How about I pick you tonight? How bout if I ask my dad for the car? How about if I pay din­ner? -- Fib­ertel: that whiny teenag­er is you.


Contents © 2000-2021 Roberto Alsina