1.1 --- a/iixr/filesystem.py Sat Sep 19 01:43:35 2009 +0200
1.2 +++ b/iixr/filesystem.py Sat Sep 19 21:36:32 2009 +0200
1.3 @@ -21,7 +21,8 @@
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 os import remove, rename # partition manipulation
1.9 +from shutil import copy # index updating
1.10 from os.path import join
1.11
1.12 # Constants.
1.13 @@ -106,6 +107,8 @@
1.14
1.15 return FieldDictionaryReader(field_reader, field_index_reader)
1.16
1.17 +# Renaming.
1.18 +
1.19 def rename_files(pathname, names, from_partition, to_partition):
1.20 for name in names:
1.21 rename(join(pathname, "%s-%s" % (name, from_partition)), join(pathname, "%s-%s" % (name, to_partition)))
1.22 @@ -116,6 +119,8 @@
1.23 def rename_field_files(pathname, from_partition, to_partition):
1.24 rename_files(pathname, FIELD_FILENAMES, from_partition, to_partition)
1.25
1.26 +# Removal/deletion.
1.27 +
1.28 def remove_files(pathname, names, partition):
1.29 for name in names:
1.30 remove(join(pathname, "%s-%s" % (name, partition)))
1.31 @@ -126,4 +131,17 @@
1.32 def remove_field_files(pathname, partition):
1.33 remove_files(pathname, FIELD_FILENAMES, partition)
1.34
1.35 +# Copying.
1.36 +
1.37 +def copy_files(source, names, partition, destination, suffix):
1.38 + for name in names:
1.39 + filename = "%s-%s" % (name, partition)
1.40 + copy(join(source, filename), join(destination, filename + suffix))
1.41 +
1.42 +def copy_term_files(source, partition, destination, suffix):
1.43 + copy_files(source, TERM_FILENAMES, partition, destination, suffix)
1.44 +
1.45 +def copy_field_files(source, partition, destination, suffix):
1.46 + copy_files(source, FIELD_FILENAMES, partition, destination, suffix)
1.47 +
1.48 # vim: tabstop=4 expandtab shiftwidth=4