Пример #1
0
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))
Пример #2
0
def test_css_beautify():
    css_expected = '.head{\n    margin:0 8px;\n    /*display:none*/\n}\na:active{\n    color:red\n}'
    css_pretty = vkb.css(
        '.head{margin:0 8px;/*display:none*/}a:active{color:red}')
    assert css_pretty.strip() == css_expected.strip()
 def test_css_beautify_with_custom_tab(self):
     css_expected = '.head{\n  margin:0 8px;\n  /*display:none*/\n}\na:active{\n  color:red\n}'
     css_pretty = vkb.css('.head{margin:0 8px;/*display:none*/}a:active{color:red}', 2) #set tab 2 spaces
     self.assertEqual(css_pretty.strip(), css_expected.strip())
Пример #4
0
def test_css_beautify_and_save(tmpdir):
    file = tmpdir.join('output.xml')
    css_pretty = vkb.css(
        '.head{margin:0 8px;/*display:none*/}a:active{color:red}',
        file.strpath)
    assert css_pretty == 74