예제 #1
0
def get_config():
    fn = get_config_filename('CSS Comb')
    s = open(fn, 'r').read()
    #del // comments
    s = re.sub(r'(^|[^:])//.*', r'\1', s)
    d = json.loads(s)
    return json.dumps(d)
예제 #2
0
def do_format(text):

    fn = get_config_filename('ColdFusion Beautify')
    s = open(fn, 'r').read()
    #del // comments
    s = re.sub(r'(^|[^:])//.*', r'\1', s)
    d = json.loads(s)

    opts = default_options()

    opts.tab_size = d.get('tab_size', 4)
    opts.indent_size = d.get('indent_size', 4)
    opts.indent_char = d.get('indent_char', ' ')
    opts.indent_with_tabs = d.get('indent_with_tabs', False)
    opts.expand_tags = d.get('expand_tags', False)
    opts.minimum_attribute_count = d.get('minimum_attribute_count', 2)
    opts.first_attribute_on_new_line = d.get('first_attribute_on_new_line',
                                             False)
    opts.reduce_empty_tags = d.get('reduce_empty_tags', False)
    opts.reduce_whole_word_tags = d.get('reduce_whole_word_tags', False)
    opts.exception_on_tag_mismatch = d.get('exception_on_tag_mismatch', False)
    opts.custom_singletons = d.get('custom_singletons', '')

    fmt = Beautifier(text, opts)
    return fmt.beautify()
예제 #3
0
def options():
    ini = get_config_filename('AStyle Format')
    if os.path.isfile(ini):
        s = open(ini).read()
    else:
        s = ''
    return s
예제 #4
0
def options():

    op = jsbeautifier.default_options()
    fn = get_config_filename('JS Beautify')
    if not os.path.isfile(fn):
        return op

    with open(fn) as f:
        d = json.load(f)
        op.indent_size = d.get('indent_size', 4)
        op.indent_char = d.get('indent_char', ' ')
        op.indent_with_tabs = d.get('indent_with_tabs', False)
        op.preserve_newlines = d.get('preserve_newlines', True)
        op.max_preserve_newlines = d.get('max_preserve_newlines', 10)
        op.space_in_paren = d.get('space_in_paren', False)
        op.e4x = d.get('e4x', False)
        op.jslint_happy = d.get('jslint_happy', False)
        op.brace_style = d.get('brace_style', 'collapse')
        op.keep_array_indentation = d.get('keep_array_indentation', False)
        op.keep_function_indentation = d.get('keep_function_indentation',
                                             False)
        op.eval_code = d.get('eval_code', False)
        op.unescape_strings = d.get('unescape_strings', False)
        op.wrap_line_length = d.get('wrap_line_length', 0)
        op.break_chained_methods = d.get('break_chained_methods', False)
    return op
def opt():
    fn = get_config_filename('SQL Parse')
    if os.path.isfile(fn):
        s = open(fn, 'r').read()
        #del // comments
        s = re.sub(r'(^|[^:])//.*', r'\1', s)
        d = json.loads(s)
    else:
        d = {}
    return d
def get_cmd():
    interpreter = 'ruby'
    executable = 'rubocop'

    #cmd = [interpreter, executable]
    cmd = [executable]

    cmd.extend(['--config', get_config_filename('Ruby Rubocop')])
    cmd.extend(['--stdin', '-', '--auto-correct'])

    return cmd
def format_xml(text):

    fn = get_config_filename('XML IndentX')
    s = open(fn, 'r').read()
    d = json.loads(s)

    xml_fmt.indentString = d.get('indent_string', '  ')
    xml_fmt.removeComments = d.get('remove_comments', False)
    xml_fmt.removeEmptyLines = d.get('remove_empty_lines', False)

    return xml_fmt.indent(text)
예제 #8
0
def do_format(text):

    fn = get_config_filename('CSS Clean')
    s = open(fn, 'r').read()
    #del // comments
    s = re.sub(r'(^|[^:])//.*', r'\1', s)
    cleancss.settings = json.loads(s)

    lines = text.split('\n')
    result = cleancss.CssRule('', lines, [], -1).output()
    result.pop()
    return '\n'.join(result)
예제 #9
0
def run_app(text, syntax):

    command = [
        PROGRAM,
        '-l',
        syntax,
        '-c',
        get_config_filename('Uncrustify'),
        '--set',
        'newlines=LF',
    ]

    print('Running:', ' '.join(command))
    content = text.encode("utf-8")

    try:
        if os.name == 'nt':
            # to hide the console window brings from command
            si = subprocess.STARTUPINFO()
            si.dwFlags |= subprocess.STARTF_USESHOWWINDOW
            # si.wShowWindow = subprocess.SW_HIDE   # this is default provided

            proc = subprocess.Popen(command, \
                   stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE, startupinfo = si)
        else:
            proc = subprocess.Popen(command, \
                   stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)

        outs, errs = proc.communicate(input=content)

        ret_code = proc.poll()
        if ret_code != 0:
            if errs:
                msg = errs.decode("utf-8")
                # slice the last useless part if found (from Uncrustify)
                pos = msg.find("Try running with -h for usage information")
                err = "Uncrustify failed (0x%X)\n\n%s" % (ret_code, msg[:pos])
            else:
                err = "Uncrustify stopped (0x%X)" % ret_code

            app.msg_box(err, app.MB_OK + app.MB_ICONWARNING)
            return

    except (OSError, ValueError, subprocess.CalledProcessError,
            Exception) as e:

        err = "Cannot execute '%s':\n\n%s" % (command[0], e)
        app.msg_box(err, app.MB_OK + app.MB_ICONERROR)
        return

    formatted_code = outs.decode("utf-8")
    return formatted_code
예제 #10
0
def do_fix_imports(text):

    fn = get_config_filename('Python Fix Imports')
    op_split = ini_read(fn, 'op', 'split_import_statements', '1') == '1'
    op_sort = ini_read(fn, 'op', 'sort_import_statements', '1') == '1'

    res, textout = fmt.sortImportGroups(ed_filename,
                                        text,
                                        splitImportStatements=op_split,
                                        sortImportStatements=op_sort)
    if res:
        if textout != text:
            return textout
예제 #11
0
def do_format(text):

    fn = get_config_filename('Bash Beautify')
    s = open(fn, 'r').read()
    #del // comments
    s = re.sub(r'(^|[^:])//.*', r'\1', s)
    d = json.loads(s)

    fmt.tab_size = d.get('tab_size', 4)
    fmt.tab_str = d.get('tab_str', ' ')
    fmt.apply_function_style = d.get('apply_function_style', None)

    res, error = fmt.beautify_string(text)
    return res
예제 #12
0
def options():

    op = v.default_options()
    fn = get_config_filename('VBScript Format')
    if not os.path.isfile(fn):
        return op

    with open(fn) as f:
        d = json.load(f)
        op.indent_size = d.get("indent_size", 1)
        op.indent_char = d.get("indent_char", "\t")
        op.indent_with_tabs = d.get("indent_with_tabs", True)
        op.preserve_newlines = d.get("preserve_newlines", True)
        op.max_preserve_newlines = d.get("max_preserve_newlines", 10)
    return op
def do_format_ex(text, is_css):

    fn = get_config_filename('CSS AutoPrefixer')
    s = open(fn, 'r').read()
    #del // comments
    s = re.sub(r'(^|[^:])//.*', r'\1', s)
    opt = json.loads(s)
    opt['is_css'] = is_css
    opt = json.dumps(opt)

    try:
        return run_node(text, [tool_js, opt])
    except Exception as e:
        app.msg_box('Error while running Node.js \n' + str(e),
                    app.MB_OK + app.MB_ICONERROR)
def get_mode():

    fn = get_config_filename('Python Black')
    s = open(fn, 'r').read()
    #del // comments
    s = re.sub(r'(^|[^:])//.*', r'\1', s)
    d = json.loads(s)

    line_len = d.get('line_len', black.DEFAULT_LINE_LENGTH)
    norm = d.get('string_normalization', True)
    target = d.get('target')

    return black.FileMode(target_versions=ver_map.get(target, ver33),
                          line_length=line_len,
                          string_normalization=norm)
예제 #15
0
def options():

    op = cssbeautifier.default_options()
    fn = get_config_filename('CSS Beautify')
    if not os.path.isfile(fn):
        return op

    with open(fn) as f:
        d = json.load(f)
        op.indent_size = d.get('indent_size', 4)
        op.indent_char = d.get('indent_char', ' ')
        op.selector_separator_newline = d.get('selector_separator_newline',
                                              True)
        op.end_with_newline = d.get('end_with_newline', False)
    return op
예제 #16
0
def options():
    fn = get_config_filename('Markdown Table Format')
    if os.path.isfile(fn):
        s = open(fn, 'r').read()
        #del // comments
        s = re.sub(r'(^|[^:])//.*', r'\1', s)
        d = json.loads(s)

        op_margin = d.get("margin", 1)
        op_padding = d.get("padding", 0)

        s = d.get("default_justify", "L")
        op_just = table.Justify.LEFT if s == "L" else table.Justify.RIGHT if s == "R" else table.Justify.CENTER

        return op_margin, op_padding, op_just
    else:
        return 1, 0, table.Justify.LEFT
def do_format_ex(source_text, lang_key):

    fn_ini = get_config_filename('Embarcadero Format')
    opt_formater_dir = ini_read(fn_ini, 'op', 'formater_directory', '')
    fn_exe = os.path.join(opt_formater_dir, 'formatter.exe')
    fn_exe_cfg = os.path.join(opt_formater_dir, 'formatter.config')

    if not os.path.isfile(fn_exe):
        msg_box(
            'Embarcadero Format:\nPath of formatter.exe is wrong:\n' + fn_exe,
            MB_OK + MB_ICONERROR)
        return

    try:
        s = source_text

        fx = tempfile.NamedTemporaryFile(delete=False)
        file_name = fx.name
        fx.close()

        with open(file_name, 'w') as f:
            f.write(s)

        cmd = '"{}" {} {} "{}"'.format(
            fn_exe, lang_key, '-config "{}"'.format(fn_exe_cfg)
            if os.path.isfile(fn_exe_cfg) else '', file_name)

        proc = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE)
        out, err = proc.communicate()
        proc.stdout.close()

        if err:
            print('Embarcadero Format: ' + err)

        with open(file_name, 'r') as f:
            s = f.read()

        os.remove(file_name)

        return s
    except:
        raise
def get_ops():
    fn = get_config_filename('SQL Uroboro Format')
    if os.path.isfile(fn):
        s = open(fn, 'r').read()
        #del // comments
        s = re.sub(r'(^|[^:])//.*'  , r'\1', s)
        d = json.loads(s)
    else:
        d = {}

    config = LocalConfig()
    config.set_case(d.get("uf_case", "upper"))
    config.set_reserved_case(d.get("uf_reserved_case", "upper"))
    config.set_input_reserved_words(d.get("uf_reserved_words", config.input_reserved_words))
    uroborosqlfmt.config.glb.escape_sequence_u005c = d.get("uf_escapesequence_u005c", False)
    if d.get("uf_comment_syntax", "uroboroSQL").upper() == "DOMA2":
        config.set_commentsyntax(Doma2CommentSyntax())

    tab_config = {}
    tab_config["size"] = d.get("uf_tab_size", 4)
    tab_config["spaces"] = d.get("uf_translate_tabs_to_spaces", True)

    return config, tab_config