Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Implement option code for `--license_text_location`
  • Loading branch information
chinyeungli committed May 18, 2016
1 parent 1c123f4 commit 7bc7f9e
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 11 deletions.
15 changes: 14 additions & 1 deletion about_code_tool/cmd.py
Expand Up @@ -34,8 +34,10 @@
from about_code_tool import ERROR
from about_code_tool import INFO
from about_code_tool import NOTSET
from util import to_posix
from util import copy_files
from util import extract_zip
from util import to_posix
from util import verify_license_files


__version__ = '3.0.0dev'
Expand Down Expand Up @@ -182,6 +184,17 @@ def gen(mapping, license_text_location, extract_license, location, output):
click.echo('Generating ABOUT files...')
errors, abouts = about_code_tool.gen.generate(mapping, extract_license, location, output)

if license_text_location:
lic_loc_dict, lic_file_err = verify_license_files(abouts, license_text_location)
if lic_loc_dict:
copy_files(lic_loc_dict, output)
if lic_file_err:
update_errors = errors
errors = []
for err in update_errors:
errors.append(err)
for file_err in lic_file_err:
errors.append(file_err)

lea = len(abouts)
lee = 0
Expand Down
9 changes: 0 additions & 9 deletions about_code_tool/gen.py
Expand Up @@ -204,15 +204,6 @@ def generate(mapping, extract_license, location, base_dir, policy=None, conf_loc
if not e in errors:
errors.append(e)

# Check if there is any Critical Error which should halt the generation
for e in errors:
# Severity 50 = Critical Error
if e.severity == 50:
# Clear the errors and abouts object
errors = []
abouts = []
errors.append(e)
return errors, abouts
for about in abouts:
# TODO: check the paths overlap ...???
# For some reasons, the join does not work, using the '+' for now
Expand Down
33 changes: 32 additions & 1 deletion about_code_tool/util.py
Expand Up @@ -25,11 +25,13 @@
from os.path import dirname
from os.path import join
import posixpath
import shutil
import socket
import string
import sys

from about_code_tool import CRITICAL
from about_code_tool import ERROR
from about_code_tool import Error
import unicodecsv

Expand Down Expand Up @@ -391,4 +393,33 @@ def add_unc(location):
"""
if on_windows and not location.startswith(UNC_PREFIXES):
return UNC_PREFIX + os.path.abspath(location)
return location
return location


def verify_license_files(abouts, lic_location):
lic_loc_dict = {}
errors = []

for about in abouts:
if about.license_file.value:
for lic in about.license_file.value:
lic_path = posix_path(posixpath.join(lic_location, lic))
if posixpath.exists(lic_path):
copy_to = posixpath.dirname(about.about_file_path)
lic_loc_dict[copy_to] = lic_path
else:
msg = ('The file, ' + lic + ' in \'license_file\' field does not exist')
errors.append(Error(ERROR, msg))
return lic_loc_dict, errors


def copy_files(license_location_dict, gen_location):
"""
Copy the files into the gen_location
"""
for loc in license_location_dict:
location = loc
if loc.startswith('/'):
location = loc.strip('/')
copy_to = posixpath.join(posix_path(gen_location), location)
shutil.copy2(license_location_dict[loc], copy_to)

0 comments on commit 7bc7f9e

Please sign in to comment.