Skip to main content

Ralsina.Me — Roberto Alsina's website

Posts about programming (old posts, page 66)

Making deployment of desktop Python apps trivial: an idea

Proprietor and printer in front of Schwartz Print Shop in Minneapolis

Here's what I'm think­ing: how hard could it be to make PyQt app de­ploy­ment ab­so­lute­ly easy? Well, I am guess­ing: not very hard.

Here's the trick: see what works in the re­al world, and adopt it.

Ques­tion: what has de­ployed bil­lions of apps and has its users hap­py? An­swer: phones app stores.

Ques­tion: how do they work? An­swer: well, that's not that short, so let's start ex­plain­ing.

As I see it, a rea­son­able app store has the fol­low­ing com­po­nents:

A Stable Deployment Target

You can't de­ploy from the store if you don't know what you are de­ploy­ing in­to. If the tar­get plat­form is shaky, you just can't know how to de­ploy with­out us­er as­sis­tance, and we are try­ing to make this easy for the user, which means that's not ac­cept­able.

So, what's a sta­ble de­ploy­ment tar­get we can provide?

  • PyQt (so we can de­­ploy GUIs to all ma­jor desk­­top plat­­for­m­s)

  • Python stan­­dard li­brary

  • Se­lec­t­ed mod­­ules

What can be (and should be) bun­dled with the ap­p?

  • Pure python mod­­ules

  • Art­­work and oth­­er re­­sources

What may be bun­dled:

  • Python mod­­ules writ­ten in C/C++, but you then have to re­­do the app for each plat­­for­m, and that kin­­da suck­­s.

Deployment Services

  • Apps should be able to check if there is a new ver­­sion of them in the store, to ask for up­­­grades.

  • Apps should be added by the de­­ploy­­ment plat­­form nice­­ly in­­­to the host sys­tem's menus, desk­­top, etc.

Monetization Services

  • Some way to charge for ap­p­s. Even for open source ap­p­s, you could ask for U$S0.99 if you in­­stall them through the store. Op­­tion­al, of course, and up to the app own­er.

  • Ad plat­­for­m? There must be a good one for desk­­top apps some­where?

The Store Itself

  • A we­b­site that down­loads a "pack­­age" as­­so­­ci­at­ed with a lo­­cal de­­ploy­­ment ap­­pli­­ca­­tion.

  • A app store ap­p. In­­stall things not via we­b, but via a desk­­top ap­­pli­­ca­­tion.

I don't ex­pect a func­tion­al ver­sion of this would take me more than a week work­ing full­time to im­ple­men­t. Of course then there are all sorts of us­abil­i­ty, look­s, etc. things to con­sid­er.

And... I am go­ing to do some­thing I very rarely do. I am go­ing to ask for mon­ey.

As an ex­per­i­men­t, I have set­up a project at­diegogo.­com/Qt-Shop and set a fund­ing goal of U$S 600.

There you can fund me. I prom­ise that if the project is to­tal­ly fund­ed, I will de­liv­er. If it is­n't, I may de­liv­er any­way. I would pre­fer to have the mon­ey though.

The plat­form would be re­leased un­der GPLv2 or lat­er.

Why we are here.

Warn­ing: rant ahead.

Yes­ter­day the gov­ern­ment of Ar­genti­na an­nounced that they are giv­ing way 3 mil­lion net­books to stu­dents. They al­so an­nounced that they are giv­ing them the op­tion of Ubun­tu or Win­dows 7.

There was, of course, the typ­i­cal re­ac­tion from the FLOSS side: why are they giv­ing Win­dows to the stu­dents when Lin­ux is bet­ter? It's un­fair that the gov­ern­ment pays for Win­dows!

I am here to tell you to grow up and stop be­ing a ba­by. I am here to tell you to stop treat­ing oth­ers like ba­bies.

I think I can do this be­cause I am im­mune to crit­i­cism from the FLOSS crowd: I am a mem­ber of that crowd. I have an awe­some FLOSS pedi­gree, I have used noth­ing but Lin­ux for over 15 years. And I have a thick skin and I don't care much what oth­er peo­ple say, in prin­ci­ple, un­less they give me good rea­sons to care. And I am telling you to stop com­plain­ing.

I am telling you that if the on­ly rea­son to use a spe­cif­ic piece of soft­ware is be­cause it's cheap­er, you are ac­cept­ing that piece of soft­ware suck­s.

I want peo­ple not to just use Lin­ux, I want them to want to use Lin­ux. I want them to wait anx­ious­ly for the next re­lease of Ubun­tu or Fire­fox or what­ev­er.

And the first step to­wards ex­cel­lence is want­ing to be ex­cel­len­t. If hav­ing to pay noth­ing for Win­dows or Ubun­tu there is a cer­tain­ty that Win­dows will win, then Ubun­tu freak­ing sucks and needs to im­prove. Peo­ple are not adopt­ing it even if it's free? Then some­thing is wrong, and fig­ur­ing out what is im­por­tan­t.

But even more im­por­tant than find­ing the miss­ing piece is know­ing a piece is miss­ing. Open source has grown com­pla­cen­t. It's grown self right­eous. It's be­come ado­les­cen­t, sure of its awe­some­ness and im­mor­tal­i­ty.

I don't be­lieve in many things, but I do be­lieve in free will. I be­lieve that peo­ple are not mo­ron­s, I be­lieve that if they pre­fer Win­dows, it's be­cause it does some­thing bet­ter, and I be­lieve that what­ev­er that is (and I don't re­al­ly know what it may be), it can be found, and can be im­proved, and can be re­placed, and oth­er things can be added, and peo­ple will want to use the bet­ter prod­uc­t.

And if they don't... well, at least we fought an hon­est fight, and we did our best, and we (hope­ful­ly) had fun in the pro­cess, and pushed the en­velope, and cre­at­ed nice things, and the users are bet­ter off in the end even if our ba­bies are not the cho­sen ones, be­cause we raised the lev­el of ev­ery­thing.

For ex­am­ple, be­fore Lin­ux, Win­dows sucked much, much more than it does now, and I think many of those im­prove­ments were be­cause of Lin­ux, and I am hap­py that to­day Win­dows users have a OS that does­n't stink.

I want free and open source soft­ware to be used be­cause it's awe­some, not be­cause it's cheap. Awe­some and cheap I can live with. Just cheap? That suck­s.

And the con­stant "they use win­dows be­cause they don't know bet­ter"? That's pa­tron­iz­ing and con­de­scend­ing, and very, very an­noy­ing. And if it an­noys me, who is not the tar­get of the lame con­de­scen­sion, trust me, it an­noys the crap out of Win­dows user­s.

Grow a spine, get your ass­es in­to gear, start mak­ing awe­some stuff, kick ass with qual­i­ty. That's why we are here. Not to be the cheap­est date in town.

Goodreads+webcam+python+zbar == hackfun!

I am a big fan of GoodReads a so­cial net­work for peo­ple who read book­s.

I read a lot, and I like that I can see what oth­er peo­ple think be­fore start­ing a book, and I can put my short re­views, and I can see what I have been read­ing, and lots more.

In fac­t, goodreads is go­ing to be a big part of a project I am start­ing with some PyAr guys.

One thing I have been lazy about is adding my book list to goodread­s, be­cause it's a bit of a chore.

Well, chore no more!

Here's how to do it, the hack­er way...

  1. Get zbar

  2. Get a cheap we­b­­cam

  3. Get a book

  4. Get a 7-­­line python pro­­gram (in­­clud­ed be­low)

Now watch the video...

Cute, is­n't it?

Here's the code:

import os

while True:
    code = p.readline()
    print 'Got barcode:', code
    isbn = code.split(':')[1]

PET: English Translation Issue 1 has a date

Be­cause it worked on­ce, let's do it again. I have just set a com­plete­ly ar­bi­trary, and prob­a­bly too ear­ly date for the re­lease of the first eng­lish Is­sue of "PET: Python En­tre To­dos" mag­a­zine.

The eng­lish ver­sion is called PET, which means "Python En­tre To­dos: Eng­lish Trans­la­tion".

It will have the same con­tents as the first span­ish Is­sue and... it will be the last Is­sue done like this.

From now on, both ver­sions will be pub­lished at the same time, if we can.

So, there will be a very short gap be­tween the eng­lish first Is­sue and the sec­ond one (less than a mon­th, we hope).

So, stay tuned

Things I learned publishing a magazine

To­day at 00:00:00 GMT-3 PET: Python en­tre to­dos was in­deed launched, in time (ar­bi­trary but forced) and in bud­get ($0).

So, what did I learn? I learned a lot!

  • The on­­ly thing you need to pub­­lish an e-­­mag is time and con­­ten­t.

  • Time can be con­vert­ed in­­­to con­­ten­t, but if you write ev­ery­thing your­­self it's a blog, not a mag­a­zine. Luck­­i­­ly, PET found great con­trib­u­­tors.

  • If you want util­i­­tar­i­an de­sign, rst2pdf can do the job

  • In fac­t, it can do it bet­ter than oth­­er tools in some ways

    • I can push a fixed ver­­­sion of the PDFs in 5 min­utes for all lay­out­s. How much would it take me us­ing Scribus or oth­­­er DT­P? In a mag­a­zine where cor­rec­t­­­ness mat­ter­s, that's a big deal.

    • TOCs are bet­ter than in most am­a­­­teur PDF mag­a­zines I've seen. The in­­­-­­­con­­ten­t-­­­TOC is click­­­able, and the PDF TOC is per­fec­t.

    • Page num­bers in the PDF TOC make sense (no, the cov­­­er is not page 1)

    • I am pro­­­duc­ing 6 PDF ver­­­sion­s: A4(b­w, colour), A5(b­w,­­­colour), Book­let(b­w, colour) and I could add any oth­­­er I want in a few min­utes.

  • I learned about PDF im­po­si­­tion!

Let's ex­plain the last one:

Sup­pose you want to print a small book­let, and you have 32 pages of con­tent. How do you do that?

The eas­i­est way is to print it 2-up dou­ble-sid­ed in A4 pa­per so that you can stack the pages, fold them down the mid­dle, sta­ple them, and get a nice A5 book­let.

The prob­lem is that the page or­der­ing is hard to get right. For ex­am­ple, for a 4-­page book­let, you need to print one A4 page with pages 4-1 on one side and 2-3 on the oth­er. For an 8 page book­let it's 8-1,2-7,3-6,4-5.

Lucklily there's a way to get this done au­to­mat­i­cal­ly:

1. In­stall pod­ofo 3. Get book­let-A4.­plan (see be­low) 2. Run this:

podofoimpose my-A5-pages.pdf my-booklet.pdf booklet-A4.plan lua

book­let-A4.­plan is this:

---Generic Booklet (A4)
---It is said generic as it will try to determine
---automatically how to fit the booklet onto A4
---paper sheets, scaling pages if necessary.
---it is well suited for office documents for
---which you do not care too much about resulting
---imposition artefacts since it manages to save
-- print("Booklet")
-- We output an A4 booklet
PageWidth = 595.27559
PageHeight = 841.88976


-- We assume that H > W
-- Argh, we now can do better since we have "if" ;-)
-- Scale = PageHeight / (2*SourceWidth)
if(SourceWidth <= SourceHeight)
--  If you A5 pages are not really A5, uncomment the next line
--  Scale = PageHeight / (2*SourceWidth)
    Scale = 1
    rot = 90
        xof = SourceHeight
        yofRA = 0
        yofRB = SourceWidth
        yofVA = 0
        yofVB = SourceWidth
--  If you A5 pages are not really A5, uncomment the next line
--  Scale = PageHeight / (2*SourceHeight)
    Scale = 1
    rot = 0
        xof = 0;
        yofRA = 0
        yofRB = SourceHeight
        yofVA = SourceHeight
        yofVB = 0

    rest = PageCount % 4
    totp = PageCount
    if rest ~= 0
        totp = totp + ( 4 - rest)
    inc = 0
    count = 0
    imax = totp/4
    while count < imax
--          We assume that podofoimpose will discard invalid records
--          such as those with source page greater than PageCount
--          print(totp, inc, rot, xof,yofRA, yofRA, yofVA, yofVB)
-- Recto
        PushRecord(totp - inc , inc + 1 , rot, xof , yofRA)
        PushRecord(inc + 1 , inc + 1 , rot, xof , yofRB)
-- Verso
        PushRecord(inc + 2 , inc + 2 , rot, xof , yofVA)
        PushRecord(totp-(inc + 1) , inc + 2 , rot, xof, yofVB)

        count = count + 1
        inc = inc + 2

That code is tak­en from here: http://www.oep-h.­com/im­pose/

And voilá, you get a scram­bled PDF with the pages in ex­act­ly the right or­der (and emp­ty pages added as need­ed).

Contents © 2000-2023 Roberto Alsina