1.1 --- a/iixr/filesystem.py Sun Feb 13 02:49:55 2011 +0100
1.2 +++ b/iixr/filesystem.py Mon Feb 14 00:44:57 2011 +0100
1.3 @@ -30,7 +30,7 @@
1.4
1.5 # Constants.
1.6
1.7 -TERM_FILENAMES = "terms",
1.8 +TERM_FILENAMES = "terms", "term-index"
1.9
1.10 # Utility functions.
1.11
1.12 @@ -63,6 +63,10 @@
1.13 def get_next_partition(partitions):
1.14 return max(partitions or [-1]) + 1
1.15
1.16 +def get_writer(pathname, name, partition, cls):
1.17 + f = open(join(pathname, "%s-%s" % (name, partition)), "wb")
1.18 + return cls(f)
1.19 +
1.20 def get_term_writer(pathname, partition):
1.21
1.22 """
1.23 @@ -70,8 +74,16 @@
1.24 according to the given 'partition'.
1.25 """
1.26
1.27 - f = open(join(pathname, "terms-%s" % partition), "wb")
1.28 - return TermWriter(f)
1.29 + return get_writer(pathname, "terms", partition, TermWriter)
1.30 +
1.31 +def get_term_index_writer(pathname, partition):
1.32 +
1.33 + """
1.34 + Return a term index writer using files under the given 'pathname' labelled
1.35 + according to the given 'partition'.
1.36 + """
1.37 +
1.38 + return get_writer(pathname, "term-index", partition, TermIndexWriter)
1.39
1.40 def get_reader(pathname, name, partition, cls):
1.41 f = open(join(pathname, "%s-%s" % (name, partition)), "rb")
1.42 @@ -95,11 +107,32 @@
1.43
1.44 return get_reader(pathname, "terms", partition, TermDataIterator)
1.45
1.46 +def get_term_index_reader(pathname, partition):
1.47 +
1.48 + """
1.49 + Return a term index reader using files under the given 'pathname' labelled
1.50 + according to the given 'partition'.
1.51 + """
1.52 +
1.53 + return get_reader(pathname, "term-index", partition, TermIndexIterator)
1.54 +
1.55 +def get_combined_term_reader(pathname, partition):
1.56 +
1.57 + """
1.58 + Return a combined term reader using files under the given 'pathname'
1.59 + labelled according to the given 'partition'.
1.60 + """
1.61 +
1.62 + return CombinedIterator(get_term_reader(pathname, partition), get_term_index_reader(pathname, partition))
1.63 +
1.64 # Renaming.
1.65
1.66 def rename_files(pathname, names, from_partition, to_partition):
1.67 for name in names:
1.68 - rename(join(pathname, "%s-%s" % (name, from_partition)), join(pathname, "%s-%s" % (name, to_partition)))
1.69 + try:
1.70 + rename(join(pathname, "%s-%s" % (name, from_partition)), join(pathname, "%s-%s" % (name, to_partition)))
1.71 + except OSError:
1.72 + pass
1.73
1.74 def rename_term_files(pathname, from_partition, to_partition):
1.75 rename_files(pathname, TERM_FILENAMES, from_partition, to_partition)
1.76 @@ -108,7 +141,10 @@
1.77
1.78 def remove_files(pathname, names, partition):
1.79 for name in names:
1.80 - remove(join(pathname, "%s-%s" % (name, partition)))
1.81 + try:
1.82 + remove(join(pathname, "%s-%s" % (name, partition)))
1.83 + except OSError:
1.84 + pass
1.85
1.86 def remove_term_files(pathname, partition):
1.87 remove_files(pathname, TERM_FILENAMES, partition)
1.88 @@ -118,7 +154,10 @@
1.89 def copy_files(source, names, partition, destination, suffix):
1.90 for name in names:
1.91 filename = "%s-%s" % (name, partition)
1.92 - copy(join(source, filename), join(destination, filename + suffix))
1.93 + try:
1.94 + copy(join(source, filename), join(destination, filename + suffix))
1.95 + except OSError:
1.96 + pass
1.97
1.98 def copy_term_files(source, partition, destination, suffix):
1.99 copy_files(source, TERM_FILENAMES, partition, destination, suffix)