Skip to content

Commit 93e4fef

Browse files
committed
Fixed #103
Add the --template_location to pass the user custom's template for attribution generation.
1 parent 44d7b44 commit 93e4fef

File tree

4 files changed

+40
-7
lines changed

4 files changed

+40
-7
lines changed

README.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ the .ABOUT files in the directory /tmp/thirdparty_about/.
177177
0 - Do not print any warning or error messages, just a total count (default)
178178
1 - Print error messages
179179
2 - Print error and warning messages
180+
181+
--template_location=TEMPLATE_LOCATION
182+
Use the custom template for the Attribution Generation
183+
184+
--mapping Configure the mapping key from the MAPPING.CONFIG
180185

181186
Example::
182187

USAGE

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -192,12 +192,12 @@ Syntax
192192
------
193193

194194
Usage: genattrib.py [options] input_path output_path component_list
195-
195+
196196
Input can be a file or directory.
197197
Output of rendered template must be a file (e.g. .html).
198198
Component List must be a .csv file which has at least an "about_resource" column.
199-
200-
199+
200+
201201
Options:
202202
-h, --help Display help
203203
-v, --version Display current version, license notice, and copyright notice
@@ -208,6 +208,11 @@ Syntax
208208
1 - Print error messages
209209
2 - Print error and warning messages
210210

211+
--template_location=TEMPLATE_LOCATION
212+
Use the custom template for the Attribution Generation
213+
214+
--mapping Configure the mapping key from the MAPPING.CONFIG
215+
211216
-------
212217
Purpose
213218
-------
@@ -225,4 +230,18 @@ Purpose
225230
'/home/attribution/attribution.html' is the user's output path
226231
'/home/project/component_list.csv' is the component list that user want to be generated
227232

228-
$ python genattrib.py /home/about_files/ /home/attribution/attribution.html /home/project/component_list.csv
233+
$ python genattrib.py /home/about_files/ /home/attribution/attribution.html /home/project/component_list.csv
234+
235+
-------
236+
Options
237+
-------
238+
239+
--template_loaction
240+
241+
This option allows user to use its own template for Attribution Generation.
242+
For instance, if the custom template the user want to use is located at:
243+
/home/custom_template/template.html
244+
245+
$ python genattrib.py --template_location=/home/custom_template/template.html input_path output_path component_list
246+
247+

about_code_tool/about.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ def write_to_csv(self, output_path):
10861086
row_data = about_object.get_row_data(relative_path)
10871087
csv_writer.writerow(row_data)
10881088

1089-
def generate_attribution(self, template_path='templates/default.html',
1089+
def generate_attribution(self, template_path=None,
10901090
limit_to=None):
10911091
"""
10921092
Generates an attribution file from the current list of ABOUT objects.
@@ -1096,6 +1096,9 @@ def generate_attribution(self, template_path='templates/default.html',
10961096
if not limit_to:
10971097
limit_to = []
10981098

1099+
if not template_path:
1100+
template_path = 'templates/default.html'
1101+
10991102
try:
11001103
from jinja2 import Environment, FileSystemLoader, TemplateNotFound
11011104
except ImportError:

about_code_tool/genattrib.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ def update_path_to_about(input_list):
8989
2 - Print error and warning messages
9090
"""
9191

92+
TEMPLATE_LOCATION_HELP = """\
93+
Use the custom template for the Attribution Generation
94+
"""
95+
9296
MAPPING_HELP = """\
9397
Configure the mapping key from the MAPPING.CONFIG
9498
"""
@@ -97,7 +101,8 @@ def main(parser, options, args):
97101
overwrite = options.overwrite
98102
verbosity = options.verbosity
99103
mapping_config = options.mapping
100-
104+
template_location = options.template_location
105+
101106
if options.version:
102107
print('ABOUT tool {0}\n{1}'.format(__version__, __copyright__))
103108
sys.exit(0)
@@ -169,7 +174,7 @@ def main(parser, options, args):
169174
sublist = component_subset_to_sublist(input_list)
170175
outlist = update_path_to_about(sublist)
171176

172-
attrib_str = collector.generate_attribution( limit_to = outlist )
177+
attrib_str = collector.generate_attribution(template_path=template_location, limit_to=outlist)
173178
with open(output_path, "w") as f:
174179
f.write(attrib_str)
175180
errors = collector.get_genattrib_errors()
@@ -233,6 +238,7 @@ def format_option(self, option):
233238
parser.add_option('--overwrite', action='store_true',
234239
help='Overwrites the output file if it exists')
235240
parser.add_option('--verbosity', type=int, help=VERBOSITY_HELP)
241+
parser.add_option('--template_location', type='string', help=TEMPLATE_LOCATION_HELP)
236242
parser.add_option('--mapping', action='store_true', help=MAPPING_HELP)
237243
return parser
238244

0 commit comments

Comments
 (0)