773
773
return [t % my_map for t in self.command_template]
775
775
def _execute(self, old_path, new_path):
776
proc = subprocess.Popen(self._get_command(old_path, new_path),
777
stdout=subprocess.PIPE, cwd=self._root)
776
command = self._get_command(old_path, new_path)
778
proc = subprocess.Popen(command, stdout=subprocess.PIPE,
781
if e.errno == errno.ENOENT:
782
raise errors.ExecutableMissing(command[0])
778
785
self.to_file.write(proc.stdout.read())
779
786
return proc.wait()
781
def _write_file(self, file_id, tree, prefix, old_path):
782
full_old_path = osutils.pathjoin(self._root, prefix, old_path)
783
parent_dir = osutils.dirname(full_old_path)
788
def _try_symlink_root(self, tree, prefix):
789
if not (getattr(tree, 'abspath', None) is not None
790
and osutils.has_symlinks()):
793
os.symlink(tree.abspath(''), osutils.pathjoin(self._root, prefix))
795
if e.errno != errno.EEXIST:
799
def _write_file(self, file_id, tree, prefix, relpath):
800
full_path = osutils.pathjoin(self._root, prefix, relpath)
801
if self._try_symlink_root(tree, prefix):
803
parent_dir = osutils.dirname(full_path)
785
805
os.makedirs(parent_dir)
786
806
except OSError, e:
787
807
if e.errno != errno.EEXIST:
789
source = tree.get_file(file_id)
809
source = tree.get_file(file_id, relpath)
791
target = open(full_old_path, 'wb')
811
target = open(full_path, 'wb')
793
813
osutils.pumpfile(source, target)
818
osutils.make_readonly(full_path)
819
mtime = tree.get_file_mtime(file_id)
820
os.utime(full_path, (mtime, mtime))
800
823
def _prepare_files(self, file_id, old_path, new_path):
801
824
old_disk_path = self._write_file(file_id, self.old_tree, 'old',
805
828
return old_disk_path, new_disk_path
807
830
def finish(self):
808
shutil.rmtree(self._root)
831
osutils.rmtree(self._root)
810
833
def diff(self, file_id, old_path, new_path, old_kind, new_kind):
811
834
if (old_kind, new_kind) != ('file', 'file'):