git » abk » commit d6d7f09

Implement multiple copy modes and a small config.

author
2005-03-03 00:42:48 UTC
committer
2005-03-03 00:42:48 UTC
parent e2db9556e1680a982a6ec3a0c003abeafc7bac1f

Implement multiple copy modes and a small config.

abk +36 -5

diff --git a/abk b/abk
index f6437c5..6247df8 100644
--- a/abk
+++ b/abk
@@ -2,11 +2,20 @@
 
 import sys
 import os
-import bz2
 import sha
 import cPickle
 from stat import *
 
+#
+# configuration
+#
+class config:
+	# copy mode; can be "raw", "gzip", "bzip2"
+	copy_mode = 'bzip2'
+
+	# use_hash; true or false
+	use_hash = 1
+
 
 #
 # constants
@@ -34,6 +43,13 @@ class file_info:
 		self.rdev = None
 		self.hash = None
 		self.stat = None
+		
+		if config.copy_mode == 'raw':
+			self.copy_file_reg = self.copy_file_reg_raw
+		elif config.copy_mode == 'gzip':
+			self.copy_file_reg = self.copy_file_reg_gzip
+		elif config.copy_mode == 'bzip2':
+			self.copy_file_reg = self.copy_file_reg_bzip2
 
 	def __repr__(self):
 		return "<%s: %s %d>" % (self.name, self.type, self.size)
@@ -67,8 +83,7 @@ class file_info:
 		self.uid = s.st_uid
 		self.gid = s.st_gid
 
-		# FIXME: hacer opcional para Damian
-		if self.type == 'r':
+		if config.use_hash and self.type == 'r':
 			self.hash = self.hash_file()
 
 	def cmp_mdata(self, other):
@@ -103,7 +118,7 @@ class file_info:
 	def __ne__(self, other):
 		return not (self == other)
 
-	def UNUSED_copy_file_reg(self, dst):
+	def copy_file_reg_raw(self, dst):
 		"Copy a regular file."
 		sfile = open(self.name, 'r')
 		dfile = open(dst, 'w')
@@ -117,8 +132,9 @@ class file_info:
 		sfile.close()
 		dfile.close()
 
-	def copy_file_reg(self, dst):
+	def copy_file_reg_bzip2(self, dst):
 		"Copy a regular file, destination is bz2 compressed."
+		import bz2
 		sfile = open(self.name)
 		dfile = open(dst, 'w')
 
@@ -131,6 +147,21 @@ class file_info:
 		sfile.close()
 		dfile.close()
 
+	def copy_file_reg_gz(self, dst):
+		"Copy a regular file, destination is gzip compressed."
+		import gzip
+		sfile = open(self.name)
+		dfile = gzip.open(dst, 'w')
+
+		data = sfile.read(PSIZE)
+		while data:
+			dfile.write(data)
+			data = sfile.read(PSIZE)
+
+		sfile.close()
+		dfile.close()
+	
+
 	def copy_file_link(self, dst):
 		"Copy a symbolic link."
 		linkto = os.readlink(self.name)