comparison danboorufs.py @ 3:880904f1071f draft

Add python3 support.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 21 Aug 2012 21:21:47 +0200
parents 85cbd44f98b1
children c40f0eed70cd
comparison
equal deleted inserted replaced
2:85cbd44f98b1 3:880904f1071f
1 #!/usr/bin/env python2 1 #!/usr/bin/env python
2 # -*- encoding: utf-8 -*- 2 # -*- encoding: utf-8 -*-
3 # 3 #
4 # 4 #
5 # Copyright © 2012 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> 5 # Copyright © 2012 Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
6 # 6 #
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23 # SOFTWARE. 23 # SOFTWARE.
24 24
25 25
26 from __future__ import with_statement 26 from __future__ import with_statement, unicode_literals
27 27
28 from errno import ENOENT, ENOTDIR 28 from errno import ENOENT, ENOTDIR
29 from sys import argv 29 from sys import argv
30 from threading import Lock 30 from threading import Lock
31 from time import time 31 from time import time
32 from functools import reduce
32 33
33 import os 34 import os
34 35
35 from fuse import FUSE, FuseOSError, Operations, LoggingMixIn 36 from fuse import FUSE, FuseOSError, Operations, LoggingMixIn
36 37
59 tags = [] 60 tags = []
60 self.files[basename] = tags 61 self.files[basename] = tags
61 with open(name, 'r') as tagfile: 62 with open(name, 'r') as tagfile:
62 for line in tagfile: 63 for line in tagfile:
63 for tag in line.split(): 64 for tag in line.split():
64 tag = tag.decode('UTF-8') 65 try:
65 tag = tag.replace('/', u'�') #XXX 66 tag = tag.decode('UTF-8')
67 except AttributeError:
68 pass
69 tag = tag.replace('/', '�') #XXX
66 tags.append(tag) 70 tags.append(tag)
67 self.tags.setdefault(tag, []).append(basename) 71 self.tags.setdefault(tag, []).append(basename)
68 72
69 print('[%d] Index done.' % (time() - start)) 73 print('[%d] Index done.' % (time() - start))
70 74
115 os.lseek(file_handle, offset, 0) 119 os.lseek(file_handle, offset, 0)
116 return os.read(file_handle, size) 120 return os.read(file_handle, size)
117 121
118 def readdir(self, path, file_handle): 122 def readdir(self, path, file_handle):
119 if path == '/': 123 if path == '/':
120 return ['.', '..'] + self.tags.keys() + self.files.keys() 124 return (['.', '..'] + list(self.tags.keys())
125 + list(self.files.keys()))
121 126
122 tags, filename = self._split_path(path) 127 tags, filename = self._split_path(path)
123 if filename: 128 if filename:
124 return FuseOSError(ENOTDIR) 129 return FuseOSError(ENOTDIR)
125 130