| |-- a2.html
| `-- a3.html
`-- b
- |-- b1.html
+ |-- b1.svg
|-- b2.html
`-- b3.html
tag/
|-- 1
| |-- a1.html -> ../../raw/a/a1.html
- | `-- b1.html -> ../../raw/b/b1.html
+ | `-- b1.svg -> ../../raw/b/b1.svg
`-- x
|-- a2.html -> ../../raw/a/a2.html
|-- b3.html -> ../../raw/b/b3.html
`-- y
- `-- b1.html -> ../../../raw/b/b1.html
+ `-- b1.svg -> ../../../raw/b/b1.svg
Corresponding to the following tags::
a1.html 1
a2.html x
a3.html
- b1.html 1, x/y
+ b1.svg 1, x/y
b2.html
b3.html x
>>> print '\\n'.join(['|'.join(x) for x in t.traverse(depth=1)])
1
1|a1.html
- 1|b1.html
+ 1|b1.svg
x
x|y
- x|y|b1.html
+ x|y|b1.svg
x|a2.html
x|b3.html
>>> print '\\n'.join(['|'.join(x) for x in t.traverse(depth=1, type='files')])
1|a1.html
- 1|b1.html
- x|y|b1.html
+ 1|b1.svg
+ x|y|b1.svg
x|a2.html
x|b3.html
>>> print '\\n'.join(['|'.join(x) for x in t.traverse(depth=1, type='dirs')])
file test/raw a|a2.html x
file test/raw a|a3.html
dir test/raw b
- file test/raw b|b1.html 1,x/y
+ file test/raw b|b1.svg 1,x/y
file test/raw b|b2.html
file test/raw b|b3.html x
>>> print '\\n'.join(['|'.join(x) for x in d.elements(['x'])])
x|y
- x|y|b1.html
+ x|y|b1.svg
x|a2.html
x|b3.html
>>> print '\\n'.join(['|'.join(x) for x in d.tags()])
x|y
>>> print '\\n'.join(['|'.join(x) for x in d.tags(['b', 'b2.html'])])
<BLANKLINE>
- >>> print '\\n'.join(['|'.join(x) for x in d.tags(['b', 'b1.html'])])
+ >>> print '\\n'.join(['|'.join(x) for x in d.tags(['b', 'b1.svg'])])
1
x|y
>>> print d.tag_path(['a', 'a3.html'], ['x', 'y'])
test/tag/x/y/a3.html
>>> os.listdir('test/tag/x/y')
- ['b1.html']
+ ['b1.svg']
>>> d.add_tag(['a', 'a3.html'], ['x', 'y'])
>>> sorted(os.listdir('test/tag/x/y'))
- ['a3.html', 'b1.html']
+ ['a3.html', 'b1.svg']
>>> print 'Z'+os.path.realpath('test/tag/x/y/a3.html') # doctest: +ELLIPSIS
Z.../test/raw/a/a3.html
>>> d.remove_tag(['a', 'a3.html'], ['x', 'y'])
>>> os.listdir('test/tag/x/y')
- ['b1.html']
+ ['b1.svg']
"""
def __init__(self, raw_dir, tag_dir):
self.raw_dir = raw_dir
#!/usr/bin/env python
+from mimetypes import guess_type
from optparse import OptionParser
import os
from os import path
'/'.join(f),
self._dir_tags(f),
'file?%s' % urlencode({'selected':'/'.join(
- self.dirtag.raw_node(f))}))
+ self.dirtag.raw_node(f))}),
+ self._preview(f))
for f in s.tree.traverse(prefix=[s.root]+s[:-1],
depth=1,
type='files',
else:
return '-'
+ def _preview(self, node):
+ style = 'style="height=200px; width=200px;"'
+ type,encoding = guess_type(node[-1])
+ return ('<iframe %s src="static/raw/%s"></iframe>'
+ % (style, '/'.join(node)))
+ #elif node[-1].endswith('.jpg'):
+ # return ('<img %s " src="static/raw/%.s"/>'
+ # % (style, '/'.join(node)))
+ return 'Unknown filetype for %s' % node[-1]
+
@cherrypy.expose
def file(self, selected):
# Disable form value caching in Firefox. See
<tr>
<th>File</th>
<th>Tags</th>
+ <th>Preview</th>
</tr>
- {% for file,path,tags,tag_url in files %}
+ {% for file,path,tags,tag_url,preview in files %}
<tr>
<td><a href="static/raw/{{ path }}">{{ file }}</></td>
<td><a href="{{ tag_url }}">{{ tags }}</a></td>
+ <td>{{ preview }}</td>
</tr>
{% endfor %}
</table>
</ul>
<input type="submit" value="Set tags" />
</form>
-<iframe style="width:100%; height:500px" src="{{ selected_url }}"/>
+<iframe style="width:100%; height:500px" src="{{ selected_url }}"></iframe>
</body>
+++ /dev/null
-<html><head/><body><h1>b1.html</h1></body></html>
--- /dev/null
+<?xml version="1.0" standalone="no"?>
+<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
+"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
+
+
+<svg xmlns="http://www.w3.org/2000/svg" version="1.1"
+ width="100%" height="100%" viewBox="0 0 300 300">
+ <title>b1.svg</title>
+ <circle cx="150" cy="150" r="100" stroke="black"
+ stroke-width="2" fill="yellow"/>
+ <text x="150" y="150" text-anchor="middle">
+ b1.svg
+ </text>
+</svg>
+++ /dev/null
-../../raw/b/b1.html
\ No newline at end of file
--- /dev/null
+../../raw/b/b1.svg
\ No newline at end of file
+++ /dev/null
-../../../raw/b/b1.html
\ No newline at end of file
--- /dev/null
+../../../raw/b/b1.svg
\ No newline at end of file