def __init__(self, args_factory=CommandFactory(os.environ), logger=None): self.args_factory = args_factory if logger: AppProject.set_logger(logger) else: AppProject(os.environ).setup_logger() self._logger = logger
def apply(self, prompt, context): app = AppProject(env_vars=os.environ) logger.debug("Applying CodePath filter to project :" + app.emproject.root) project_modules = app.emproject.paths["repo_modules"].path product_modules = app.product_layout()["repo_modules"].path get_paths_func = lambda: [project_modules, product_modules] prompt.completer = PathCompleter(get_paths=get_paths_func)
def _compute_update_seq_no(self): self.displayer.computing_rev_no() try: revision_no = int(self.svn_client.revision_number()) except Exception: revision_no = 0 self.displayer.unable_to_rev_no_svn_not_installed("-1") app_config = AppProject(env_vars=self.env_vars).config rev_no_offset = app_config.get("svn.rev.no.offset", "0") result = revision_no + 1 + int(rev_no_offset) self.displayer.update_seq_no_computed(result) return result
def __init__( self, pytest=pytest, templates_path=None, emprj_path=None, context_builder=None, verbose_mode="-v", test_group="all", test_name=None, reuse_tests=False, args=None, ): self.reuse_tests = reuse_tests self.emprj_path = emprj_path self.app_project = AppProject(emprj_path=emprj_path) self.context_builder = self._init_context_builder( self.app_project, context_builder ) self.apprunner = FileAppRunner(templates_path, emprj_path, self.context_builder) self._test_generator = None self.pytest = pytest self.displayer = TestTemplatesCommandDisplayer() self.test_loader = TestLoader(self.all_tests_path, templates_path) self.verbose_mode = verbose_mode self.test_group = test_group self.test_name = test_name
def __init__( self, env_vars=os.environ, context_builder=None, emprj_path=None, templates_path=None, run_on_db=True, listener=None, template_name=None, template_values={}, run_once=None, ): if context_builder is None: if emprj_path: context_builder = ContextBuilder(emprj_path=emprj_path) else: context_builder = ContextBuilder(AppProject(env_vars=env_vars)) if templates_path: self.templates_path = templates_path else: self.templates_path = EMTemplatesEnv().extract_templates_path( env_vars) self.context_builder = context_builder self.context_builder.addon_values.update(template_values) self.context = None self.listener = listener # If we are printing two templates, running the sql # allow the second template to see the modification made # by the first template (kenyames, entities inserted, etc) self.run_on_db = run_on_db self.template_name = template_name self.run_once = run_once
def __init__( self, env_vars=os.environ, context_builder=None, svn_client=None, clipboard=pyperclip, path=None, template_name=None, template_values={}, run_once=False, ): self._app_project = None self.env_vars = env_vars if context_builder is None: app_project = AppProject(env_vars=env_vars) context_builder = ContextBuilder(app_project) if svn_client is None: svn_client = EMSvn() self.path = path self.svn_client = svn_client self.context_builder = context_builder self.displayer = CreateSQLTaskDisplayer() self.clipboard = clipboard self.sqltask = None self.template_name = template_name self.template_values = template_values self.run_once = run_once
def __init__(self, app=None, emprj_path=None): self.app = app self.template_API = None self.context_values = None self.context_values_filepath = None self.addon_values = {} if not self.app: self.app = AppProject.make(emprj_path)
def build(self, testfile, emprj_path=None): expected = testfile.expected_sql() app_project = AppProject(emprj_path=self.emprj_path) actual = self.apprunner.run_test(testfile) template_name = testfile.template_name() return ExpectedSQLTestTemplate().render( template_name=template_name, expected=expected, actual=actual )
def test_something(capsys): classpath = "CoreEntities/InvalidProcess.xml" relative_src = "opt/em/products/agent_desktop/repository/default/" + classpath src = create_file(relative_src, contents="hola") em_prj_path = "/home/dgarcia/dev/python/em_automation/devtask/test/..testfilesystem/opt/em/projects/pacificorp" app_project = EMProject(emprj_path=em_prj_path) product_path = "/home/dgarcia/dev/python/em_automation/devtask/test/.testfilesystem/opt/em/products/agent_desktop" app_project._config = {"product.home": product_path} # assert "guaje" == app_project.product_layout()['repo_modules'].path em_prj_path = "/home/dgarcia/dev/python/em_automation/devtask/test/.testfilesystem/opt/em/projects/pacificorp" devtask.extend_process.app_project = AppProject(emprj_path=em_prj_path) product_path = "/home/dgarcia/dev/python/em_automation/devtask/test/.testfilesystem/opt/em/products/agent_desktop" app_project.emproject._config = {"product.home": product_path} app_project._em_config = {"product.home": product_path} extend_process(classpath) assert os.path.exists(src) assert capsys.readouterr().out == "dd"
def get_templates_path(self, env_vars): templates_path = "" templates_path_env_name = "SQL_TEMPLATES_PATH" em_prj_env_name = "EM_CORE_HOME" if templates_path_env_name in env_vars: templates_path = env_vars[templates_path_env_name] else: try: app_prj = AppProject(env_vars) templates_path = app_prj.paths["templates"].path except: error_msg = ( "Templates path can not be determined from current directory or from environment variables. " + "Please make sure you running this command from within an EM project folder. Otherwise, if you want to run it from anywhere within your filesystem, add '" + em_prj_env_name + "' to your environment variables (so templates path can be computes) or, add '" + templates_path_env_name + "'.") raise ValueError(error_msg) return templates_path
from prompt_toolkit import prompt from prompt_toolkit.history import FileHistory from prompt_toolkit.auto_suggest import AutoSuggestFromHistory from prompt_toolkit.completion import Completer, Completion # import click from fuzzyfinder import fuzzyfinder from sql_gen.sql_gen.completer import SuggestionCompleter from sql_gen.app_project import AppProject app = AppProject() addb = app.addb result = addb.query("SELECT NAME FROM EVA_ENTITY_DEFINITION") entity_names = [] # for key in result: # print(entity_names.append(key['NAME'])) # print (str(entity_names)) SQLKeywords = ["select", "from", "insert", "update", "delete", "drop"] class SQLCompleter(Completer): def get_completions(self, document, complete_event): word_before_cursor = document.get_word_before_cursor(WORD=True) matches = fuzzyfinder(word_before_cursor, SQLKeywords) for m in matches: yield Completion(m, start_position=-len(word_before_cursor)) while 1:
def __init__(self, emproject, fs, env_vars=None): self.emproject = emproject self.app_project = AppProject(env_vars=env_vars) self.fs = fs
def get_app_project(): if not app_project: app_project = AppProject() return app_project
def app_project(self): if not self._app_project: self._app_project = AppProject(env_vars=self.env_vars) return self._app_project
def test_query_runner(app_runner): app = AppProject(os.environ) app_runner.with_emproject_under( "/opt/em/projects/Pacificorp/trunk").saveAndExit().run_prod()