Package flumotion :: Package common :: Module vfsgnome
[hide private]

Source Code for Module flumotion.common.vfsgnome

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3  # 
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2008 Fluendo, S.L. (www.fluendo.com). 
  6  # All rights reserved. 
  7   
  8  # This file may be distributed and/or modified under the terms of 
  9  # the GNU General Public License version 2 as published by 
 10  # the Free Software Foundation. 
 11  # This file is distributed without any warranty; without even the implied 
 12  # warranty of merchantability or fitness for a particular purpose. 
 13  # See "LICENSE.GPL" in the source distribution for more information. 
 14   
 15  # Licensees having purchased or holding a valid Flumotion Advanced 
 16  # Streaming Server license may use this file in accordance with the 
 17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
 18  # See "LICENSE.Flumotion" in the source distribution for more information. 
 19   
 20  # Headers in this file shall remain intact. 
 21   
 22  """GnomeVFS backend for Virtual File System. 
 23  """ 
 24   
 25  import os 
 26   
 27  from twisted.internet.defer import succeed 
 28  from twisted.spread.flavors import Copyable, RemoteCopy 
 29  from twisted.spread.jelly import setUnjellyableForClass 
 30  from zope.interface import implements 
 31   
 32  from flumotion.common import log 
 33  from flumotion.common.errors import AccessDeniedError 
 34  from flumotion.common.interfaces import IDirectory, IFile 
 35   
 36  # gnomevfs is only imported inside nested scopes so that 
 37  # pychecker can ignore them, If pychecker ever gets fixed, 
 38  # move it back where it belongs 
 39  __pychecker__ = 'keepgoing' 
 40   
 41   
42 -class GnomeVFSFile(Copyable, RemoteCopy):
43 """I am object implementing L{IFile} on top of GnomeVFS, 44 see L{IFile} for more information. 45 """ 46 implements(IFile) 47
48 - def __init__(self, parent, fileInfo):
49 self.parent = parent 50 self.filename = fileInfo.name 51 self.iconNames = ['gnome-fs-regular']
52 53 # IFile 54
55 - def getPath(self):
56 return os.path.join(self.parent, self.filename)
57 58
59 -class GnomeVFSDirectory(Copyable, RemoteCopy):
60 """I am object implementing L{IDirectory} on top of GnomeVFS, 61 see L{IDirectory} for more information. 62 """ 63 implements(IDirectory) 64
65 - def __init__(self, path):
66 import gnomevfs 67 fileInfo = gnomevfs.get_file_info(os.path.abspath(path)) 68 self.path = path 69 self.filename = fileInfo.name 70 self.iconNames = ['gnome-fs-directory']
71 72 # IFile 73
74 - def getPath(self):
75 return self.path
76 77 # IDirectory 78
79 - def getFiles(self):
80 import gnomevfs 81 log.info('vfsgnome', 'getting files for %s' % (self.path,)) 82 retval = [] 83 try: 84 fileInfos = gnomevfs.open_directory(self.path) 85 except gnomevfs.AccessDeniedError: 86 raise AccessDeniedError 87 for fileInfo in fileInfos: 88 filename = fileInfo.name 89 if filename.startswith('.') and filename != '..': 90 continue 91 if fileInfo.type == gnomevfs.FILE_TYPE_DIRECTORY: 92 obj = GnomeVFSDirectory(os.path.join(self.path, 93 fileInfo.name)) 94 else: 95 obj = GnomeVFSFile(self.path, fileInfo) 96 retval.append(obj) 97 log.info('vfsgnome', 'returning %r' % (retval,)) 98 return succeed(retval)
99 100
101 -def registerGnomeVFSJelly():
102 """Register the jelly used by the GnomeVFS VFS backend. 103 """ 104 setUnjellyableForClass(GnomeVFSFile, GnomeVFSFile) 105 setUnjellyableForClass(GnomeVFSDirectory, GnomeVFSDirectory) 106 log.info('jelly', 'GnomeVFS registered')
107