Skip to content

Commit

Permalink
Merge branch 'development_test'
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleksandr Danylchenko committed Jun 6, 2019
2 parents e7ba150 + 56c9500 commit ecb40ac
Show file tree
Hide file tree
Showing 9 changed files with 148 additions and 79 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## 1.2.5 2018-25-04
- TPLint no longer supported. Option now will skip.

## 1.1.5 2018-25-04
- Added new versions of tpl and ADDM. Also added stubs for future version.

Expand Down
12 changes: 8 additions & 4 deletions bmc_tplpre/check.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def parse_args_f():
TPLPreprocessor output result ignoring ADDM tpl version check_ide procedure.
Use when you want upload older or newer tpl on ADDM If file is not a .tplpre
- this option will be ignored. '''
tkn_h = ''' TKN_CORE env for TPLpreprocerssor only'''
full_path_h = '''Path to current edited or processed file. '''
u_h = '''Your ADDM user - root or tideway '''
p_h = '''Password for ADDM user '''
Expand All @@ -85,6 +86,7 @@ def parse_args_f():
developer.add_argument("-test_verbose", action="store_true", help=test_verbose_h)
developer.add_argument("-test_failfast", action="store_true", help=test_failfast_h)
developer.add_argument("-tpl", type=str, action='store', dest="version_tpl", default="", help=tpl_h)
developer.add_argument("-tkn_core", type=str, action='store', dest="tkn_core", default="", help=tkn_h)

# COMMON ARGS - works in most usual cases.
common.add_argument("-full_path", type=str, action='store', dest="full_path", default="", help=full_path_h)
Expand Down Expand Up @@ -153,10 +155,12 @@ def parse_args_f():

# Executing syntax checker:
if callable(conditional_functions['syntax_check_f']):
syntax_check_f = conditional_functions['syntax_check_f']
if syntax_check_f:
log.debug("SYNTAX:\t\tsyntax_check_f")
syntax_check_f()
print("LOCAL TPL Syntax check now skipped by default!")
pass
# syntax_check_f = conditional_functions['syntax_check_f']
# if syntax_check_f:
# log.debug("SYNTAX:\t\tsyntax_check_f")
# syntax_check_f()

# Executing zipping files (and upload maybe?)
if callable(conditional_functions['zip_files_f']):
Expand Down
90 changes: 58 additions & 32 deletions bmc_tplpre/check_ide/global_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
from check_ide.imports import TPLimports
from check_ide.test_queries import TestRead
from check_ide.upload import AddmOperations
from check_ide.syntax_checker import SyntaxCheck
from check_ide.local_logic import LocalLogic
from check_ide.scan import AddmScan

# Deprecated:
# from check_ide.syntax_checker import SyntaxCheck
# import json
# from pprint import pformat

Expand Down Expand Up @@ -55,6 +57,7 @@ def __init__(self, extra_args, known_args):
self.dev_vm_path = ''
self.system_user = ''
self.system_password = ''
self.tkn_core = ''

# IMPORTS ARGS:
self.recursive_imports = ''
Expand All @@ -71,6 +74,9 @@ def __init__(self, extra_args, known_args):
# Get all available arguments in three sets based on its type:
self.full_path_args, self.oper_args, self.addm_args_set = self.check_args_set(known_args=known_args,
extra_args=extra_args)
log.debug("full_path_args: %s", self.full_path_args)
log.debug("oper_args: %s", self.oper_args)
log.debug("addm_args_set: %s", self.addm_args_set)

# Check args in init module to further assign on function bodies:
# FULL PATH ARGS:
Expand Down Expand Up @@ -145,6 +151,9 @@ def __init__(self, extra_args, known_args):
self.patt_file_name = self.full_path_args['file_name']
self.patt_folder_name = self.full_path_args['pattern_folder']
self.env_cond = self.full_path_args['env_cond']
self.tkn_core = self.full_path_args['CORE_t']

log.debug("self.tkn_core %s", self.tkn_core)

if not self.working_dir:
log.error("File working dir is not extracted - I cannot proceed any function.")
Expand Down Expand Up @@ -187,6 +196,7 @@ def __init__(self, extra_args, known_args):
self.disco_mode = self.addm_args_set['disco_mode']
self.system_user = self.addm_args_set['system_user']
self.system_password = self.addm_args_set['system_password']

self.addm_ver = self.addm_args_set['addm_ver']
self.dev_vm_path = self.addm_args_set['dev_vm_path']
self.dev_vm_check = self.addm_args_set['dev_vm_check']
Expand Down Expand Up @@ -345,7 +355,7 @@ def make_function_set(self):
"import_patterns": "<function GlobalLogic.make_imports.<locals>.importer at 0x00000000036662F0>"
},
"addm_activate_f": "<function GlobalLogic.make_activate_zip.<locals>.activate at 0x000000000395FF28>",
"syntax_check_f": "<function GlobalLogic.make_syntax_check.<locals>.syntax_check at 0x000000000395FBF8>",
"syntax_check_f": "<function GlobalLogic._make_syntax_check.<locals>.syntax_check at 0x000000000395FBF8>",
"upload_f": false
}
Expand All @@ -364,7 +374,7 @@ def make_function_set(self):

return conditional_functions, conditional_results

# Doing business based on all decisions made:
# Doing business based on all decisions made:syntax_check_f
def cond_args(self):
"""
This section will compose sets of functions to execute.
Expand Down Expand Up @@ -407,7 +417,8 @@ def cond_args(self):
# This will be re-write if success:
imports_f = False
preproc_f = False
syntax_check_f = False
# LOCAL TPL Syntax check now skipped by default!
syntax_check_f = True
zip_files_f = False
addm_activate_f = False
upload_f = False
Expand Down Expand Up @@ -458,7 +469,15 @@ def cond_args(self):
log.debug("ADDM run tests.")
# I don't know:
else:
conditional_debug = dict(
tpl_folder = self.tpl_folder,
scan_hosts = self.scan_hosts,
disco_mode = self.disco_mode,
ssh = self.ssh,
tst_cond = self.tst_cond,
)
log.info("This set of conditional arguments is not supported by my logic, Please read docs.")
log.debug("Conditional statuses: %s", conditional_debug)

if upload_scan:
'''
Expand All @@ -481,7 +500,7 @@ def cond_args(self):

imports_f = self.imports_cond()
preproc_f = self.preproc_cond()
syntax_check_f = self.syntax_cond(tpl_version = self.addm_ver)
# syntax_check_f = self.syntax_cond(tpl_version = self.addm_ver)
addm_working_dir, tests_path = self.addm_dev_cond()

zip_files_f, addm_zip, local_zip = self.pattern_path_cond(addm_working_dir=addm_working_dir)
Expand Down Expand Up @@ -513,7 +532,7 @@ def cond_args(self):

imports_f = self.imports_cond()
preproc_f = self.preproc_cond()
syntax_check_f = self.syntax_cond(tpl_version = self.addm_ver)
# syntax_check_f = self.syntax_cond(tpl_version = self.addm_ver)
zip_files_f, addm_zip, local_zip = self.pattern_path_cond(addm_working_dir = 'Null')

log.info("Zipped for ADDM: "+str(self.addm_prod) +
Expand All @@ -540,7 +559,7 @@ def cond_args(self):

imports_f = self.imports_cond()
preproc_f = self.preproc_cond()
syntax_check_f = self.syntax_cond(tpl_version = self.addm_ver)
# syntax_check_f = self.syntax_cond(tpl_version = self.addm_ver)
addm_working_dir, tests_path = self.addm_dev_cond()

zip_files_f, addm_zip, local_zip = self.pattern_path_cond(addm_working_dir=addm_working_dir)
Expand Down Expand Up @@ -572,7 +591,7 @@ def cond_args(self):

imports_f = self.imports_cond()
preproc_f = self.preproc_cond()
syntax_check_f = self.syntax_cond(tpl_version = '')
# syntax_check_f = self.syntax_cond(tpl_version = '')

_local_mode_ = 'There is no ADDM connection, program is running in local mode.'
addm_zip = _local_mode_
Expand All @@ -591,6 +610,7 @@ def cond_args(self):

conditional_functions = dict(imports_f = imports_f,
preproc_f = preproc_f,
# LOCAL TPL Syntax check now skipped by default!
syntax_check_f = syntax_check_f,
zip_files_f = zip_files_f,
wipe_tku_f = wipe_tku_f,
Expand All @@ -605,7 +625,6 @@ def cond_args(self):

return conditional_functions, conditional_results


# Functions to make decisions based on options and create closures.
def imports_cond(self):
"""
Expand Down Expand Up @@ -734,7 +753,8 @@ def preproc_cond(self):
preproc_cond_f = self.make_preproc(workspace = self.workspace,
input_path = self.full_path,
output_path = self.working_dir,
mode = "usual_imports")
mode = "usual_imports",
tkn_core = self.tkn_core)
return preproc_cond_f

# MY IMPORTS TPLPreproc on 'imports':
Expand All @@ -748,7 +768,8 @@ def preproc_cond(self):
preproc_cond_f = self.make_preproc(workspace = self.workspace,
input_path = self.working_dir+os.sep+"imports",
output_path = self.working_dir+os.sep+"imports",
mode = "recursive_imports")
mode = "recursive_imports",
tkn_core = self.tkn_core)
return preproc_cond_f

# NOTHING:
Expand All @@ -764,7 +785,8 @@ def preproc_cond(self):
preproc_cond_f = self.make_preproc(workspace = self.workspace,
input_path = self.full_path,
output_path = self.working_dir,
mode = "solo_mode")
mode = "solo_mode",
tkn_core = self.tkn_core)

return preproc_cond_f

Expand Down Expand Up @@ -809,9 +831,10 @@ def syntax_cond(self, tpl_version):
- If no addm version -
it will use empty string as arg and run syntax check_ide for all supported versions.
"""
log.info("Syntax check_ide TPLPreprocessor result.")
log.debug("Syntax check_ide will run on tpl folders after usual TPLPreproc output. (usual_imports)")
syntax_check_cond_f = self.make_syntax_check(self.working_dir, disco_ver=tpl_version)
log.info("TPL Syntax local check no longer supported. skipping.")
# log.info("Syntax check_ide TPLPreprocessor result.")
# log.debug("Syntax check_ide will run on tpl folders after usual TPLPreproc output. (usual_imports)")
# syntax_check_cond_f = self._make_syntax_check(self.working_dir, disco_ver=tpl_version)

# Preproc will run on all files from folder 'imports'
elif self.recursive_imports or self.read_test:
Expand All @@ -820,10 +843,11 @@ def syntax_cond(self, tpl_version):
- If no addm version -
it will use empty string as arg and run syntax check_ide for all supported versions.
"""
log.info("Syntax check_ide on imports.")
log.debug("Syntax check_ide will run on imports folder after my importing logic. "
"(recursive_imports or read_test)")
syntax_check_cond_f = self.make_syntax_check(self.working_dir+os.sep+"imports", disco_ver=tpl_version)
log.info("TPL Syntax local check no longer supported. skipping.")
# log.info("Syntax check_ide on imports.")
# log.debug("Syntax check_ide will run on imports folder after my importing logic. "
# "(recursive_imports or read_test)")
# syntax_check_cond_f = self._make_syntax_check(self.working_dir+os.sep+"imports", disco_ver=tpl_version)

else:
log.debug("This mode is not operational: "+str(self.import_cond))
Expand All @@ -835,10 +859,11 @@ def syntax_cond(self, tpl_version):
- In this condition syntax check_ide will hope that imports are already in folder after previous runs.
"""
if self.env_cond == 'developer_tplpre' or self.env_cond == 'developer_tpl':
log.info("1/1 Syntax check_ide solo file.")
log.debug("1/2 Imports was already created just checking syntax for active pattern. "
"(not read_test not recursive_imports not usual_imports)")
syntax_check_cond_f = self.make_syntax_check(self.working_dir, disco_ver=tpl_version)
log.info("TPL Syntax local check no longer supported. skipping.")
# log.info("1/1 Syntax check_ide solo file.")
# log.debug("1/2 Imports was already created just checking syntax for active pattern. "
# "(not read_test not recursive_imports not usual_imports)")
# syntax_check_cond_f = self._make_syntax_check(self.working_dir, disco_ver=tpl_version)

elif self.env_cond == 'customer_tku':

Expand Down Expand Up @@ -1229,7 +1254,6 @@ def test_run_cond(self):
else:
log.debug("No test run, tst_cond = False.")


# Functions to create closures for all related options:

def make_test_read_query(self):
Expand Down Expand Up @@ -1263,7 +1287,7 @@ def importer():
return importer

@staticmethod
def make_preproc(workspace, input_path, output_path, mode):
def make_preproc(workspace, input_path, output_path, mode, tkn_core):
"""
Closure for preproc function.
Expand All @@ -1277,11 +1301,11 @@ def make_preproc(workspace, input_path, output_path, mode):

def pre_processing():
preproc = Preproc()
preproc.tpl_preprocessor(workspace, input_path, output_path, mode)
preproc.tpl_preprocessor(workspace, input_path, output_path, mode, tkn_core)
return pre_processing

@staticmethod
def make_syntax_check(working_dir, disco_ver):
def _make_syntax_check(working_dir, disco_ver):
"""
Closure for syntax check_ide function.
Expand All @@ -1294,12 +1318,14 @@ def make_syntax_check(working_dir, disco_ver):
:return: func - syntax check_ide with args in it.
"""

def syntax_check():
syntax = SyntaxCheck()
if_check = syntax.syntax_check(working_dir, disco_ver)
return if_check
log.info("TPL Syntax local check no longer supported. skipping.")

def _syntax_check():
# syntax = SyntaxCheck()
# if_check = syntax.syntax_check(working_dir, disco_ver)
return True

return syntax_check
return _syntax_check

@staticmethod
def make_zip(path, module_name, mode_single=None):
Expand Down
5 changes: 4 additions & 1 deletion bmc_tplpre/check_ide/imports.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ def recursive_imports(self, **importing_set_options):
find_importing_modules = find_importing_modules,
current_modules_name = current_modules_name)
find_importing_modules = find_2
log.debug("find_importing_modules: %s", find_importing_modules)
current_modules_name = current_2

if find_importing_modules:
Expand Down Expand Up @@ -425,7 +426,9 @@ def search_in_path(self, file_candidates, find_importing_modules, current_module

for pattern_module in find_importing_modules:
# Compile re based on item from [find_importing_modules] -> module SupportingFiles.CDM_Mapping
module_r = re.compile(pattern_module)
# Add semicolon to not to import files where module can have one word in name
module_r = re.compile("{}{}".format(pattern_module, ';'))
# log.debug("Searching with re - %s", module_r)
# Check opened file with re composed from each [find_importing_modules]
check_modules = module_r.findall(read_file)

Expand Down
Loading

0 comments on commit ecb40ac

Please sign in to comment.