コード例 #1
0
def scan_infos(input_file, diag=False):
    """
    Scan one file or directory and return file_infos data.
    This always contains an extra 'errors' key with a list of error messages,
    possibly empty.
    """
    errors = []
    try:
        infos = get_file_infos(input_file, as_list=False)
    except Exception as e:
        # never fail but instead add an error message.
        infos = _empty_file_infos()
        errors = ['ERROR: infos: ' + e.message]
        if diag:
            errors.append('ERROR: infos: ' + traceback.format_exc())
    # put errors last
    infos['scan_errors'] = errors
    return infos
コード例 #2
0
ファイル: cli.py プロジェクト: ocabrisses/scancode-toolkit
def scan_infos(input_file, diag=False):
    """
    Scan one file or directory and return file_infos data. This always
    contains an extra 'errors' key with a list of error messages,
    possibly empty. If `diag` is True, additional diagnostic messages
    are included.
    """
    errors = []
    try:
        infos = get_file_infos(input_file)
    except Exception as e:
        # never fail but instead add an error message.
        infos = _empty_file_infos()
        errors = ['ERROR: infos: ' + e.message]
        if diag:
            errors.append('ERROR: infos: ' + traceback.format_exc())
    # put errors last
    infos['scan_errors'] = errors
    return infos
コード例 #3
0
 def test_get_file_infos_has_no_nulls(self):
     # note the test file is EMPTY on purpose to generate all False is_* flags
     test_dir = self.get_test_loc('api/info')
     info = api.get_file_infos(test_dir, as_list=False)
     is_key_values = [v for k, v in info.items() if k.startswith('is_')]
     assert all(v is not None for v in is_key_values)
コード例 #4
0
ファイル: test_api.py プロジェクト: yudhik11/scancode-toolkit
 def test_get_file_infos_include_base_name(self):
     test_dir = self.get_test_loc('api/info/test.txt')
     info = api.get_file_infos(test_dir)
     assert 'test' == info['base_name']
コード例 #5
0
 def test_get_file_infos_flag_are_not_null(self):
     # note the test file is EMPTY on purpose to generate all False is_* flags
     test_dir = self.get_test_loc('api/info')
     info = api.get_file_infos(test_dir)
     is_key_values = [v for k, v in info.items() if k.startswith('is_')]
     assert all(v is not None for v in is_key_values)