2222import collections
2323import datetime
2424import os
25- from posixpath import basename
26- from posixpath import dirname
27- from posixpath import exists
28- from posixpath import join
2925
3026import jinja2
3127
32- import attributecode
3328from attributecode import ERROR
3429from attributecode import Error
3530from attributecode .licenses import COMMON_LICENSES
3631from attributecode .model import parse_license_expression
3732from 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
4041def 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.
260257def 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' ):
0 commit comments