Ejemplo n.º 1
0
def __execute():
    """
    Check the arguments.
    If the number of arguments does not match the specified number,
    quit the application with usage massages.
    """
    args = _parse_args()

    mode = args.mode
    nochange_case = args.nochange_case
    escapesequence_u005c = args.escapesequence_u005c
    comment_syntax = args.comment_syntax
    input_path = args.input_path
    output_path = args.output_path
    local_config = LocalConfig()

    set_uppercase(local_config, not nochange_case)
    set_escapesequence_u005c(escapesequence_u005c)
    set_comment_syntax(local_config, comment_syntax)
    """
    The application requires either "file" or "directory"
    as a command line argument. If the argument does not match them,
    quit the application with usage massages.
    """
    if mode == "file":
        format_file(input_path, output_path, local_config)
    elif mode == "directory":
        format_dir(input_path, output_path, local_config)
    else:
        sys.exit()

    print("\n===== Finish the application =====")
    print("Output directory path : %s" % output_path)
    print("=====           End          =====")
Ejemplo n.º 2
0
    def run(self, edit, sync=False):
        view = self.view
        view.window().status_message('formatting...')
        self.settings = view.settings()
        self.user_settings = sublime.load_settings(
            'sublime-uroborosql-formatter.sublime-settings')
        # set syntax
        if self.settings.get('syntax') == \
                "Packages/Text/Plain text.tmLanguage":
            view.set_syntax_file("Packages/SQL/SQL.tmLanguage")
        # setting
        self.settings.set("tab_size", self.getval("uf_tab_size"))
        self.settings.set("translate_tabs_to_spaces",
                          self.getval("uf_translate_tabs_to_spaces"))

        config = LocalConfig()
        config.set_case(self.getval("uf_case"))
        config.set_reserved_case(self.getval("uf_reserved_case"))
        # set reserved words
        input_reserved_words_list = self.getval("uf_reserved_words")
        reserved_words = input_reserved_words_list.split(",")
        config.set_input_reserved_words(reserved_words)

        uroborosqlfmt.config.glb.escape_sequence_u005c = self.getval(
            "uf_escapesequence_u005c")
        if str(self.getval("uf_comment_syntax")).upper() == "DOMA2":
            config.set_commentsyntax(Doma2CommentSyntax())

        raw_text = ""
        regions = view.sel()
        # format selection
        if len(regions) > 1 or not regions[0].empty():
            for region in view.sel():
                if not region.empty():
                    raw_text = view.substr(region)
        else:  # format all
            region = sublime.Region(0, view.size())
            raw_text = view.substr(region)

        if sync:
            self.run_format(edit, raw_text, config, region.a, region.b)
        else:
            threading.Thread(target=self.run_format,
                             args=(edit, raw_text, config, region.a,
                                   region.b)).start()
    def test_uppercase_config(self):
        self.assertEqual(format_sql("""
        select * from DUAL
        """, LocalConfig().set_uppercase(False)),
"""select
\t*
from
\tDUAL"""
        )


        self.assertEqual(format_sql("""
        select * from DUAL
        """, LocalConfig()),
"""SELECT
\t*
FROM
\tDUAL"""
        )
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
def format_sql(text):
    formated = uroborosqlfmt.format_sql(text, LocalConfig())

    return formated