2
# Abstraction layer for VFS operations to move gnomevfs dependency out of the
13
OPEN_READ = gnomevfs.OPEN_READ
14
OPEN_WRITE = gnomevfs.OPEN_WRITE
18
import gnome.vfs as gnomevfs
20
OPEN_READ = gnomevfs.OPEN_READ
21
OPEN_WRITE = gnomevfs.OPEN_WRITE
24
log("Using urllib, because gnomevfs isn't available")
35
return gnomevfs.escape_string(uri)
37
return escape_path_urllib(uri)
39
def escape_path_urllib(uri):
41
return urllib.quote(uri)
45
def unescape_path(uri):
47
return urllib.unquote(uri)
52
# Reads the entire file and returns its contents.
54
def read_entire_file(uri):
57
uri = gnomevfs.read_entire_file(uri)
59
log("Warning: Couldn't read file \"%s\"." % (uri,))
64
def read_entire_file_urllib(uri):
66
if (not "://" in uri): uri = "file://" + uri
69
uri = urllib.urlopen(uri).read()
71
log("Warning: Couldn't read file \"%s\"." % (uri,))
79
# Opens the given URI and returns a file descriptor.
81
def open(uri, mode = OPEN_READ):
84
fd = gnomevfs.open(uri, mode)
86
log("Warning: Couldn't open file \"%s\"." % (uri,))
91
def open_urllib(uri, mode = OPEN_READ):
93
if (not "://" in uri): uri = "file://" + uri
96
fd = urllib.urlopen(uri)
98
log("Warning: Couldn't open file \"%s\"." % (uri,))
106
# Returns whether the given URI exists.
110
return gnomevfs.exists(gnomevfs.URI(uri))
112
def exists_urllib(uri):
114
if (not "://" in uri): uri = "file://" + uri
125
if (not USE_GNOMEVFS):
126
read_entire_file = read_entire_file_urllib
128
exists = exists_urllib
129
escape_path = escape_path_urllib