|
49 | 49 | from attributecode import Error |
50 | 50 | from attributecode import saneyaml |
51 | 51 | from attributecode import util |
| 52 | +from attributecode.transform import write_excel |
52 | 53 | from attributecode.util import add_unc |
53 | 54 | from attributecode.util import boolean_fields |
54 | 55 | from attributecode.util import copy_license_notice_files |
@@ -986,7 +987,7 @@ def load(self, location): |
986 | 987 | errors = [] |
987 | 988 | try: |
988 | 989 | loc = add_unc(loc) |
989 | | - with io.open(loc, encoding='utf-8') as txt: |
| 990 | + with io.open(loc, encoding='utf-8', errors='replace') as txt: |
990 | 991 | input_text = txt.read() |
991 | 992 | # The 'Yes' and 'No' will be converted to 'True' and 'False' in the yaml.load() |
992 | 993 | # Therefore, we need to wrap the original value in quote to prevent |
@@ -1513,34 +1514,28 @@ def write_output(abouts, location, format): # NOQA |
1513 | 1514 | about_dicts = about_object_to_list_of_dictionary(abouts) |
1514 | 1515 | location = add_unc(location) |
1515 | 1516 | if format == 'csv': |
1516 | | - errors = save_as_csv(location, about_dicts, get_field_names(abouts)) |
| 1517 | + save_as_csv(location, about_dicts, get_field_names(abouts)) |
| 1518 | + elif format == 'json': |
| 1519 | + save_as_json(location, about_dicts) |
1517 | 1520 | else: |
1518 | | - errors = save_as_json(location, about_dicts) |
1519 | | - return errors |
1520 | | - |
| 1521 | + save_as_excel(location, about_dicts) |
1521 | 1522 |
|
1522 | 1523 | def save_as_json(location, about_dicts): |
1523 | 1524 | with io.open(location, mode='w') as output_file: |
1524 | 1525 | data = util.format_about_dict_for_json_output(about_dicts) |
1525 | 1526 | output_file.write(json.dumps(data, indent=2)) |
1526 | | - return [] |
1527 | | - |
1528 | 1527 |
|
1529 | 1528 | def save_as_csv(location, about_dicts, field_names): |
1530 | | - errors = [] |
1531 | 1529 | with io.open(location, mode='w', encoding='utf-8', newline='') as output_file: |
1532 | 1530 | writer = csv.DictWriter(output_file, field_names) |
1533 | 1531 | writer.writeheader() |
1534 | | - csv_formatted_list = util.format_about_dict_for_csv_output(about_dicts) |
| 1532 | + csv_formatted_list = util.format_about_dict_output(about_dicts) |
1535 | 1533 | for row in csv_formatted_list: |
1536 | | - # See https://github.com/dejacode/about-code-tool/issues/167 |
1537 | | - try: |
1538 | | - writer.writerow(row) |
1539 | | - except Exception as e: |
1540 | | - msg = u'Generation skipped for ' + row['about_file_path'] + u' : ' + str(e) |
1541 | | - errors.append(Error(CRITICAL, msg)) |
1542 | | - return errors |
| 1534 | + writer.writerow(row) |
1543 | 1535 |
|
| 1536 | +def save_as_excel(location, about_dicts): |
| 1537 | + formatted_list = util.format_about_dict_output(about_dicts) |
| 1538 | + write_excel(location, formatted_list) |
1544 | 1539 |
|
1545 | 1540 | def pre_process_and_fetch_license_dict(abouts, api_url=None, api_key=None, scancode=False, reference=None): |
1546 | 1541 | """ |
|
0 commit comments