Thursday, April 9, 2009

similar install on new laptop machine

One thing I have found myself doing on a number of occasions is having a base install on a new desktop/laptop and wanting to bring it into line with my current machine.

In the past I have used a shell script to do this between servers but for the desktop and in particular the mini9 I am now attempting to bring up to speed, I thought I might give python a try.

First I looked a little at urllib2 to see about trial fetching the debs concerned to see if they exist.
Later I read up about python-apt and so the script below is a work in progress that includes a bit of code from both.

import apt
from urllib2 import Request, urlopen, URLError, HTTPError
#import urllib2

#      # Dell Inspiron 1525 2008Q2 version
# # Dell mini9 2009Q1 ver is 8.04 LTS

release_name_lower="hardy"   # Dell mini9 2009Q1 version uses 8.04 LTS

req = Request(urlstub_default)
    response = urlopen(req)
except HTTPError, e:
    print 'The server failed to fulfill the request.'
    print 'Error code: ', e.code
except URLError, e:
    print 'URL problem so we fail to reach the server.'
    print 'Reason: ', e.reason
    # response okay

all_packages = apt.Cache()
installed_packages = [i for i in all_packages if i.isInstalled]
upgradable_packages = [i for i in installed_packages if i.isUpgradable]
print "Total available packages: %d\n" % len(all_packages)
print "Total installed packages: %d\n" % len(installed_packages)

for i in upgradable_packages:
    print (, i.candidateVersion, i.architecture, i.installedPriority)

Hopefully when I get back from the weekend break I can finish this
and bring the mini9 into line.

No comments: