Roadmap?

jmhodges at dbguin.lunar-linux.org jmhodges at dbguin.lunar-linux.org
Fri Jun 27 06:32:08 GMT 2003


Following along with csm's comment, I decided I wanted an easier way of
viewing what modules needed updating.  Maybe this is in the core
functionality already but oh well, it was something to spend my 15 minute
breaks on at work.  The script is straightforward and a probe.py -h should
get you started.  It will list all of the modules that were updated before
a given number of timeperiods ago (like 7 days or 8 months or 2 years).
The date code is just a quick kludge so if you run a 'probe.py -m'  on the
first of the month, you will get modules last updated on the 31st, etc,
not from "a month ago".  Also, there is no sorting of any kind.  I wrote
this very quickly because I felt I needed a place to start.  The
translation to bash is mostly trival and left as an excercise for the
reader.
*ducks the onslaught of thrown  calculus textbooks*
Kidding!  If there is interest in this, I'll rewrite it in bash or add
features.  Or hell, somebody else can do it, if they really feel like it
:).
	-- Jeff
PS Most of this was written on pieces of butcher paper so be gentle if you
dont like how it feels :-P

PSS Oh and once again ive been banned from lunar-linux.org.. this time i
have NO IDEA WHY.  Someone want to enlighten me?
-------------- next part --------------
#!/usr/bin/python

"""
Grep through the moonbase and look for old dates in UPDATED
Have options for "before last week" "last month" "last year"
"""
import sys,os,string,time

moonbase = '/var/lib/lunar/moonbase'
argdict = { '-d':'days', '-m':'months', '-y':'years','--help':'', '-h':'' }

def lister(dummy, dirname, filesindir):
    print '[' + dirname + ']'
    for fname in filesindir:
        if fname == 'DETAILS':
            return os.path.join(dirname,fname)

def success(fname,timeperiod,delta, update):
    if delta == 1:
        if timeperiod == 'days':
            print fname + ' was updated yesterday'
        else: print fname + ' was updated last ' + timeperiod[:-1]
        
    elif delta == 2:
        print fname + ' was updated the ' + timeperiod[:-1] + 'before last'
        
    else:
        print fname + ' was updated at least ' + delta + ' ' + timeperiod + ' ago on ' + update
    
def compareit(update, today, fname, timeperiod, delta):
    if int(update) < (int(today) - delta) or int(update) == (int(today) - delta):
        success(fname, timeperiod, delta, update)
        
def checkbase(timeperiod, delta = 1):
    Today = time.strftime("%Y%m%dx")
    for section in os.listdir(moonbase):
        
        if os.path.isdir(os.path.join(moonbase,section)):
            
            for module in os.listdir(os.path.join(moonbase,section)):

                if os.path.isdir(os.path.join(moonbase, section, module)):
                    for f in os.listdir(os.path.join(moonbase, section, module)):
                        if f == 'DETAILS':
                            file = open(os.path.join(moonbase,section,module,f), 'r')

                            for line in file.readlines():
                                line = string.strip(line)
                                
                                if line[:8] == 'UPDATED=':
                                    update = line[8:]
                                    if update != "`date -u +%Y%m%d`":
                                        if timeperiod == 'days':
                                            compareit(update,Today, module, timeperiod, delta)
                                    
                                        if timeperiod == 'months':
                                            compareit(update[:6],Today[:6], module, timeperiod, delta)
                                    
                                        if timeperiod == 'years':
                                            compareit(update[:4], Today[:4], module, timeperiod, delta)
                                else: pass


if len(sys.argv) > 1:
    if sys.argv[1] in argdict:
        if sys.argv[1] == '-h' or sys.argv[1] == '--help':
            print "This script will generate a list of modules updated after a time specifed \
                Use probe.py -d {somenum} for modules with UPDATED fields before or at {somenum} days ago.  \
                The default {somenum} is 1.  There is also -m for months and -y for days."
            print
        
        elif len(sys.argv) > 2:
            checkbase(argdict[sys.argv[1]], sys.argv[2])

        else: checkbase(argdict[sys.argv[1]])
            
elif len(sys.argv) == 1:
    print "You need more arguments! Look at probe.py -h !"


More information about the Lunar-dev mailing list