Commit bc80e898903fbcd217903fc82372ecdb156afbcd
1 parent
40eb5d02
Exists in
master
Adição de arquivo para evitar conflito no merge
git-svn-id: http://svn.brlight.net/svn/lightbase-neo/trunk/LBBulk@904 29b92fdf-8c97-4584-b987-84e8d3c556fa
Showing
1 changed file
with
61 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,61 @@ |
| 1 | +#!../../../../../../bin/python | |
| 2 | +__author__ = 'eduardo' | |
| 3 | +import sys, getopt | |
| 4 | +from lbbulk.lib.csv import CSVFileHandler | |
| 5 | + | |
| 6 | +class Convert(object): | |
| 7 | + """ | |
| 8 | + Classe para o comando de conversão | |
| 9 | + """ | |
| 10 | + def __init__(self, parameters): | |
| 11 | + """ | |
| 12 | + Construtor | |
| 13 | + """ | |
| 14 | + self.parameters = parameters | |
| 15 | + | |
| 16 | + def __doc__(self): | |
| 17 | + """ | |
| 18 | + Documentação dos comandos | |
| 19 | + """ | |
| 20 | + return "Comandos válidos são: " \ | |
| 21 | + "-i arquivo de entrada " \ | |
| 22 | + "-o arquivo de saída" | |
| 23 | + | |
| 24 | + def csv2json(self): | |
| 25 | + """ | |
| 26 | + Converte o arquivo CSV para o JSON | |
| 27 | + """ | |
| 28 | + csv_handler = CSVFileHandler(**self.parameters) | |
| 29 | + csv_handler.csv2json() | |
| 30 | + return | |
| 31 | + | |
| 32 | +if __name__ == '__main__': | |
| 33 | + parameters = dict() | |
| 34 | + parameters['outfile'] = "/tmp/saida.xml" | |
| 35 | + # Faz o parsing dos argumentos | |
| 36 | + try: | |
| 37 | + opts, args = getopt.getopt(sys.argv[1:], "hi:o:d:a:q:f:", ["ifile=", "ofile=", "help=", "delimiter=", "as_dict=", "quotechar=", "fieldnames="]) | |
| 38 | + except getopt.GetoptError: | |
| 39 | + print('convert.py -i <inputfile> -o <outputfile>') | |
| 40 | + sys.exit(2) | |
| 41 | + for opt, arg in opts: | |
| 42 | + if opt in ('-h', "--help"): | |
| 43 | + convert = Convert(parameters=parameters) | |
| 44 | + print(convert.__doc__()) | |
| 45 | + sys.exit() | |
| 46 | + elif opt in ("-i", "--ifile"): | |
| 47 | + parameters['filename'] = arg | |
| 48 | + elif opt in ("-o", "--ofile"): | |
| 49 | + parameters['outfile'] = arg | |
| 50 | + elif opt in ("-d", "--delimiter"): | |
| 51 | + parameters['delimiter'] = arg | |
| 52 | + elif opt in ("-a", "--as_dict"): | |
| 53 | + parameters['as_dict'] = arg | |
| 54 | + elif opt in ("-q", "--quotechar"): | |
| 55 | + parameters['quotechar'] = arg | |
| 56 | + elif opt in ("-f", "--fieldnames"): | |
| 57 | + parameters['fieldnames'] = arg | |
| 58 | + | |
| 59 | + # Executa o comando | |
| 60 | + convert = Convert(parameters=parameters) | |
| 61 | + convert.csv2json() | |
| 0 | 62 | \ No newline at end of file | ... | ... |