Mercurial > danboorufs
comparison danboorufs.py @ 6:2c81cc41de2d draft
Allow only a base directory for the tags, which will be recursively walked to find the actual tags files.
author | Emmanuel Gil Peyrot <linkmauve@linkmauve.fr> |
---|---|
date | Sun, 02 Dec 2012 19:15:17 +0100 |
parents | a422e75bf464 |
children | 09945ce42e28 |
comparison
equal
deleted
inserted
replaced
5:a422e75bf464 | 6:2c81cc41de2d |
---|---|
57 filename = name.replace('.tags', '') | 57 filename = name.replace('.tags', '') |
58 basename = os.path.basename(filename) | 58 basename = os.path.basename(filename) |
59 self.paths[basename] = filename | 59 self.paths[basename] = filename |
60 tags = [] | 60 tags = [] |
61 self.files[basename] = tags | 61 self.files[basename] = tags |
62 with open(name, 'r') as tagfile: | 62 with open(name, 'rb') as tagfile: |
63 for line in tagfile: | 63 for line in tagfile: |
64 for tag in line.split(): | 64 for tag in line.split(): |
65 try: | 65 try: |
66 tag = tag.decode('UTF-8') | 66 tag = tag.decode('UTF-8') |
67 except UnicodeDecodeError: | |
68 continue | |
67 except AttributeError: | 69 except AttributeError: |
68 pass | 70 pass |
69 tag = tag.replace('/', '�') #XXX | 71 tag = tag.replace('/', '�') #XXX |
70 tags.append(tag) | 72 tags.append(tag) |
71 self.tags.setdefault(tag, []).append(basename) | 73 self.tags.setdefault(tag, []).append(basename) |
187 def main(args): | 189 def main(args): |
188 mountpoint = args.pop() | 190 mountpoint = args.pop() |
189 | 191 |
190 if args[1] == '-n' or args[1] == '--no-symlinks': | 192 if args[1] == '-n' or args[1] == '--no-symlinks': |
191 use_symlinks = False | 193 use_symlinks = False |
192 filelist = args[1:] | 194 directory = args[2] |
193 else: | 195 else: |
194 use_symlinks = True | 196 use_symlinks = True |
195 filelist = args[2:] | 197 directory = args[1] |
198 | |
199 filelist = [] | |
200 start = time() | |
201 for (path, _, files) in os.walk(directory): | |
202 filelist.extend(os.path.join(path, filename) for filename in files | |
203 if filename.endswith('.tags')) | |
204 print('[%d] Walk done.' % (time() - start)) | |
196 | 205 |
197 FUSE(Danbooru(filelist, os.path.dirname(mountpoint), use_symlinks), | 206 FUSE(Danbooru(filelist, os.path.dirname(mountpoint), use_symlinks), |
198 mountpoint, foreground=True) | 207 mountpoint, foreground=True) |
199 | 208 |
200 | 209 |
201 if __name__ == '__main__': | 210 if __name__ == '__main__': |
202 if len(argv) < 3: | 211 if len(argv) < 3: |
203 print('USAGE: %s' % argv[0], '[-n|--no-symlinks]', | 212 print('USAGE: %s' % argv[0], '[-n|--no-symlinks]', |
204 '<tag file> [<tag file>...]', '<mountpoint>') | 213 '<tags directory>', '<mountpoint>') |
205 exit(1) | 214 exit(1) |
206 | 215 |
207 main(argv) | 216 main(argv) |