Skip to content

Commit 67a6e3e

Browse files
committed
Limit usage of posixpath to the minimum
* this may not get the right results on Windows * also improve the usage of default_template Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 15957f5 commit 67a6e3e

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

src/attributecode/attrib.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,20 @@
2222
import collections
2323
import datetime
2424
import os
25-
from posixpath import basename
26-
from posixpath import dirname
27-
from posixpath import exists
28-
from posixpath import join
2925

3026
import jinja2
3127

32-
import attributecode
3328
from attributecode import ERROR
3429
from attributecode import Error
3530
from attributecode.licenses import COMMON_LICENSES
3631
from attributecode.model import parse_license_expression
3732
from attributecode.util import add_unc
33+
from attributecode.util import get_about_file_path
34+
35+
36+
# FIXME: the template dir should be outside the code tree
37+
default_template = os.path.join(
38+
os.path.dirname(os.path.realpath(__file__)), 'templates', 'default_html.template')
3839

3940

4041
def generate(abouts, template_string=None, vartext_dict=None):
@@ -130,17 +131,11 @@ def check_template(template_string):
130131
return e.lineno, e.message
131132

132133

133-
# FIXME: the template dir should be outside the code tree
134-
default_template = join(os.path.dirname(os.path.realpath(__file__)),
135-
'templates', 'default_html.template')
136-
137-
def generate_from_file(abouts, template_loc=None, vartext_dict=None):
134+
def generate_from_file(abouts, template_loc=default_template, vartext_dict=None):
138135
"""
139136
Generate and return attribution string from a list of About objects and a
140137
template location.
141138
"""
142-
if not template_loc:
143-
template_loc = default_template
144139
template_loc = add_unc(template_loc)
145140
with codecs.open(template_loc, 'rb', encoding='utf-8') as tplf:
146141
tpls = tplf.read()
@@ -152,6 +147,7 @@ def generate_and_save(abouts, output_location, use_mapping=False, mapping_file=N
152147
"""
153148
Generate attribution file using the `abouts` list of About object
154149
at `output_location`.
150+
Return a list of errors if any.
155151
156152
Optionally use the mapping.config file if `use_mapping` is True.
157153
@@ -173,7 +169,7 @@ def generate_and_save(abouts, output_location, use_mapping=False, mapping_file=N
173169
updated_abouts = abouts
174170
# Do the following if an filter list (inventory_location) is provided
175171
else:
176-
if not exists(inventory_location):
172+
if not os.path.exists(inventory_location):
177173
# FIXME: this message does not make sense
178174
msg = (u'"INVENTORY_LOCATION" does not exist. Generation halted.')
179175
errors.append(Error(ERROR, msg))
@@ -184,7 +180,7 @@ def generate_and_save(abouts, output_location, use_mapping=False, mapping_file=N
184180

185181
try:
186182
# Return a list which contains only the about file path
187-
about_list = attributecode.util.get_about_file_path(
183+
about_list = get_about_file_path(
188184
inventory_location, use_mapping=use_mapping, mapping_file=mapping_file)
189185
# FIXME: why catching all exceptions?
190186
except Exception:
@@ -257,11 +253,15 @@ def generate_and_save(abouts, output_location, use_mapping=False, mapping_file=N
257253
return errors
258254

259255

256+
# FIXME: this function purpose needs to be explained.
260257
def as_about_paths(paths):
261258
"""
262259
Return a list of paths to .ABOUT files from a list of `paths`
263260
strings.
264261
"""
262+
from posixpath import basename
263+
from posixpath import dirname
264+
265265
about_paths = []
266266
for path in paths:
267267
if path.endswith('.ABOUT'):

src/attributecode/gen.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,5 +309,3 @@ def generate(location, base_dir, license_notice_text_location=None,
309309
errors.append(Error(ERROR, msg))
310310
unique_errors = unique(errors)
311311
return unique_errors, abouts
312-
313-

0 commit comments

Comments
 (0)