1.1 --- a/iixr/filesystem.py Mon Nov 22 23:45:44 2010 +0100
1.2 +++ b/iixr/filesystem.py Mon Nov 22 23:50:03 2010 +0100
1.3 @@ -21,10 +21,15 @@
1.4 from iixr.fields import *
1.5 from iixr.terms import *
1.6 from iixr.positions import *
1.7 -from os import remove, rename # partition manipulation
1.8 -from shutil import copy # index updating
1.9 +from os import listdir, remove, rename # partition manipulation
1.10 +from shutil import copy # index updating
1.11 from os.path import join
1.12
1.13 +try:
1.14 + set
1.15 +except NameError:
1.16 + from sets import Set as set
1.17 +
1.18 # Constants.
1.19
1.20 TERM_FILENAMES = "terms", "terms_index", "positions", "positions_index"
1.21 @@ -32,6 +37,42 @@
1.22
1.23 # Utility functions.
1.24
1.25 +def get_partitions(pathname, prefix):
1.26 +
1.27 + """
1.28 + Return a set of partition names for partitions residing at the given
1.29 + 'pathname' having the given 'prefix'.
1.30 + """
1.31 +
1.32 + prefix_length = len(prefix)
1.33 +
1.34 + partitions = set()
1.35 + for filename in listdir(pathname):
1.36 + if filename.startswith(prefix):
1.37 + partitions.add(filename[prefix_length:])
1.38 + return partitions
1.39 +
1.40 +def get_term_partitions(pathname):
1.41 +
1.42 + """
1.43 + Return a set of term partition identifiers for partitions residing at the
1.44 + given 'pathname'.
1.45 + """
1.46 +
1.47 + return get_partitions(pathname, "terms-")
1.48 +
1.49 +def get_field_partitions(pathname):
1.50 +
1.51 + """
1.52 + Return a set of field partition identifiers for partitions residing at the
1.53 + given 'pathname'.
1.54 + """
1.55 +
1.56 + return get_partitions(pathname, "fields-")
1.57 +
1.58 +def get_next_partition(partitions):
1.59 + return max([int(n) for n in partitions if n.isdigit()] or [-1]) + 1
1.60 +
1.61 def get_term_writer(pathname, partition, interval, doc_interval):
1.62
1.63 """