Changeset 314:248e3671b39b
- Timestamp:
- 2007-09-02 13:27:27 (1 year ago)
- Files:
-
- converter.py (modified) (2 diffs)
- dirtree.py (modified) (2 diffs)
- test_dirtree_posix.txt (modified) (1 diff)
- websourcebrowser.css (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
converter.py
r313 r314 110 110 add_html('</p>') 111 111 return "\n".join(html_parts) 112 113 def _directory_navigation(item, directory_tree, start_level, actual_dir_levels):114 """115 Return HTML code for the arrow links after directory items.116 The string `item` is assumed to be a path for a directory while117 `directory_tree` is a `dirtree.DirectoryTree` object containing118 relations between items. The integer `start_level` is the119 directory level for the root path the directory is displayed for.120 The integer `actual_dir_levels` is the depth of the directory tree121 as it should be displayed.122 """123 if dirtree.dir_level(item) - start_level == actual_dir_levels:124 return ""125 item_family = directory_tree.family[item]126 # use text ready for display in HTML code127 link_data = [(item_family.parent, "par"),128 (item_family.previous, "prev"),129 (item_family.next, "next")]130 links = []131 for relative, text in link_data:132 if relative:133 relative = urlpath.to_url(config.root, relative)134 anchor = tools.url_to_anchor(relative)135 links.append('<a href="#%s">%s</a>' %136 (anchor, text))137 else:138 links.append(text)139 return '<span class="DirLinks"> ' + " ".join(links) + '</span>'140 141 # mask `_directory_navigation` with dummy implementation for now142 def _directory_navigation(*args, **kwargs):143 return ""144 112 145 113 def dir_to_html(path, params): … … 211 179 # HTML for suffix 212 180 if os.path.isdir(item): 213 suffix = u' /%s' % \ 214 _directory_navigation(item, tree, start_level, 215 actual_dir_levels) 181 suffix = u' /' 216 182 else: 217 183 suffix = "" dirtree.py
r313 r314 132 132 return False 133 133 134 def _make_family_data(self, depth):135 """136 Generate family data. That is, for each item store an137 `_ItemFamily` object - with the parent item and the previous138 and next sibling items - in the instance variable `family`.139 If a value can't be determined, e. g. the previous sibling of140 the "first" item in a directory, it's set to `None`.141 """142 if not self.items:143 return144 # helper generator145 dir_items = [item for item in self.items if os.path.isdir(item)]146 # this helps to make the algorithm simpler147 family = {"": _ItemFamily()}148 # prepare "local" families for items149 for item in dir_items:150 family[item] = _ItemFamily()151 # remember the last item we encountered at each dir level as152 # mapping {dir_level: item (string)}153 previous_sibling = {}154 for item in dir_items:155 # make an alias for the family of this item156 item_family = family[item]157 ### set parent for this item158 item_family.parent = os.path.dirname(item)159 ### set previous sibling for this item160 # consider siblings at this dir level161 item_level = dir_level(item)162 # set a useful default163 previous_sibling.setdefault(item_level, "")164 # two items aren't siblings if they don't have the same parent165 if item_family.parent != \166 family[previous_sibling[item_level]].parent:167 item_family.previous = ""168 else:169 item_family.previous = previous_sibling[item_level]170 ### make this item the next sibling for its previous sibling171 if item_family.previous:172 family[item_family.previous].next = item173 # the current item is the previous sibling for the next item174 # on its dir level175 previous_sibling[item_level] = item176 # make some final corrections177 for item, item_family in family.iteritems():178 if item_family.parent == self.root:179 item_family.parent = ""180 # use `None` instead of the empty string in the end result181 item_family.parent = (item_family.parent or None)182 item_family.previous = (item_family.previous or None)183 item_family.next = (item_family.next or None)184 self.family = family185 186 134 def read(self, depth=sys.maxint): 187 135 """ … … 208 156 itertools.ifilterfalse(self._ignore_item, 209 157 self.walk(self.root, depth=depth))) 210 # determine parent and sibling items211 #self._make_family_data(depth=depth)212 158 213 159 def __str__(self): test_dirtree_posix.txt
r310 r314 80 80 False 81 81 82 After scanning the directory, the dictionary attribute ``family``83 contains information on how the file system items are related. For the84 following example, we set the items directly. In reality, the85 generation of the ``family`` data structure would happen upon reading86 the directory tree.87 88 >>> dt = dirtree.DirectoryTree("/the/root")89 >>> dt.items = [90 ... "/the/root/abc",91 ... "/the/root/abc/abc",92 ... "/the/root/abc/def",93 ... "/the/root/abc/ghi",94 ... "/the/root/def",95 ... "/the/root/def/abc",96 ... "/the/root/ghi"]97 >>> dt._make_family_data()98 >>> for item in dt.items:99 ... family = dt.family[item]100 ... print item, family.parent, family.previous, family.next101 /the/root/abc None None /the/root/def102 /the/root/abc/abc /the/root/abc None /the/root/abc/def103 /the/root/abc/def /the/root/abc /the/root/abc/abc /the/root/abc/ghi104 /the/root/abc/ghi /the/root/abc /the/root/abc/def None105 /the/root/def None /the/root/abc /the/root/ghi106 /the/root/def/abc /the/root/def None None107 /the/root/ghi None /the/root/def None108 109 Note that the root directory isn't considered as parent directory.110 This has to do with the application in Websourcebrowser. (We don't111 want to go "up" beyond the root directory.)112 websourcebrowser.css
r312 r314 14 14 padding-left: 3px; padding-right: 3px; } 15 15 span.Indent { color: #b0b0b0; font-size: 10px; } 16 span.DirLinks { color: #b0b0b0; }17 span.DirLinks a { color: black; }18 16 table { margin-top: 0px; padding-top: 0px; margin-bottom: 1em; } 19 17 body, .Main, table { font-size: 12px; }