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