git » abk » commit de728a6

Add a "rebuild index" option (mostly for debug purposes).

author
2005-03-03 01:45:50 UTC
committer
2005-03-03 01:45:50 UTC
parent 138876b32b18f33bce355ff3907f0f1097bfd7c0

Add a "rebuild index" option (mostly for debug purposes).

abk +28 -0

diff --git a/abk b/abk
index ee4f4da..0cd91ea 100644
--- a/abk
+++ b/abk
@@ -414,6 +414,24 @@ def show_idx(idx_path):
 		print "%s %d %f %s %s" % (fi.type, fi.size, fi.mtime,
 				str(fi.hash), fi.name)
 
+def build_idx(idx_path, path):
+	print "* building index"
+
+	# see comments in make_sync()
+	while path[-1] == '/' and path != '/':
+		path = path[:-1]
+	idx_path = os.path.join(os.getcwd(), idx_path)
+	if path != '/':
+		parent, src = os.path.split(path)
+		if parent:
+			os.chdir(parent)
+			path = src
+
+	# build the index
+	idx = index_file(idx_path)
+	idx.populate(path)
+	idx.save()
+
 
 #
 # main
@@ -426,6 +444,8 @@ Use: abk command params
 Commands:
 	show idx_file
 		Shows the given index file contents.
+	mkidx idx_file dir
+		Builds an index file for the given directory.
 	sync src src.idx dst dst.idx
 		Synchronizes src with dst, using the given index files.
 """
@@ -463,6 +483,14 @@ if cmd == 'show':
 		print "Incorrect or missing parameters"
 		sys.exit(1)
 	show_idx(sys.argv[2])
+elif cmd == 'mkidx':
+	try:
+		idx_path = sys.argv[2]
+		path = sys.argv[3]
+	except:
+		print "Incorrect or missing parameters"
+		sys.exit(1)
+	build_idx(idx_path, path)
 elif cmd == 'sync':
 	try:
 		src_path = sys.argv[2]