/usr/share/pyshared/freevo/util/vfs.py is in python-freevo 1.9.2b2-4.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | # -*- coding: iso-8859-1 -*-
# -----------------------------------------------------------------------
# Virtual filesystem
# -----------------------------------------------------------------------
# $Id: vfs.py 11905 2011-11-14 21:54:46Z adam $
#
# Notes:
#
# This is a virtual filesystem for Freevo. It uses the structure in
# config.OVERLAY_DIR to store files that should be in the normal
# directory, but the user has no write access to it. It's meant to
# store fxd and image files (covers).
#
# Todo:
#
# -----------------------------------------------------------------------
# Freevo - A Home Theater PC framework
# Copyright (C) 2002 Krister Lagerstrom, et al.
# Please see the file freevo/Docs/CREDITS for a complete list of authors.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MER-
# CHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
# Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# -----------------------------------------------------------------------
import logging
logger = logging.getLogger("freevo.util.vfs")
import os
import copy
import traceback
import codecs
from stat import *
import config
def www_link_cachedir():
'''returns the www link cache directory name
if the directory does not exist it is created
'''
cache_dir = '%s/link_cache' % (config.WEBSERVER_CACHEDIR)
cache_dir_mode = S_IMODE(os.stat(config.WEBSERVER_CACHEDIR)[ST_MODE])
if not os.path.isdir(cache_dir):
os.makedirs(cache_dir, cache_dir_mode)
return cache_dir
def www_image_cachedir():
'''returns the www image cache directory name
if the directory does not exist it is created
'''
cache_dir = '%s/image_cache' % (config.WEBSERVER_CACHEDIR)
cache_dir_mode = S_IMODE(os.stat(config.WEBSERVER_CACHEDIR)[ST_MODE])
if not os.path.isdir(cache_dir):
os.makedirs(cache_dir, cache_dir_mode)
return cache_dir
def getoverlay(directory):
if not directory.startswith('/'):
directory = os.path.abspath(directory)
if directory.startswith(config.OVERLAY_DIR):
return directory
for media in config.REMOVABLE_MEDIA:
if directory.startswith(media.mountdir):
directory = directory[len(media.mountdir):]
return '%s/disc/%s%s' % (config.OVERLAY_DIR, String(media.id), directory)
return config.OVERLAY_DIR + directory
def getwwwoverlay(directory):
if not directory.startswith('/'):
directory = os.path.abspath(directory)
if directory.startswith(www_image_cachedir()):
return directory
return www_image_cachedir() + directory
def abspath(name):
"""
return the complete filename (including OVERLAY_DIR)
"""
if os.path.exists(name):
if not name.startswith('/'):
return os.path.abspath(name)
return name
overlay = getoverlay(name)
if overlay and os.path.isfile(overlay):
return overlay
return ''
def isfile(name):
"""
return if the given name is a file
"""
if os.path.isfile(name):
return True
overlay = getoverlay(name)
return overlay and os.path.isfile(overlay)
def unlink(name):
absname = abspath(name)
if not absname:
raise IOError, 'file %s not found' % name
os.unlink(absname)
def stat(name):
absname = abspath(name)
if not absname:
raise IOError, 'file %s not found' % name
return os.stat(absname)
def mtime(name):
"""
Return the modification time of the file. If the files also exists
in OVERLAY_DIR, return the max of both. If the file does not exist
in the normal directory, OSError is raised.
"""
t = os.stat(name)[ST_MTIME]
try:
return max(os.stat(getoverlay(name))[ST_MTIME], t)
except (OSError, IOError):
return t
def open(name, mode='r'):
"""
open the file
"""
try:
return file(name, mode)
except:
overlay = os.path.abspath(getoverlay(name))
if not overlay:
raise OSError
try:
if not os.path.isdir(os.path.dirname(overlay)):
os.makedirs(os.path.dirname(overlay), mode=04775)
except IOError:
_debug_('error creating dir %s' % os.path.dirname(overlay), DWARNING)
raise IOError
try:
return file(overlay, mode)
except IOError:
_debug_('error opening file %s' % overlay, DWARNING)
raise IOError
def codecs_open(name, mode, encoding):
"""
use codecs.open to open the file
"""
try:
return codecs.open(name, mode, encoding=encoding)
except:
overlay = os.path.abspath(getoverlay(name))
if not overlay:
raise OSError
try:
if not os.path.isdir(os.path.dirname(overlay)):
os.makedirs(os.path.dirname(overlay))
except IOError:
_debug_('error creating dir %s' % os.path.dirname(overlay), DWARNING)
raise IOError
try:
return codecs.open(overlay, mode, encoding=encoding)
except IOError, e:
_debug_('error opening file %s' % overlay, DWARNING)
raise IOError, e
def listdir(directory, handle_exception=True, include_dot_files=False, include_overlay=False):
"""
get a directory listing (including OVERLAY_DIR)
"""
try:
files = []
if include_dot_files:
for f in os.listdir(directory):
if not f in ('.svn', '.xvpics', '.thumbnails', '.pics', 'folder.fxd', 'lost+found'):
files.append(os.path.join(directory, f))
else:
for f in os.listdir(directory):
if not f.startswith('.') and not f in ('folder.fxd', 'lost+found'):
files.append(os.path.join(directory, f))
if not include_overlay:
return files
overlay = getoverlay(directory)
if overlay and overlay != directory and os.path.isdir(overlay):
for fname in os.listdir(overlay):
if fname.endswith('.raw') or fname.startswith('.') or fname in ('folder.fxd', 'lost+found') or \
fname.find('.thumb.') > 0:
continue
f = os.path.join(overlay, fname)
if not os.path.isdir(f):
files.append(f)
return files
except OSError, why:
_debug_('Cannot list dir %r: %s' % (directory, why), DWARNING)
traceback.print_exc()
if not handle_exception:
raise OSError
return []
def isoverlay(name):
"""
return if the name is in the overlay dir
"""
return name.startswith(config.OVERLAY_DIR)
def normalize(name):
"""
remove OVERLAY_DIR if it's in the path
"""
if isoverlay(name):
name = name[len(config.OVERLAY_DIR):]
if name.startswith('disc-set'):
# revert it, disc-sets have no real dir
return os.path.join(config.OVERLAY_DIR, name)
if name.startswith('disc'):
name = name[5:]
id = name[:name.find('/')]
name = name[name.find('/')+1:]
for media in config.REMOVABLE_MEDIA:
if media.id == id:
name = os.path.join(media.mountdir, name)
return name
return name
# some other os functions (you don't need to use them)
basename = os.path.basename
join = os.path.join
splitext = os.path.splitext
basename = os.path.basename
dirname = os.path.dirname
exists = os.path.exists
isdir = os.path.isdir
islink = os.path.islink
|