|
| 1 | +#!/usr/bin/env python |
| 2 | +#-*- coding: utf-8 -*- |
| 3 | +''' |
| 4 | +Copyright (C) Thibault Francois |
| 5 | +
|
| 6 | +This program is free software: you can redistribute it and/or modify |
| 7 | +it under the terms of the GNU Lesser General Public License as |
| 8 | +published by the Free Software Foundation, version 3. |
| 9 | +
|
| 10 | +This program is distributed in the hope that it will be useful, but |
| 11 | +WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | +Lesser General Lesser Public License for more details. |
| 14 | +
|
| 15 | +You should have received a copy of the GNU Lesser General Public License |
| 16 | +along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | +''' |
| 18 | + |
| 19 | +import argparse |
| 20 | +import os |
| 21 | +from odoo_csv_tools.lib import mapper |
| 22 | +from odoo_csv_tools.lib.transform import Processor |
| 23 | + |
| 24 | +if __name__ == '__main__': |
| 25 | + parser = argparse.ArgumentParser(description='Convert csv column Image Path into base64') |
| 26 | + parser.add_argument('file', metavar='F', help='file to convert') |
| 27 | + parser.add_argument('--path', dest='path', help='Image Path Prefix, default is the working directory') |
| 28 | + parser.add_argument('--out', dest='out', help='name of the result file, default out.csv', default="out.csv") |
| 29 | + parser.add_argument('-f', dest='fields', help='Fields to convert from path to base64, comma separated', required = True) |
| 30 | + args = parser.parse_args() |
| 31 | + |
| 32 | + file_csv = args.file |
| 33 | + out_csv = args.out |
| 34 | + path = args.path |
| 35 | + fields = args.fields |
| 36 | + if not path: |
| 37 | + path = os.getcwd() |
| 38 | + if not path.endswith(os.sep): |
| 39 | + path += os.sep |
| 40 | + |
| 41 | + |
| 42 | + processor = Processor(file_csv) |
| 43 | + mapping = processor.get_o2o_mapping() |
| 44 | + for f in fields.split(','): |
| 45 | + f = f.strip() |
| 46 | + mapping[f] = mapper.binary_map(mapper.remove_sep_mapper(f), path) |
| 47 | + processor.process(mapping, out_csv, {}, 'list') |
| 48 | + processor.write_to_file("") |
| 49 | + |
0 commit comments