From 9cd6c5c896f28f8050e313933c4ec590036dc556 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Mon, 22 Jun 2015 11:27:58 -0700 Subject: [PATCH 01/20] Update the README file to be the same as the one in Master. --- README.rst | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/README.rst b/README.rst index 7941fa53..f94bdba2 100644 --- a/README.rst +++ b/README.rst @@ -1,11 +1,11 @@ AboutCode tool ============== -.. image:: https://api.travis-ci.org/dejacode/about-code-tool.png?branch=develop - :target: https://travis-ci.org/dejacode/about-code-tool +.. image:: https://travis-ci.org/dejacode/about-code-tool.svg?branch=master + :target: https://travis-ci.org/dejacode/about-code-tool -.. image:: https://coveralls.io/repos/dejacode/about-code-tool/badge.png?branch=develop - :target: https://coveralls.io/r/dejacode/about-code-tool?branch=develop +.. image:: https://coveralls.io/repos/dejacode/about-code-tool/badge.svg?branch=master + :target: https://coveralls.io/r/dejacode/about-code-tool?branch=master The AboutCode tool and ABOUT files provide a simple way to document the @@ -50,7 +50,7 @@ Python 2.7.x here https://www.python.org/downloads/ : * Download the .msi installer for Windows or the .dmg archive for Mac. * Open and run the installer using all the default options. -* On Windows, make sure you install Python in the default c:\Python27 and not +* On Windows, make sure you install Python in the default c:\\Python27 and not on another drive. @@ -71,28 +71,28 @@ And on Windows:: For instance on Linux the whole installation would be like this:: - $ wget https://github.com/dejacode/about-code-tool/archive/v2.0.0.zip - $ unzip v2.0.0.zip - $ cd about-code-tool-2.0.0/ + $ wget https://github.com/dejacode/about-code-tool/archive/v2.0.1.zip + $ unzip v2.0.1.zip + $ cd about-code-tool-2.0.1/ $ source configure On Windows, the whole installation would be like this: - * Download and extract https://github.com/dejacode/about-code-tool/archive/v2.0.0.zip + * Download and extract https://github.com/dejacode/about-code-tool/archive/v2.0.1.zip * open a command prompt and cd to the directory where the zip extraction directory * run configure - Later on, if opening a new shell or command prompt on an already installed AboutCode you need to **activate** this installation. On Linux or Mac, run this:: + source bin/activate On Windows, run this:: - bin\activate + bin\\activate Usage @@ -203,8 +203,6 @@ In this example, the tool will use the list in the "thirdparty_code.csv" file and generate .ABOUT files in a directory tmp/thirdparty_about/ - - **Using the genattrib.py script** The genattrib.py script is used to generate a credit and license attribution @@ -271,10 +269,12 @@ branching model. **Tests** You can run the test suite with:: + python setup.py test **Contributing** + We accept bugs, patches and pull requests for code and documentation provided under the same license (Apache-2.0) as this tool. When contributing, you are agreeing to the http://developercertificate.org/ From 24d8c4dd946c268f0b952d9839af07b758591303 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Mon, 22 Jun 2015 11:30:44 -0700 Subject: [PATCH 02/20] Update gitignore file. --- .gitignore | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 8b18ace5..65091725 100644 --- a/.gitignore +++ b/.gitignore @@ -30,5 +30,6 @@ nosetests.xml # PyCharm project .idea/ - -/*.egg_info +/aboutcode.egg_info +AboutCode.egg-info +/dist From 4954cd4890d5e08f4b4a7a1be2eeb7e3a0bd0d14 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Mon, 22 Jun 2015 15:27:35 -0700 Subject: [PATCH 03/20] Update gitignore file --- .gitignore | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 65091725..8b5efe4f 100644 --- a/.gitignore +++ b/.gitignore @@ -30,6 +30,5 @@ nosetests.xml # PyCharm project .idea/ -/aboutcode.egg_info -AboutCode.egg-info -/dist + +/*.egg-info/ From 9cedb6def6a05c0834e0846f61515c8deebf0f59 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Wed, 24 Jun 2015 16:24:38 -0700 Subject: [PATCH 04/20] Add test cases file for long path testing --- .../longpath1/longpath1/non-supported_date_format.ABOUT | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 about_code_tool/tests/testdata/longpath/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/non-supported_date_format.ABOUT diff --git a/about_code_tool/tests/testdata/longpath/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/non-supported_date_format.ABOUT b/about_code_tool/tests/testdata/longpath/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/non-supported_date_format.ABOUT new file mode 100644 index 00000000..11211ca2 --- /dev/null +++ b/about_code_tool/tests/testdata/longpath/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/non-supported_date_format.ABOUT @@ -0,0 +1,4 @@ +name: distribute +version: 1.1 +about_resource: distribute_setup.py +date:01/08/2013 \ No newline at end of file From e0bcbf4c6c0a7b39de1c5e2103c592e69b6e5d16 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Wed, 24 Jun 2015 16:33:09 -0700 Subject: [PATCH 05/20] Update version to 2.0.2 Add try/catch to handle when ABOUT files don't have dje_license_name. Add code to handle long path specifically in windows (read and write) See See https://msdn.microsoft.com/en-us/library/aa365247.aspx Add code to strip the UNC_Prefix for path location the in the error log. Create test for long path handling. Add code to strip the quote from the api input. --- about_code_tool/about.py | 45 ++++++++++++++++++++++++++--- about_code_tool/genabout.py | 8 ++++- about_code_tool/genattrib.py | 2 +- about_code_tool/tests/test_about.py | 32 +++++++++++++++++--- 4 files changed, 77 insertions(+), 10 deletions(-) diff --git a/about_code_tool/about.py b/about_code_tool/about.py index dbafc1b3..47b894e4 100644 --- a/about_code_tool/about.py +++ b/about_code_tool/about.py @@ -32,21 +32,24 @@ import csv from datetime import datetime from email.parser import HeaderParser -from os.path import basename, dirname, join, normpath, realpath import errno import httplib import logging +import ntpath import optparse import os +from os.path import basename, dirname, join, normpath, realpath import posixpath import socket import string import sys import urlparse -import ntpath -__version__ = '2.0.1' +on_windows = 'win32' in sys.platform +UNC_PREFIX = u'\\\\?\\' + +__version__ = '2.0.2' # See http://dejacode.org __about_spec_version__ = '1.0' @@ -1082,7 +1085,10 @@ def get_dje_license_name(self): """ Return the about object's dje_license_name. """ - return self.parsed.get('dje_license_name', '') + try: + return self.parsed.get('dje_license_name', '') + except: + return '' def check_invalid_chars(field_name, line): """ @@ -1104,6 +1110,8 @@ def check_invalid_chars(field_name, line): warnings = Warn(IGNORED, field_name, line, msg) return invalid_chars, warnings +def posix_unc_prefix(): + return posix_path(u'\\\\?\\') class Collector(object): """ @@ -1144,6 +1152,23 @@ def collect(location): """ # FIXME: we should not accept both a file and dir location as input paths = [] + + if on_windows: + location = unicode(location) + """ + Convert a location to an absolute Window UNC path to support long paths + on Windows. Return the location unchanged if not on Windows. + See https://msdn.microsoft.com/en-us/library/aa365247.aspx + """ + if on_windows and not location.startswith(UNC_PREFIX): + location = UNC_PREFIX + os.path.abspath(location) + location = os.path.expanduser(location) + location = os.path.expandvars(location) + location = os.path.normpath(location) + location = os.path.abspath(location) + + assert os.path.exists(location) + if location: if os.path.isfile(location) and is_about_file(location): paths.append(location) @@ -1241,6 +1266,9 @@ def get_about_context(self, about_object): if '\n' in about_object.get_dje_license_name(): msg = ('Multiple licenses is not supported. ' 'Skipping License generation.') + if on_windows: + if about_object.location.startswith(posix_unc_prefix()): + about_object.location = about_object.location.strip(posix_unc_prefix()) err = Error(GENATTRIB, 'dje_license', about_object.location, msg) self.genattrib_errors.append(err) @@ -1258,6 +1286,9 @@ def get_about_context(self, about_object): and not '\n' in about_object.get_dje_license_name(): msg = ('No license_text found. ' 'Skipping License generation.') + if on_windows: + if about_object.location.startswith(posix_unc_prefix()): + about_object.location = about_object.location.strip(posix_unc_prefix()) err = Error(GENATTRIB, 'license_text_file', about_object.location, msg) self.genattrib_errors.append(err) @@ -1314,6 +1345,9 @@ def generate_attribution(self, template_path=None, limit_to=None, verification=N break if not component_exist: + if on_windows: + if self.location.startswith(posix_unc_prefix()): + self.location = self.location.strip(posix_unc_prefix()) loc = self.location + component msg = ('The requested ABOUT file: %r does not exist. ' 'No attribution generated for this file.' % loc) @@ -1364,6 +1398,9 @@ def check_paths(self, paths): for path in paths: path = posix_path(path) afp = join(self.location, path) + if on_windows: + if afp.startswith(posix_unc_prefix()): + afp = afp.strip(posix_unc_prefix()) msg = ('The requested ABOUT file: %(afp)r does not exist. ' 'No attribution generated for this file.' % locals()) err = Error(GENATTRIB, 'about_file', path, msg) diff --git a/about_code_tool/genabout.py b/about_code_tool/genabout.py index 404f8c10..aea7cc3c 100644 --- a/about_code_tool/genabout.py +++ b/about_code_tool/genabout.py @@ -41,7 +41,7 @@ import about -__version__ = '2.0.0' +__version__ = '2.0.2' __copyright__ = """ Copyright (c) 2013-2014 nexB Inc. All rights reserved. @@ -614,6 +614,8 @@ def format_output(input_list): @staticmethod def write_output(output): for about_file_location, context in output: + if about.on_windows: + about_file_location = about.UNC_PREFIX + os.path.abspath(about_file_location) if _exists(about_file_location): os.remove(about_file_location) with open(about_file_location, 'wb') as output_file: @@ -855,6 +857,10 @@ def main(parser, options, args): sys.exit(errno.EINVAL) if gen_license: + # Strip the ' and " for api_url, api_username and api_key from input + api_url = api_url.strip("'").strip("\"") + api_username = api_username.strip("'").strip("\"") + api_key = api_key.strip("'").strip("\"") dje_license_dict = gen.pre_process_and_dje_license_dict(input_list, api_url, api_username, diff --git a/about_code_tool/genattrib.py b/about_code_tool/genattrib.py index 30544d19..d3c81288 100644 --- a/about_code_tool/genattrib.py +++ b/about_code_tool/genattrib.py @@ -43,7 +43,7 @@ logger.addHandler(handler) file_logger = logging.getLogger(__name__ + '_file') -__version__ = '2.0.0' +__version__ = '2.0.2' __about_spec_version__ = '1.0.0' # See http://dejacode.org diff --git a/about_code_tool/tests/test_about.py b/about_code_tool/tests/test_about.py index b6cce448..94e7310f 100644 --- a/about_code_tool/tests/test_about.py +++ b/about_code_tool/tests/test_about.py @@ -27,9 +27,12 @@ from os.path import abspath, dirname, join, split from about_code_tool import about +from pip._vendor.distlib.wheel import to_posix +from about_code_tool.about import on_windows TESTDATA_DIR = join(abspath(dirname(__file__)), 'testdata') +UNC_PREFIX = u'\\\\?\\' def create_dir(location): @@ -134,11 +137,16 @@ def test_header_row_in_csv_output(self): def test_collect_can_collect_a_directory_tree(self): test_dir = 'about_code_tool/tests/testdata/DateTest' - expected = [('about_code_tool/tests/testdata/DateTest' - '/non-supported_date_format.ABOUT'), - ('about_code_tool/tests/testdata/DateTest' - '/supported_date_format.ABOUT')] + expected = [(os.path.abspath('about_code_tool/tests/testdata/DateTest' + '/non-supported_date_format.ABOUT')), + (os.path.abspath('about_code_tool/tests/testdata/DateTest' + '/supported_date_format.ABOUT'))] result = about.Collector.collect(test_dir) + if on_windows: + expected = [(to_posix(UNC_PREFIX + os.path.abspath('about_code_tool/tests/testdata/DateTest' + '/non-supported_date_format.ABOUT'))), + (to_posix(UNC_PREFIX + os.path.abspath('about_code_tool/tests/testdata/DateTest' + '/supported_date_format.ABOUT')))] self.assertEqual(sorted(expected), sorted(result)) def test_collect_can_collect_a_single_file(self): @@ -147,8 +155,24 @@ def test_collect_can_collect_a_single_file(self): expected = ['about_code_tool/tests/testdata/thirdparty' '/django_snippets_2413.ABOUT'] result = about.Collector.collect(test_file) + if on_windows: + expected = [to_posix(UNC_PREFIX + os.path.abspath('about_code_tool/tests/testdata/thirdparty' + '/django_snippets_2413.ABOUT'))] self.assertEqual(expected, result) + def test_collect_can_collect_a_long_directory_tree(self): + test_dir = 'about_code_tool/tests/testdata/longpath/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/' + expected = [('about_code_tool/tests/testdata/longpath/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1' + '/non-supported_date_format.ABOUT')] + result = about.Collector.collect(test_dir) + if on_windows: + # For some reasons, the os.path.abspath doesn't work if I have long + # path in the parameter. Therefore, I just append to long path + # after the os.path.abspath() + expected = [to_posix(UNC_PREFIX + os.path.abspath('about_code_tool') + '/tests/testdata/longpath/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1' + '/non-supported_date_format.ABOUT')] + self.assertEqual(sorted(expected), sorted(result)) + def test_collector_errors_encapsulation(self): test_file = 'about_code_tool/tests/testdata/DateTest' collector = about.Collector(test_file) From c7df1dafd38dc8eb6d91f96d1b00dbb0d13cf3e1 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Wed, 24 Jun 2015 20:21:14 -0700 Subject: [PATCH 06/20] Not support Python26 --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 61f978c0..d5196b43 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: python python: - - "2.6" - "2.7" install: - source configure etc/conf From a0b6e48b8330996d1c451aa04c602bd0445b34cb Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Wed, 24 Jun 2015 20:27:37 -0700 Subject: [PATCH 07/20] Fix tests --- about_code_tool/tests/test_about.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/about_code_tool/tests/test_about.py b/about_code_tool/tests/test_about.py index 94e7310f..44fbae0f 100644 --- a/about_code_tool/tests/test_about.py +++ b/about_code_tool/tests/test_about.py @@ -152,8 +152,8 @@ def test_collect_can_collect_a_directory_tree(self): def test_collect_can_collect_a_single_file(self): test_file = ('about_code_tool/tests/testdata/thirdparty' '/django_snippets_2413.ABOUT') - expected = ['about_code_tool/tests/testdata/thirdparty' - '/django_snippets_2413.ABOUT'] + expected = [os.path.abspath('about_code_tool/tests/testdata/thirdparty' + '/django_snippets_2413.ABOUT')] result = about.Collector.collect(test_file) if on_windows: expected = [to_posix(UNC_PREFIX + os.path.abspath('about_code_tool/tests/testdata/thirdparty' @@ -162,8 +162,8 @@ def test_collect_can_collect_a_single_file(self): def test_collect_can_collect_a_long_directory_tree(self): test_dir = 'about_code_tool/tests/testdata/longpath/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/' - expected = [('about_code_tool/tests/testdata/longpath/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1' - '/non-supported_date_format.ABOUT')] + expected = [os.path.abspath(('about_code_tool/tests/testdata/longpath/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1/longpath1' + '/non-supported_date_format.ABOUT'))] result = about.Collector.collect(test_dir) if on_windows: # For some reasons, the os.path.abspath doesn't work if I have long From 39025a5df28f360e1fdc4d0cd2341104ccef4f18 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Thu, 25 Jun 2015 10:40:40 -0700 Subject: [PATCH 08/20] Update copyright date. --- about_code_tool/about.py | 4 ++-- about_code_tool/genabout.py | 4 ++-- about_code_tool/genattrib.py | 4 ++-- about_code_tool/tests/test_about.py | 2 +- about_code_tool/tests/test_genabout.py | 2 +- about_code_tool/tests/test_genattrib.py | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/about_code_tool/about.py b/about_code_tool/about.py index 47b894e4..cdd9f3c2 100644 --- a/about_code_tool/about.py +++ b/about_code_tool/about.py @@ -2,7 +2,7 @@ # -*- coding: utf8 -*- # ============================================================================ -# Copyright (c) 2014 nexB Inc. http://www.nexb.com/ - All rights reserved. +# Copyright (c) 2013-2015 nexB Inc. http://www.nexb.com/ - All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -56,7 +56,7 @@ __copyright__ = """ -Copyright (c) 2013-2014 nexB Inc. All rights reserved. +Copyright (c) 2013-2015 nexB Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/about_code_tool/genabout.py b/about_code_tool/genabout.py index aea7cc3c..d6bb0abd 100644 --- a/about_code_tool/genabout.py +++ b/about_code_tool/genabout.py @@ -2,7 +2,7 @@ # -*- coding: utf8 -*- # ============================================================================ -# Copyright (c) 2014 nexB Inc. http://www.nexb.com/ - All rights reserved. +# Copyright (c) 2013-2015 nexB Inc. http://www.nexb.com/ - All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -44,7 +44,7 @@ __version__ = '2.0.2' __copyright__ = """ -Copyright (c) 2013-2014 nexB Inc. All rights reserved. +Copyright (c) 2013-2015 nexB Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/about_code_tool/genattrib.py b/about_code_tool/genattrib.py index d3c81288..3c95fe24 100644 --- a/about_code_tool/genattrib.py +++ b/about_code_tool/genattrib.py @@ -2,7 +2,7 @@ # -*- coding: utf8 -*- # ============================================================================ -# Copyright (c) 2014 nexB Inc. http://www.nexb.com/ - All rights reserved. +# Copyright (c) 2013-2015 nexB Inc. http://www.nexb.com/ - All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at @@ -48,7 +48,7 @@ __about_spec_version__ = '1.0.0' # See http://dejacode.org __copyright__ = """ -Copyright (c) 2013-2014 nexB Inc. All rights reserved. +Copyright (c) 2013-2015 nexB Inc. All rights reserved. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. diff --git a/about_code_tool/tests/test_about.py b/about_code_tool/tests/test_about.py index 44fbae0f..0605e1f1 100644 --- a/about_code_tool/tests/test_about.py +++ b/about_code_tool/tests/test_about.py @@ -2,7 +2,7 @@ # -*- coding: utf8 -*- # ============================================================================ -# Copyright (c) 2014 nexB Inc. http://www.nexb.com/ - All rights reserved. +# Copyright (c) 2013-2015 nexB Inc. http://www.nexb.com/ - All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/about_code_tool/tests/test_genabout.py b/about_code_tool/tests/test_genabout.py index 03db877c..98facd65 100644 --- a/about_code_tool/tests/test_genabout.py +++ b/about_code_tool/tests/test_genabout.py @@ -2,7 +2,7 @@ # -*- coding: utf8 -*- # ============================================================================ -# Copyright (c) 2014 nexB Inc. http://www.nexb.com/ - All rights reserved. +# Copyright (c) 2013-2015 nexB Inc. http://www.nexb.com/ - All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at diff --git a/about_code_tool/tests/test_genattrib.py b/about_code_tool/tests/test_genattrib.py index 575e1101..701c2726 100644 --- a/about_code_tool/tests/test_genattrib.py +++ b/about_code_tool/tests/test_genattrib.py @@ -2,7 +2,7 @@ # -*- coding: utf8 -*- # ============================================================================ -# Copyright (c) 2014 nexB Inc. http://www.nexb.com/ - All rights reserved. +# Copyright (c) 2013-2015 nexB Inc. http://www.nexb.com/ - All rights reserved. # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at From 4cfa771df1efe72e1105fc49c070bd269d85d151 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Thu, 25 Jun 2015 11:53:18 -0700 Subject: [PATCH 09/20] The os.path.abspath(location) is needed when inserting the UNC_PREFIX for long path in windows. In addition, adding code to make sure both the input and filter are in posix path format before doing any string partition. --- about_code_tool/about.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/about_code_tool/about.py b/about_code_tool/about.py index cdd9f3c2..50f492da 100644 --- a/about_code_tool/about.py +++ b/about_code_tool/about.py @@ -557,7 +557,7 @@ class AboutFile(object): """ def __init__(self, location=None): self.about_resource = None - self.location = location + self.location = os.path.abspath(location) self.parsed = None self.parsed_fields = None @@ -1222,6 +1222,10 @@ def get_relative_path(self, location): """ user_loc = normpath(self.location) if os.path.isdir(self.normalized_location): + # Making sure both are in posix path format before + # doing any string partition. + location = posix_path(location) + user_loc = posix_path(user_loc) parent_name = basename(user_loc) subpath = '/' + parent_name + location.partition(user_loc)[2] if user_loc[-1] == '/': From 560805591ffab31427f5fe8e18a7270da9111d29 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Thu, 25 Jun 2015 12:06:09 -0700 Subject: [PATCH 10/20] Strip trailing whitespace to avoid creating invalid file such as "about.c .ABOUT" Test code added. --- about_code_tool/genabout.py | 2 +- about_code_tool/tests/test_genabout.py | 10 ++++++++++ .../about_with_trailling_spaces.csv | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 about_code_tool/tests/testdata/test_files_for_genabout/about_with_trailling_spaces.csv diff --git a/about_code_tool/genabout.py b/about_code_tool/genabout.py index d6bb0abd..cc3ac6b7 100644 --- a/about_code_tool/genabout.py +++ b/about_code_tool/genabout.py @@ -135,7 +135,7 @@ def get_input_list(input_file): for row in csvfile: row_dict = {} for key in row: - row_dict[key.lower()] = row[key] + row_dict[key.lower()] = row[key].rstrip() input_list.append(row_dict) return input_list diff --git a/about_code_tool/tests/test_genabout.py b/about_code_tool/tests/test_genabout.py index 98facd65..87abae55 100644 --- a/about_code_tool/tests/test_genabout.py +++ b/about_code_tool/tests/test_genabout.py @@ -41,6 +41,16 @@ def test_get_input_list(self): result = gen.get_input_list(test_file) self.assertEqual(expected, result) + def test_get_input_with_trailing_spaces(self): + gen = genabout.GenAbout() + test_file = join(TESTDATA_DIR, 'test_files_for_genabout/about_with_trailling_spaces.csv') + expected = [{'about_file': 'about.c', + 'about_resource': '.', + 'name': 'ABOUT tool', + 'version': '0.8.1'}] + result = gen.get_input_list(test_file) + self.assertEqual(expected, result) + def test_get_input_list_covert_all_keys_to_lower(self): gen = genabout.GenAbout() test_input = join(TESTDATA_DIR, 'test_files_for_genabout' diff --git a/about_code_tool/tests/testdata/test_files_for_genabout/about_with_trailling_spaces.csv b/about_code_tool/tests/testdata/test_files_for_genabout/about_with_trailling_spaces.csv new file mode 100644 index 00000000..d1672728 --- /dev/null +++ b/about_code_tool/tests/testdata/test_files_for_genabout/about_with_trailling_spaces.csv @@ -0,0 +1,2 @@ +about_file,about_resource,name,version +about.c ,.,ABOUT tool,0.8.1 From f8d3529e9dd9295a5f3571561adbd3d6f2379a60 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Thu, 25 Jun 2015 13:22:01 -0700 Subject: [PATCH 11/20] #195 force the code to use the generated dje_license_key instead of the user entered license_key --- about_code_tool/genabout.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/about_code_tool/genabout.py b/about_code_tool/genabout.py index cc3ac6b7..815e1cdc 100644 --- a/about_code_tool/genabout.py +++ b/about_code_tool/genabout.py @@ -455,11 +455,12 @@ def pre_process_and_dje_license_dict(self, input_list, api_url, api_username, ap if not lic in license_dict: detail_list = [] detail = self.get_license_details_from_api(api_url, api_username, api_key, lic) - license_dict[lic] = detail[0] - line['dje_license_name'] = detail[0] dje_key = detail[1] + line['dje_license_key'] = dje_key + license_dict[dje_key] = detail[0] + line['dje_license_name'] = detail[0] license_context = detail [2] - line['dje_license_url'] = dje_lic_urn + lic + line['dje_license_url'] = dje_lic_urn + dje_key detail_list.append(dje_key) detail_list.append(license_context) key_text_dict[detail[0]] = detail_list From d6880795e0838400a3f8f67ec8e904ed19e732dc Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Thu, 25 Jun 2015 15:11:14 -0700 Subject: [PATCH 12/20] Fix the test as the os.path.abspath(None) will cause error in linux system. See https://bugs.python.org/issue22587 --- about_code_tool/about.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/about_code_tool/about.py b/about_code_tool/about.py index 50f492da..7aa652e6 100644 --- a/about_code_tool/about.py +++ b/about_code_tool/about.py @@ -557,7 +557,14 @@ class AboutFile(object): """ def __init__(self, location=None): self.about_resource = None - self.location = os.path.abspath(location) + # The os.path.abspath(None) will cause error in linux system. + # See https://bugs.python.org/issue22587 + # Note that the os.path.abspath is needed for windows when there + # is long path/filename. + if on_windows: + self.location = os.path.abspath(location) + else: + self.location = location self.parsed = None self.parsed_fields = None From 5182b56038e5294e43a6eee336cca7e45760f86a Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Thu, 25 Jun 2015 15:35:48 -0700 Subject: [PATCH 13/20] Remove the UNC_PREFIX in the path for windows system in the error.log --- about_code_tool/about.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/about_code_tool/about.py b/about_code_tool/about.py index 7aa652e6..2a2bf064 100644 --- a/about_code_tool/about.py +++ b/about_code_tool/about.py @@ -1278,8 +1278,9 @@ def get_about_context(self, about_object): msg = ('Multiple licenses is not supported. ' 'Skipping License generation.') if on_windows: - if about_object.location.startswith(posix_unc_prefix()): - about_object.location = about_object.location.strip(posix_unc_prefix()) + if (about_object.location.startswith(posix_unc_prefix()) + or about_object.location.startswith(UNC_PREFIX)): + about_object.location = about_object.location.strip(posix_unc_prefix()).strip(UNC_PREFIX) err = Error(GENATTRIB, 'dje_license', about_object.location, msg) self.genattrib_errors.append(err) @@ -1298,8 +1299,9 @@ def get_about_context(self, about_object): msg = ('No license_text found. ' 'Skipping License generation.') if on_windows: - if about_object.location.startswith(posix_unc_prefix()): - about_object.location = about_object.location.strip(posix_unc_prefix()) + if (about_object.location.startswith(posix_unc_prefix()) + or about_object.location.startswith(UNC_PREFIX)): + about_object.location = about_object.location.strip(posix_unc_prefix()).strip(UNC_PREFIX) err = Error(GENATTRIB, 'license_text_file', about_object.location, msg) self.genattrib_errors.append(err) From 5a5b639e977ba92e75ec24ac296e376e6c3c92c1 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Mon, 29 Jun 2015 09:52:29 -0700 Subject: [PATCH 14/20] #198 Add code to check if the about_file path is valid or invalid. If the path is invalid, the tool will log the error and skip this generation and keep continue with the rest. --- about_code_tool/genabout.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/about_code_tool/genabout.py b/about_code_tool/genabout.py index 815e1cdc..ab0c7d0f 100644 --- a/about_code_tool/genabout.py +++ b/about_code_tool/genabout.py @@ -516,7 +516,14 @@ def pre_generation(self, gen_location, input_list, action_num): about_file_location = join(gen_location, file_location) about_file_dir = dirname(about_file_location) if not os.path.exists(about_file_dir): - makedirs(about_file_dir) + # Check for invalid file path + try: + makedirs(about_file_dir) + except: + msg = 'Invalid ABOUT file path.' + self.errors.append(Error(VALUE, 'about_file_path', + about_file_dir, msg)) + continue about_file_exist = _exists(about_file_location) if about_file_exist: if action_num == ACTION_DO_NOTHING_IF_ABOUT_FILE_EXIST: From f7f24deb9b97decc9ad518e8f0bfe0f9565716b0 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Tue, 30 Jun 2015 10:29:44 -0700 Subject: [PATCH 15/20] Unify the value in the dictionary list to work with unicode. --- about_code_tool/genabout.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/about_code_tool/genabout.py b/about_code_tool/genabout.py index ab0c7d0f..917ee619 100644 --- a/about_code_tool/genabout.py +++ b/about_code_tool/genabout.py @@ -597,19 +597,22 @@ def format_output(input_list): """ components_list = [] for about_file_location, about_dict_list in input_list: + unified_dict_list = {} + for key in about_dict_list: + unified_dict_list[key] = u''.join(about_dict_list[key]) component = [] - component_name = about_dict_list.get('name', '') - component_version = about_dict_list.get('version', '') + component_name = unified_dict_list.get('name', '') + component_version = unified_dict_list.get('version', '') context = 'about_resource: %s\nname: %s\nversion: %s\n\n' % ( - about_dict_list['about_resource'], component_name, component_version) + unified_dict_list['about_resource'], component_name, component_version) - for item in sorted(about_dict_list.iterkeys()): + for item in sorted(unified_dict_list.iterkeys()): if item == 'about_file': continue if not item in about.MANDATORY_FIELDS: # The purpose of the replace('\n', '\n ') is used to # format the continuation strings - value = about_dict_list[item].replace('\n', '\n ') + value = unified_dict_list[item].replace('\n', '\n ') if (value or item in about.MANDATORY_FIELDS) and not item\ in about.ERROR_WARN_FIELDS and not item == 'about_resource': context += item + ': ' + value + '\n' From e981f3da391768383a424cc687f3378a546527fd Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Tue, 30 Jun 2015 16:13:35 -0700 Subject: [PATCH 16/20] the unified_dict_list is not working. restore the code base. --- about_code_tool/genabout.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/about_code_tool/genabout.py b/about_code_tool/genabout.py index 917ee619..d4800f81 100644 --- a/about_code_tool/genabout.py +++ b/about_code_tool/genabout.py @@ -13,7 +13,6 @@ # See the License for the specific language governing permissions and # limitations under the License. # ============================================================================ - """ This is a tool to generate ABOUT files based on the input file. The input file should be a csv format which contains information about the @@ -22,25 +21,25 @@ from __future__ import print_function +from collections import namedtuple import copy import csv import errno import json import logging import optparse +from os import makedirs import os +from os.path import exists, dirname, join, abspath, isdir, normpath, basename, expanduser import shutil import sys import urllib import urllib2 - -from collections import namedtuple from urlparse import urljoin, urlparse -from os import makedirs -from os.path import exists, dirname, join, abspath, isdir, normpath, basename, expanduser import about + __version__ = '2.0.2' __copyright__ = """ @@ -597,22 +596,19 @@ def format_output(input_list): """ components_list = [] for about_file_location, about_dict_list in input_list: - unified_dict_list = {} - for key in about_dict_list: - unified_dict_list[key] = u''.join(about_dict_list[key]) component = [] - component_name = unified_dict_list.get('name', '') - component_version = unified_dict_list.get('version', '') + component_name = about_dict_list.get('name', '') + component_version = about_dict_list.get('version', '') context = 'about_resource: %s\nname: %s\nversion: %s\n\n' % ( - unified_dict_list['about_resource'], component_name, component_version) + about_dict_list['about_resource'], component_name, component_version) - for item in sorted(unified_dict_list.iterkeys()): + for item in sorted(about_dict_list.iterkeys()): if item == 'about_file': continue if not item in about.MANDATORY_FIELDS: # The purpose of the replace('\n', '\n ') is used to # format the continuation strings - value = unified_dict_list[item].replace('\n', '\n ') + value = about_dict_list[item].replace('\n', '\n ') if (value or item in about.MANDATORY_FIELDS) and not item\ in about.ERROR_WARN_FIELDS and not item == 'about_resource': context += item + ': ' + value + '\n' From 6ff8debd9457a023833b2112d12af50667bb704f Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Mon, 6 Jul 2015 11:09:43 -0700 Subject: [PATCH 17/20] Add code to handle encoding issue. --- about_code_tool/genabout.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/about_code_tool/genabout.py b/about_code_tool/genabout.py index d4800f81..d9c38c90 100644 --- a/about_code_tool/genabout.py +++ b/about_code_tool/genabout.py @@ -611,6 +611,11 @@ def format_output(input_list): value = about_dict_list[item].replace('\n', '\n ') if (value or item in about.MANDATORY_FIELDS) and not item\ in about.ERROR_WARN_FIELDS and not item == 'about_resource': + # It will cause error if value has different coding + try: + value = unicode(value, errors='ignore') + except: + pass context += item + ': ' + value + '\n' component.append(about_file_location) From 55bb8786e31a94496aa271934060702236da0695 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Mon, 6 Jul 2015 11:29:17 -0700 Subject: [PATCH 18/20] Update README instruction reference from 2.0.1 to 2.0.2 --- README.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index f94bdba2..8ff8f8cc 100644 --- a/README.rst +++ b/README.rst @@ -71,14 +71,14 @@ And on Windows:: For instance on Linux the whole installation would be like this:: - $ wget https://github.com/dejacode/about-code-tool/archive/v2.0.1.zip - $ unzip v2.0.1.zip - $ cd about-code-tool-2.0.1/ + $ wget https://github.com/dejacode/about-code-tool/archive/v2.0.2.zip + $ unzip v2.0.2.zip + $ cd about-code-tool-2.0.2/ $ source configure On Windows, the whole installation would be like this: - * Download and extract https://github.com/dejacode/about-code-tool/archive/v2.0.1.zip + * Download and extract https://github.com/dejacode/about-code-tool/archive/v2.0.2.zip * open a command prompt and cd to the directory where the zip extraction directory * run configure From 0370c66be21183dced60cf9892eccba749b3e5fb Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Mon, 6 Jul 2015 12:15:52 -0700 Subject: [PATCH 19/20] Update changelog. --- docs/CHANGELOG.rst | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/CHANGELOG.rst b/docs/CHANGELOG.rst index 5a8ed1ef..44cd1992 100644 --- a/docs/CHANGELOG.rst +++ b/docs/CHANGELOG.rst @@ -1,3 +1,19 @@ +2015-07-xx Chin-Yeung Li + + Release 2.0.2 + + * Handle input's encoding issues + * Better error handling + * Writing to and reading from Windows OS with paths > 255 chars + + +2015-06-08 Chin-Yeung Li + + Release 2.0.1 + + * Fixes the configure scripts and updates basic documentation. + + 2015-03-06 Chin-Yeung Li Release 2.0.0 From b32413575da8352a0f314bcd67700b371b556470 Mon Sep 17 00:00:00 2001 From: Chin Yeung Li Date: Mon, 6 Jul 2015 14:55:46 -0700 Subject: [PATCH 20/20] Update CHANGELOG date. --- docs/CHANGELOG.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/CHANGELOG.rst b/docs/CHANGELOG.rst index 44cd1992..8999392e 100644 --- a/docs/CHANGELOG.rst +++ b/docs/CHANGELOG.rst @@ -1,4 +1,4 @@ -2015-07-xx Chin-Yeung Li +2015-07-06 Chin-Yeung Li Release 2.0.2