|
These are user-supplied utilities. If I like them, they will become part of the distribution.
Index: - Remove all pages except the system pages
Remove all pages except the system pages
Provided by Engelbert Gruber <engelbert.gruber@ssg.co.at>
1 #!/usr/bin/python
2
3 """Delete all files not listed.
4 USAGE: rm-non-systempages SystemPages
5 reads SystemPages and cleans curent directory"""
6
7 import sys,os
8 import re
9
10 if (len( sys.argv)<=2 ):
11 print( __doc__ )
12 sys.exit(0)
13
14 word_match = re.compile("^[ \*]*([^\s]+)")
15 # Read file list (survivors)
16 keep = {}
17 f = open(sys.argv[1])
18
19 while 1:
20 line = f.readline()
21 if not line:
22 break
23 m = word_match.match(line)
24 if (m and len(m.group(1))>2):
25 keep[m.group(1)] = 1
26
27 f.close()
28
29 # Scan through directory and remove files not in keep.
30
31 for entry in os.listdir(sys.argv[2]):
32 # donot test for directories, remove wont do no harm.
33 if (not keep.has_key(entry)):
34 fn = os.path.join( sys.argv[2], entry )
35 print "remove:"+fn
36 os.remove( fn )
37 else:
38 print "keep:"+entry
|