def get_completer(self, settings=None, casing=None): metadata = self.metadata from pgcli.pgcompleter import PGCompleter from pgspecial import PGSpecial comp = PGCompleter(smart_completion=True, settings=settings, pgspecial=PGSpecial()) schemata, tables, tbl_cols, views, view_cols = [], [], [], [], [] for sch, tbls in metadata["tables"].items(): schemata.append(sch) for tbl, cols in tbls.items(): tables.append((sch, tbl)) # Let all columns be text columns tbl_cols.extend( [self._make_col(sch, tbl, col) for col in cols]) for sch, tbls in metadata.get("views", {}).items(): for tbl, cols in tbls.items(): views.append((sch, tbl)) # Let all columns be text columns view_cols.extend( [self._make_col(sch, tbl, col) for col in cols]) functions = [ FunctionMetadata(sch, *func_meta, arg_defaults=None) for sch, funcs in metadata["functions"].items() for func_meta in funcs ] datatypes = [(sch, typ) for sch, datatypes in metadata["datatypes"].items() for typ in datatypes] foreignkeys = [ ForeignKey(*fk) for fks in metadata["foreignkeys"].values() for fk in fks ] comp.extend_schemata(schemata) comp.extend_relations(tables, kind="tables") comp.extend_relations(views, kind="views") comp.extend_columns(tbl_cols, kind="tables") comp.extend_columns(view_cols, kind="views") comp.extend_functions(functions) comp.extend_datatypes(datatypes) comp.extend_foreignkeys(foreignkeys) comp.set_search_path(["public"]) comp.extend_casing(casing or []) return comp
def plugin_loaded(): global settings settings = sublime.load_settings('PgcliSublime.sublime_settings') init_logging() logger.debug('Plugin loaded') # Before we can import pgcli, we need to know its path. We can't know that # until we load settings, and we can't load settings until plugin_loaded is # called, which is why we need to import to a global variable here sys.path = settings.get('pgcli_dirs') + sys.path for sdir in settings.get('pgcli_site_dirs'): site.addsitedir(sdir) logger.debug('System path: %r', sys.path) global PGCli, need_completion_refresh, need_search_path_refresh global has_meta_cmd, has_change_path_cmd, has_change_db_cmd from pgcli.main import (PGCli, has_meta_cmd, has_change_path_cmd, has_change_db_cmd) global PGExecute from pgcli.pgexecute import PGExecute global PGCompleter from pgcli.pgcompleter import PGCompleter global special from pgspecial import PGSpecial special = PGSpecial() global CompletionRefresher from pgcli.completion_refresher import CompletionRefresher global Document from prompt_toolkit.document import Document global format_output from pgcli.main import format_output global psycopg2 import psycopg2 global sqlparse import sqlparse
import simplejson as json from flask import Flask, request, Response, render_template from threading import Lock, Thread from multiprocessing import Queue from collections import defaultdict from collections import OrderedDict from pgcli.pgexecute import PGExecute from pgspecial import PGSpecial from pgcli.completion_refresher import CompletionRefresher from prompt_toolkit.document import Document from itsdangerous import Serializer try: from urlparse import urlparse except ImportError: from urllib.parse import urlparse special = PGSpecial() from psycopg2.extensions import (TRANSACTION_STATUS_IDLE, TRANSACTION_STATUS_ACTIVE, TRANSACTION_STATUS_INTRANS, TRANSACTION_STATUS_INERROR, TRANSACTION_STATUS_UNKNOWN, STATUS_READY, STATUS_IN_TRANSACTION, STATUS_PREPARED) home_dir = os.path.expanduser('~/.pghoffserver') completers = defaultdict(list) # Dict mapping urls to pgcompleter objects completer_lock = Lock() completerSettings = defaultdict(list) executors = defaultdict(list) # Dict mapping buffer ids to pgexecutor objects executor_lock = defaultdict(lambda: Lock())