14 fuse.fuse_python_api = (0, 2)
20 class EmptyStat(fuse.Stat):
35 def __init__(self, *args, **kw):
36 Fuse.__init__(self, *args, **kw)
39 def getattr(self, path):
42 if path == '/' or path in projects or len(filter(lambda x: x.startswith(path), projects)) > 0:
43 st.st_mode = stat.S_IFDIR | 0555
47 if os.path.dirname(path) in projects:
48 st.st_mode = stat.S_IFDIR | 0555
52 file = os.path.basename(path)
53 if files.has_key(file):
58 def readdir(self, path, offset):
59 yield fuse.Direntry('.')
60 yield fuse.Direntry('..')
62 if os.path.dirname(path) in projects: # path is package
63 prj = os.path.dirname(path).replace('/','')
64 pkg = os.path.basename(path)
66 for f in osc.core.meta_get_filelist(osc.conf.config['apiurl'], prj, pkg, verbose=True):
68 st.st_mode = stat.S_IFREG | 0444
74 yield fuse.Direntry(f.name)
77 if path in projects: # path is project
78 prj = path.replace('/','')
79 for p in osc.core.meta_get_packagelist(osc.conf.config['apiurl'], prj):
80 yield fuse.Direntry(p)
82 else: # path is project structure
86 for d in set( map(lambda x: x[l:].split('/')[0], filter(lambda x: x.startswith(path), projects) ) ) :
87 yield fuse.Direntry(d)
89 def mythread ( self ):
93 def chmod ( self, path, mode ):
94 print '*** chmod', path, oct(mode)
97 def chown ( self, path, uid, gid ):
98 print '*** chown', path, uid, gid
101 def fsync ( self, path, isFsyncFile ):
102 print '*** fsync', path, isFsyncFile
105 def link ( self, targetPath, linkPath ):
106 print '*** link', targetPath, linkPath
109 def mkdir ( self, path, mode ):
110 print '*** mkdir', path, oct(mode)
113 def mknod ( self, path, mode, dev ):
114 print '*** mknod', path, oct(mode), dev
117 def open ( self, path, flags ):
118 file = os.path.basename(path)
119 d = os.path.dirname(path)
120 pkg = os.path.basename(d)
121 prj = os.path.dirname(d).replace('/','')
122 if not cache.has_key(path):
123 tmp = tempfile.mktemp(prefix = 'oscfs_')
124 osc.core.get_source_file(osc.conf.config['apiurl'], prj, pkg, file, tmp)
126 cache[path] = (f, tmp)
128 def read ( self, path, length, offset ):
129 if not cache.has_key(path):
133 return f.read(length)
135 def readlink ( self, path ):
136 print '*** readlink', path
139 def release ( self, path, flags ):
140 if cache.has_key(path):
141 cache[path][0].close()
142 os.unlink(cache[path][1])
145 def rename ( self, oldPath, newPath ):
146 print '*** rename', oldPath, newPath
149 def rmdir ( self, path ):
150 print '*** rmdir', path
157 def symlink ( self, targetPath, linkPath ):
158 print '*** symlink', targetPath, linkPath
161 def truncate ( self, path, size ):
162 print '*** truncate', path, size
165 def unlink ( self, path ):
166 print '*** unlink', path
169 def utime ( self, path, times ):
170 print '*** utime', path, times
173 def write ( self, path, buf, offset ):
174 print '*** write', path, buf, offset
178 for prj in osc.core.meta_get_project_list(osc.conf.config['apiurl']):
179 projects.append( '/' + prj.replace(':', ':/') )
181 if __name__ == '__main__':
182 print 'Loading config ...',
183 osc.conf.get_config()
185 print 'Getting projects list ...',
188 print 'Starting FUSE ...',
189 oscfs = oscFS( version = '%prog ' + fuse.__version__, usage = '', dash_s_do = 'setsingle')
191 oscfs.multithreaded = 0
192 oscfs.parse(values = oscfs, errex = 1)