Show More
@@ -4,7 +4,7 b' Authors : MinRK, gregcaporaso' | |||
|
4 | 4 | """ |
|
5 | 5 | |
|
6 | 6 | from os import walk |
|
7 | from os.path import exists, isfile, splitext | |
|
7 | from os.path import exists, isfile, splitext, abspath | |
|
8 | 8 | |
|
9 | 9 | |
|
10 | 10 | class YouTubeVideo(object): |
@@ -52,7 +52,7 b' class FileLink(object):' | |||
|
52 | 52 | FileLink("my/data.txt") |
|
53 | 53 | """ |
|
54 | 54 | |
|
55 | link_str = "<a href='%s' target='_blank'>%s</a>" | |
|
55 | html_link_str = "<a href='%s' target='_blank'>%s</a>" | |
|
56 | 56 | |
|
57 | 57 | def __init__(self, |
|
58 | 58 | path, |
@@ -76,11 +76,11 b' class FileLink(object):' | |||
|
76 | 76 | def _format_path(self): |
|
77 | 77 | fp = '/'.join([self.url_prefix,self.path]) |
|
78 | 78 | return ''.join([self.result_html_prefix, |
|
79 | self.link_str % (fp, self.path), | |
|
79 | self.html_link_str % (fp, self.path), | |
|
80 | 80 | self.result_html_suffix]) |
|
81 | 81 | |
|
82 | 82 | def _repr_html_(self): |
|
83 |
"""return link to |
|
|
83 | """return html link to file | |
|
84 | 84 | """ |
|
85 | 85 | if not exists(self.path): |
|
86 | 86 | return ("Path (<tt>%s</tt>) doesn't exist. " |
@@ -90,9 +90,14 b' class FileLink(object):' | |||
|
90 | 90 | |
|
91 | 91 | return self._format_path() |
|
92 | 92 | |
|
93 | def __repr__(self): | |
|
94 | """return path to file | |
|
95 | """ | |
|
96 | return abspath(self.path) | |
|
97 | ||
|
93 | 98 | # Create an alias for formatting a single directory name as a link. |
|
94 | 99 | # Right now this is the same as a formatting for a single file, but |
|
95 | # we'll encorage users to reference these with a different class in | |
|
100 | # we'll encourage users to reference these with a different class in | |
|
96 | 101 | # case we want to change this in the future. |
|
97 | 102 | DirectoryLink = FileLink |
|
98 | 103 | |
@@ -135,12 +140,12 b' class FileLinks(FileLink):' | |||
|
135 | 140 | result_entries = [] |
|
136 | 141 | for root, dirs, files in walk(self.path): |
|
137 | 142 | for fn in files: |
|
138 | fp = join(self.url_prefix,root,fn) | |
|
143 | fp = '/'.join([self.url_prefix,root,fn]) | |
|
139 | 144 | # if all files are being included, or fp has a suffix |
|
140 | 145 | # that is in included_suffix, create a link to fp |
|
141 | 146 | if self.included_suffixes == None or \ |
|
142 | 147 | splitext(fn)[1] in self.included_suffixes: |
|
143 | 148 | result_entries.append(''.join([self.result_html_prefix, |
|
144 | self.link_str % (fp,fn), | |
|
149 | self.html_link_str % (fp,fn), | |
|
145 | 150 | self.result_html_suffix])) |
|
146 | 151 | return '\n'.join(result_entries) |
General Comments 0
You need to be logged in to leave comments.
Login now