#!/usr/bin/python ''' create an index of all files on the computer, lists also files in archives (like zi) usage: reindex [noarc] [] where noarc dont index archoves add files from this directory to index (does not remove deleted files from index!) ''' # ---- defaults --- f = '/home/index' fzip = '/home/index.archives' arc = True roots = ['/bin', '/home', '/mnt', '/sbin', '/usr', '/etc', '/lib', '/opt', '/root', '/var'] create_new_index = True platform = "linux" # "linux" or "windows" def finish(): txt = string.join(files, '\n') open(f,'w').write( txt ) print "done." sys.exit() args = sys.argv.pop(0) while args: arg = args.pop() # order has no meaning if arg in ["--help",'-h','?'] : print __doc__ sys.exit() if arg == "noarc": print "will NOT process archives" arc=False continue else: roots = arg create_new_index = False # -- create index file, delete existing if any... if create_new_index: print "delete old "+f os.unlink(f) print #delete old "+fzip os.unlink(fzip) files=[] else: output = open(f).read() files = output.split('\n') for x in roots: if platform == "linux": cmd = "find %s -type f " % (x) elif platform == "windows": cmd = "dir /s/b %s " % (x) print cmd output = os.popen(cmd).read() # zaurus sharp rom cleaning: output = output.replace('/usr/mnt.rom/card', '/mnt/sd') output = output.replace('/home/root/usr/bin', '/usr/bin' ) files_tmp = output.split('\n') files.append(files_tmp) print "--- clean and sort ---" # cat $f | grep -v "/$" | sort -u > $f.tmp files.sort() #mv $f.tmp $f # zaurus sharp rom cleaning: #replacer.py $f -o '/usr/mnt.rom/card' -n '/mnt/sd' -b #replacer.py $f -o '/home/root/usr/bin' -n '/usr/bin' -b if not arc: print "not processing archvies." finish() ''' # ----- look into zip files --- if test $create_new_index = True ; then print "--- removing old archive index" rm $fzip fi print looking into ipks ... grep -i \\.ipk$ $f | xargs /usr/bin/ipklist >> $fzip print looking into plain tar ... grep -i \\.tar$ $f | xargs /usr/bin/tarlist >> $fzip print looking into zip ... grep -i \\.zip$ $f | xargs /usr/bin/ziplist >> $fzip print looking into tar.gz ... grep -i \\.tgz$ $f | xargs /usr/bin/tgzlist >> $fzip grep -i \\.tar.gz$ $f | xargs /usr/bin/tgzlist >> $fzip print looking into tar.bz2 ... grep -i \\.tar.bz2$ $f | xargs /usr/bin/tbzlist >> $fzip grep -i \\.tar.bzip2$ $f | xargs /usr/bin/tbzlist >> $fzip print looking into debian packages ... grep -i \\.deb$ $f | xargs dpkg-deb -c >> $fzip print removing junk \(directories, duplicates\) cat $fzip | grep -v "/$" | sort -u > $fzip.tmp mv $fzip.tmp $fzip '''