1
#########################################################################
4
# copyright 2002 Paul Henry Tremblay #
6
# This program is distributed in the hope that it will be useful, #
7
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
8
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU #
9
# General Public License for more details. #
11
# You should have received a copy of the GNU General Public License #
12
# along with this program; if not, write to the Free Software #
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA #
17
#########################################################################
20
"""Copy each changed file to a directory for debugging purposes"""
22
def __init__(self, bug_handler, file = None, deb_dir = None, ):
24
self.__bug_handler = bug_handler
25
def set_dir(self, deb_dir):
26
"""Set the temporary directory to write files to"""
28
message = "No directory has been provided to write to in the copy.py"
29
raise self.__bug_handler, message
30
check = os.path.isdir(deb_dir)
32
message = "%(deb_dir)s is not a directory" % vars()
33
raise self.__bug_handler , message
35
def remove_files(self ):
36
"""Remove files from directory"""
37
self.__remove_the_files(Copy.__dir)
39
list_of_files = os.listdir(Copy.__dir)
40
list_of_files = os.listdir(the_dir)
41
for file in list_of_files:
42
rem_file = os.path.join(Copy.__dir,file)
43
if os.path.isdir(rem_file):
44
self.remove_files(rem_file)
48
def __remove_the_files(self, the_dir):
49
"""Remove files from directory"""
50
list_of_files = os.listdir(the_dir)
51
for file in list_of_files:
52
rem_file = os.path.join(Copy.__dir,file)
53
if os.path.isdir(rem_file):
54
self.__remove_the_files(rem_file)
60
def copy_file(self, file, new_file):
62
Copy the file to a new name
63
If the platform is linux, use the faster linux command
64
of cp. Otherwise, use a safe python method.
66
write_file = os.path.join(Copy.__dir,new_file)
67
platform = sys.platform
68
if platform[:5] == 'linux':
69
command = 'cp %(file)s %(write_file)s' % vars()
72
read_obj = open(file,'r')
73
write_obj = open(write_file, 'w')
76
line = read_obj.read(1000)
77
write_obj.write(line )
80
def rename(self, source, dest):
81
read_obj = open(source, 'r')
82
write_obj = open(dest, 'w')
85
line = read_obj.readline()