def main(argv): inputfile = '' outputfile = '' action = False try: opts, args = getopt.getopt(argv, "hi:o:a:", ["ifile=", "ofile=", "action="]) except getopt.GetoptError: print('main.py -i <inputfile> -o <outputfile> -a <action>') sys.exit(2) for opt, arg in opts: if opt == '-h': print('usage: app.py -i <inputfile> -o <outputfile> -a <action>') print(' to beautify: no <action> ') print(' to minify: set <action> to min') print('') print( ' Example: python3 app.py -i basic.json -o result.json -a min' ) print('') sys.exit() elif opt in ("-i", "--ifile"): inputfile = arg elif opt in ("-o", "--ofile"): outputfile = arg elif opt in ("-a", "--action"): action = arg if not inputfile: print('usage: main.py -i <inputfile> -o <outputfile> -a <action>' '\ninput file is mandatory') sys.exit(2) if inputfile[-4:] == '.css': if outputfile: if action == 'min': print(vkb.css.min(inputfile, outputfile, True)) else: print(vkb.css(inputfile, outputfile)) else: if action == 'min': print(vkb.css.min(inputfile, True)) else: print(vkb.css(inputfile)) if inputfile[-5:] == '.json': if outputfile: if action == 'min': print(vkb.json.min(inputfile, outputfile)) else: print(vkb.json(inputfile, outputfile)) else: if action == 'min': print(vkb.json.min(inputfile)) else: print(vkb.json(inputfile)) if inputfile[-4:] == '.xml': if outputfile: if action == 'min': print(vkb.xml.min(inputfile, outputfile, False)) else: print(vkb.xml(inputfile, outputfile)) else: if action == 'min': print(vkb.xml.min(inputfile, False)) else: print(vkb.xml(inputfile))
def test_json_beautify_with_custom_tab(self): json_expected = ' {\n "menu":\n {\n "id":"file"\n }\n}' json_pretty = vkb.json('{"menu":{"id":"file"}}', 2) #set tab 2 spaces self.assertEqual(json_pretty, json_expected)
def test_json_beautify(self): json_expected = ' {\n "menu":\n {\n "id":"file"\n }\n}' json_pretty = vkb.json('{"menu":{"id":"file"}}') self.assertEqual(json_pretty, json_expected)
def test_xml_beautify_and_save(tmpdir): file = tmpdir.join('output.json') json_pretty = vkb.json('{"menu":{"id":"file"}}', file.strpath) assert json_pretty == 48
def test_json_beautify_with_custom_tab(): json_expected = ' {\n "menu":\n {\n "id":"file"\n }\n}' json_pretty = vkb.json('{"menu":{"id":"file"}}', 2) #set tab 2 spaces assert json_pretty == json_expected
def test_json_beautify(): json_expected = ' {\n "menu":\n {\n "id":"file"\n }\n}' json_pretty = vkb.json('{"menu":{"id":"file"}}') assert json_pretty == json_expected