Skip to content

Commit 75b512f

Browse files
committed
Implemented the `--title` option. However, we, probably, want a more generic way to pass variables. Signed-off-by: Chin Yeung Li <[email protected]>
1 parent 125c9e2 commit 75b512f

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/attributecode/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
basestring = str # Python 3
2828

2929

30-
__version__ = '3.1.1'
30+
__version__ = '3.1.2'
3131

3232

3333
__about_spec_version__ = '3.0.0'

src/attributecode/attrib.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
from attributecode.util import add_unc
3838

3939

40-
def generate(abouts, template_string=None):
40+
def generate(abouts, template_string=None, title=None):
4141
"""
4242
Generate and return attribution text from a list of About objects and a
4343
template string.
@@ -110,7 +110,7 @@ def generate(abouts, template_string=None):
110110
license_file_name_and_key=license_file_name_and_key,
111111
license_key_to_license_name=license_key_to_license_name,
112112
license_name_to_license_key=license_name_to_license_key,
113-
utcnow=utcnow)
113+
utcnow=utcnow, title=title)
114114
except Exception as e:
115115
line = getattr(e, 'lineno', None)
116116
ln_msg = ' at line: %r' % line if line else ''
@@ -134,7 +134,7 @@ def check_template(template_string):
134134
default_template = join(os.path.dirname(os.path.realpath(__file__)),
135135
'templates', 'default_html.template')
136136

137-
def generate_from_file(abouts, template_loc=None):
137+
def generate_from_file(abouts, template_loc=None, title=None):
138138
"""
139139
Generate and return attribution string from a list of About objects and a
140140
template location.
@@ -144,11 +144,11 @@ def generate_from_file(abouts, template_loc=None):
144144
template_loc = add_unc(template_loc)
145145
with codecs.open(template_loc, 'rb', encoding='utf-8') as tplf:
146146
tpls = tplf.read()
147-
return generate(abouts, template_string=tpls)
147+
return generate(abouts, template_string=tpls, title=title)
148148

149149

150150
def generate_and_save(abouts, output_location, use_mapping=False, mapping_file=None,
151-
template_loc=None, inventory_location=None):
151+
template_loc=None, inventory_location=None, title=None):
152152
"""
153153
Generate attribution file using the `abouts` list of About object
154154
at `output_location`.
@@ -239,7 +239,7 @@ def generate_and_save(abouts, output_location, use_mapping=False, mapping_file=N
239239
else:
240240
about.license.value = lic_list
241241

242-
rendered = generate_from_file(updated_abouts, template_loc=template_loc)
242+
rendered = generate_from_file(updated_abouts, template_loc=template_loc, title=title)
243243

244244
if rendered:
245245
output_location = add_unc(output_location)

src/attributecode/cmd.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,11 @@ def gen(location, output, mapping, mapping_file, license_notice_text_location, f
290290
type=click.Path(exists=True, dir_okay=True, readable=True, resolve_path=True),
291291
help='Use a custom mapping file with mapping between input keys and ABOUT field names.')
292292

293+
@click.option('--template', type=click.Path(exists=True), nargs=1,
294+
help='Path to an optional custom attribution template used for generation.')
295+
296+
@click.option('--title', nargs=1, help='Title for the attribution output.')
297+
293298
@click.option('--verbose', is_flag=True, default=False,
294299
help='Show all errors and warnings. '
295300
'By default, the tool only prints these '
@@ -298,15 +303,12 @@ def gen(location, output, mapping, mapping_file, license_notice_text_location, f
298303
'for any level.'
299304
)
300305

301-
@click.option('--template', type=click.Path(exists=True), nargs=1,
302-
help='Path to an optional custom attribution template used for generation.')
303-
304306
@click.option('-q', '--quiet', is_flag=True,
305307
help='Do not print error or warning messages.')
306308

307309
@click.help_option('-h', '--help')
308310

309-
def attrib(location, output, template, mapping, mapping_file, inventory, quiet, verbose):
311+
def attrib(location, output, template, mapping, mapping_file, inventory, title, quiet, verbose):
310312
"""
311313
Generate an attribution document at OUTPUT using .ABOUT files at LOCATION.
312314
@@ -325,7 +327,7 @@ def attrib(location, output, template, mapping, mapping_file, inventory, quiet,
325327
no_match_errors = attrib_generate_and_save(
326328
abouts=abouts, output_location=output,
327329
use_mapping=mapping, mapping_file=mapping_file, template_loc=template,
328-
inventory_location=inventory)
330+
inventory_location=inventory, title=title)
329331

330332
if not no_match_errors:
331333
# Check for template error

0 commit comments

Comments
 (0)