git » abk » commit 3e2ed1b

Update main loop.

author
2005-03-02 19:12:46 UTC
committer
2005-03-02 19:12:46 UTC
parent 87185c9bcde2e75cd4be2cd06259716c2707bac2

Update main loop.
Main loop updates, making it a bit more user friendly, and small optimizations
(ie. metadata is now updated in-place since we know the path is walked
properly).

abk +24 -22

diff --git a/abk b/abk
index bb5bea4..4e14a38 100644
--- a/abk
+++ b/abk
@@ -272,53 +272,55 @@ def make_path(f):
 #
 # main
 #
-src_path = sys.argv[1]
-srcidx_path = sys.argv[2]
-dst_path = sys.argv[3]
-dstidx_path = sys.argv[4]
+try:
+	src_path = sys.argv[1]
+	srcidx_path = sys.argv[2]
+	dst_path = sys.argv[3]
+	dstidx_path = sys.argv[4]
+except:
+	print "Use: abk srcdir src.idx dstdir dst.idx"
+	sys.exit(1)
 
 # load destination index
+print "destination index"
 dstidx = index_file(dstidx_path)
 dstidx.load()
 
 # create source index
+print "source index"
 srcidx = index_file(srcidx_path)
 srcidx.populate(src_path)
 srcidx.save()
 
-# compare them
-updated_files = []
+print "sync"
 
+# compare them
 for f in srcidx.names:
 	if f not in dstidx.names or not srcidx.db[f].cmp_data(dstidx.db[f]):
 		# files missing in destination, or data changed
 		dst = os.path.join(dst_path, f)
-		print 'data', f, dst
+		print 'data\t', f, dst
 		quiet_unlink(dst)
 		srcidx.db[f].copy_file(dst)
-		updated_files.append((f, dst))
+		srcidx.db[f].update_mdata(dst)
 	elif not srcidx.db[f].cmp_mdata(dstidx.db[f]):
 		# metadata changed
-		print 'mdata', f, dst
 		dst = os.path.join(dst_path, f)
-		updated_files.append((f, dst))
+		print 'mdata\t', f, dst
+		try:
+			srcidx.db[f].update_mdata(dst)
+		except:
+			# it can fail if the destination doesn't have the
+			# file, ignore for now; TODO: output some kind of
+			# script so people can run it later when they get all
+			# back together
+			pass
 
 for f in dstidx.names:
 	if f not in srcidx.names:
 		# files in destination and not in source
 		dst = os.path.join(dst_path, f)
-		print 'unlink', f, dst
+		print 'unlink\t', f, dst
 		force_unlink(dst, dstidx.db[f].type)
 
-# update metadata
-for f, dst in updated_files:
-	print 'update', f, dst
-	try:
-		srcidx.db[f].update_mdata(dst)
-	except:
-		# it can fail if the destination doesn't have the file, ignore
-		# TODO: output some kind of script so people can run it later
-		# when they get all back together
-		pass
-