def main(input_args):
    args = parse(input_args)
    if args.verbose:
        set_logging(debug=True, timestamps=True)
    else:
        set_logging(debug=False)
    rpmdata = RpmDataBuilder(args.build_config_path,
                             read_from(args.yum_info_path),
                             read_from(args.rpm_info_path),
                             read_from(args.crypto_info_path),
                             read_files(args.boms_path),
                             remote=args.remote).run()
    if args.output_rpmlist:
        write_to(args.output_rpmlist, '\n'.join(sorted([str(rpm) for rpm in rpmdata])))
    if args.output_json:
        write_to(args.output_json, to_json(rpmdata))
    csv = CsvConverter(rpmdata, preferred_field_order=['Name', 'Version', 'Release',
                                                       'License', 'Vendor', 'From repo',
                                                       'Source RPM'])
    if args.output_csv:
        write_to(args.output_csv, str(csv))
    if args.output_ms_csv:
        write_to(args.output_ms_csv,
                 csv.convert_to_ms_excel(text_fields=['Version', 'Size', 'Release']))
    if not args.output_json and not args.output_csv:
        print(rpmdata)
 def test_double_quote_is_escaped_with_double_quote():
     """
     RFC 4180
     """
     _input = [dict(a='1"2')]
     expected = '\r\n'.join(['"a"', '"1""2"'])
     assert CsvConverter(_input).convert() == expected
 def test_newlines_are_escaped():
     """
     ...in order to get properly formatted file when written
     """
     _input = [dict(a='1"2')]
     expected = '\r\n'.join(['"a"', '"1""2"'])
     assert CsvConverter(_input).convert() == expected
 def test_ms_excel_format():
     """
     MS Excel treats CSV files with 'sep=,' as the first line to get automatically columnized
     """
     _input = [dict(a=1, b=2)]
     expected = '\r\n'.join(['sep=,', '"a","b"', '"1","2"'])
     assert CsvConverter(_input).convert_to_ms_excel() == expected
 def test_field_with_beginning_minus_is_prefixed():
     """
     MS Excel CSV fields beginning with '-' are treated as an equation even they would be
     essentially just strings. Make sure to escape the beginning signs with something in order
     not to get field braking equation.
     """
     _input = [dict(a=-1), dict(a="-2a")]
     expected = '\r\n'.join(['sep=,', '"a"', '"-1"', r'"\-2a"'])
     assert CsvConverter(_input).convert_to_ms_excel() == expected
 def test_too_big_cell_is_truncated():
     """
     MS Excel has ~32k character limit per cell. BOM information can easily exceed this.
     """
     _input = [dict(a='1' * 32000), dict(a='2' * 32001)]
     expected = '\r\n'.join([
         'sep=,', '"a"', '"{}"'.format('1' * 32000),
         '"{}...{}"'.format('2' * 16000, '2' * 16000)
     ])
     assert CsvConverter(_input).convert_to_ms_excel() == expected
 def test_text_fields():
     """
     MS Excel CSV fields prefixed with '=' will be treated as equations to string.
     This makes it possible to e.g. to have all RPM version strings treated equally instead
     of making some of them treated as generic and some of them as integers.
     """
     _input = [dict(a=1, b=2)]
     expected = '\r\n'.join(['sep=,', '"a",="b"', '"1",="2"'])
     assert CsvConverter(_input).convert_to_ms_excel(
         text_fields=['b']) == expected
示例#8
0
    def write_csv(self, path):
        data = []
        for name, components in self.changes['added'].items():
            data += [self._get_csv_cells(name, [], components)]

        for name, components in self.changes['removed'].items():
            data += [self._get_csv_cells(name, components, [])]

        for name, components in self.changes['changed'].items():
            data += [
                self._get_csv_cells(name, components['old'], components['new'])
            ]

        csv = CsvConverter(sorted(data, key=itemgetter('name')),
                           preferred_field_order=[
                               'name', 'old_components', 'old_srpms',
                               'old_licenses', 'new_components', 'new_srpms',
                               'new_licenses'
                           ],
                           escape_newlines=False)
        write_to(path, csv.convert_to_ms_excel())
 def test_csv_preferred_order(_input, expected):
     assert CsvConverter(_input,
                         preferred_field_order=['b',
                                                'a']).convert() == expected
 def test_missing_fields_are_filled_with_none():
     _input = [dict(a='1"2')]
     expected = '\r\n'.join(['"a"', '"1""2"'])
     assert CsvConverter(_input).convert() == expected
 def test_to_csv_fail(_input, exception_re):
     with pytest.raises(Exception, match=exception_re):
         str(CsvConverter(_input))
 def test_str():
     _input = [dict(a=1)]
     assert str(CsvConverter(_input)) == CsvConverter(_input).convert()
 def test_csv(_input, expected):
     assert str(CsvConverter(_input)) == expected
 def test_unicode_input(_input, expected):
     assert str(CsvConverter(_input)) == expected
def _gen_components_csv(_list):
    csv = CsvConverter(
        _list,
        preferred_field_order=['Name', 'Version', 'Release', 'Source RPM'])
    return csv.convert_to_ms_excel(text_fields=['Version'])
示例#16
0
 def gen_components_csv(self, path):
     csv = CsvConverter(
         self.components,
         preferred_field_order=['Name', 'Version', 'Release', 'Source RPM'])
     write_to(path, csv.convert_to_ms_excel(text_fields=['Version']))