2 # fs.py: public Python interface for fs components
4 # Subversion is a tool for revision control.
5 # See http://subversion.tigris.org for more information.
7 ######################################################################
9 # Copyright (c) 2000-2004 CollabNet. All rights reserved.
11 # This software is licensed as described in the file COPYING, which
12 # you should have received as part of this distribution. The terms
13 # are also available at http://subversion.tigris.org/license-1.html.
14 # If newer versions of this license are posted there, you may use a
15 # newer version instead, at your option.
17 ######################################################################
19 from libsvn
.fs
import *
20 from svn
.core
import _unprefix_names
, Pool
21 _unprefix_names(locals(), 'svn_fs_')
22 _unprefix_names(locals(), 'SVN_FS_')
26 # Names that are not to be exported
27 import sys
as _sys
, os
as _os
, popen2
as _popen2
, tempfile
as _tempfile
29 import svn
.core
as _svncore
32 def entries(root
, path
, pool
=None):
33 "Call dir_entries returning a dictionary mappings names to IDs."
34 e
= dir_entries(root
, path
, pool
)
35 for name
, entry
in e
.items():
36 e
[name
] = dirent_t_id_get(entry
)
41 def __init__(self
, root1
, path1
, root2
, path2
, pool
=None, diffoptions
=[]):
51 self
.diffoptions
= diffoptions
53 def either_binary(self
):
54 "Return true if either of the files are binary."
55 if self
.path1
is not None:
56 prop
= node_prop(self
.root1
, self
.path1
, _svncore
.SVN_PROP_MIME_TYPE
)
57 if prop
and _svncore
.svn_mime_type_is_binary(prop
):
59 if self
.path2
is not None:
60 prop
= node_prop(self
.root2
, self
.path2
, _svncore
.SVN_PROP_MIME_TYPE
)
61 if prop
and _svncore
.svn_mime_type_is_binary(prop
):
65 def _dump_contents(self
, file, root
, path
, pool
=None):
66 fp
= __builtin__
.open(file, 'w+') # avoid namespace clash with
67 # trimmed-down svn_fs_open()
69 stream
= file_contents(root
, path
, pool
)
72 chunk
= _svncore
.svn_stream_read(stream
, _svncore
.SVN_STREAM_CHUNK_SIZE
)
77 _svncore
.svn_stream_close(stream
)
83 # no need to do more. we ran this already.
84 return self
.tempfile1
, self
.tempfile2
86 # Make tempfiles, and dump the file contents into those tempfiles.
87 self
.tempfile1
= _tempfile
.mktemp()
88 self
.tempfile2
= _tempfile
.mktemp()
90 self
._dump
_contents
(self
.tempfile1
, self
.root1
, self
.path1
)
91 self
._dump
_contents
(self
.tempfile2
, self
.root2
, self
.path2
)
93 return self
.tempfile1
, self
.tempfile2
98 # use an array for the command to avoid the shell and potential
102 + [self
.tempfile1
, self
.tempfile2
]
104 # the windows implementation of popen2 requires a string
105 if _sys
.platform
== "win32":
106 cmd
= _svncore
.argv_to_command_string(cmd
)
108 # open the pipe, forget the end for writing to the child (we won't),
109 # and then return the file object for reading from the child.
110 fromchild
, tochild
= _popen2
.popen2(cmd
)
115 # it seems that sometimes the files are deleted, so just ignore any
116 # failures trying to remove them
117 if self
.tempfile1
is not None:
119 _os
.remove(self
.tempfile1
)
122 if self
.tempfile2
is not None:
124 _os
.remove(self
.tempfile2
)