Skip to content

Commit

Permalink
Issue 36.ant.a (#37)
Browse files Browse the repository at this point in the history
* Update CHANGELOG.md

* #16 - Uncaught exception

* Update .pylintrc
  • Loading branch information
antaenc authored Aug 5, 2022
1 parent 7b5375a commit fa50ae3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
1 change: 1 addition & 0 deletions .pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ disable=
missing-function-docstring,
missing-module-docstring,
redefined-outer-name,
too-many-return-statements,
unused-import,
good-names=
template-python
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
[markdownlint](https://dlaa.me/markdownlint/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [2.1.1] - 2022-08-05

### Added in 2.1.1

- Fixed uncaught exception

## [2.1.0] - 2022-08-04

### Added in 2.1.0
Expand Down
36 changes: 18 additions & 18 deletions G2SetupConfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,68 +5,69 @@
import pathlib
import sys
import G2Paths
from senzing import G2Config, G2ConfigMgr, G2Exception, G2ModuleException
from senzing import G2Config, G2ConfigMgr, G2Exception
from G2IniParams import G2IniParams


def setup_config(ini_params, auto_mode):

# Determine if a default/initial G2 configuration already exists
default_config_id = bytearray()
g2_config_mgr = G2ConfigMgr()
g2_config_mgr.init("g2ConfigMgr", ini_params, False)
g2_config_mgr.getDefaultConfigID(default_config_id)

try:
g2_config_mgr = G2ConfigMgr()
g2_config_mgr.init("g2ConfigMgr", ini_params, False)
g2_config_mgr.getDefaultConfigID(default_config_id)
except G2Exception as ex:
print('\nERROR: Could not init G2ConfigMgr or get default config ID.')
print(f'\n\t{ex}')
return -1

# If not in auto mode prompt user
if not auto_mode:

if default_config_id:
if not input('\nA configuration document already exists in the database. Do you want to replace it (yes/no)? ') in ['y', 'Y', 'yes', 'YES']:
print('\nWARN: Not replacing configuration in database.')
return -1
else:

if not input('\nInstalling template configuration to database. Do you want to continue (yes/no)? ') in ['y', 'Y', 'yes', 'YES']:
print('\nWARN: No default template configuration has been applied to the database.')
return -1

# Apply a default configuration
g2_config = G2Config()
g2_config.init("g2Config", ini_params, False)

try:
g2_config = G2Config()
g2_config.init("g2Config", ini_params, False)
config_handle = g2_config.create()
except G2ModuleException as ex:
print('\nERROR: Could not get template config from G2Config.')
except G2Exception as ex:
print('\nERROR: Could not init G2Config or get template config from G2Config.')
print(f'\n\t{ex}')
return -1

new_configuration_bytearray = bytearray()
g2_config.save(config_handle, new_configuration_bytearray)
g2_config.close(config_handle)

config_json = new_configuration_bytearray.decode()

# Save configuration JSON into G2 database.
new_config_id = bytearray()

try:

g2_config_mgr.addConfig(config_json, 'Configuration added from G2SetupConfig.', new_config_id)
except G2ModuleException as ex:
except G2Exception as ex:
ex_info = g2_config_mgr.getLastException().split('|', 1)
# The engine configuration compatibility version [{0}] does not match the version of the provided config[{1}]
if ex_info[0] == '0040E':
print("\nERROR: Failed to add config to the database. Please ensure your config is updated to the current version.")
print("\nERROR: Failed to add config to the repository. Please ensure your config is updated to the current version.")
else:
print("\nERROR: Failed to add config to the datastore.")
print("\nERROR: Failed to add config to the repository.")
print(f'\n\t{ex}')
return -1

# Set the default configuration ID.
try:
g2_config_mgr.setDefaultConfigID(new_config_id)
except G2ModuleException as ex:
except G2Exception as ex:
print("\nERROR: Failed to set config as default.")
print(f'\n\t{ex}')
return -1
Expand Down Expand Up @@ -112,5 +113,4 @@ def setup_config(ini_params, auto_mode):
iniParamCreator = G2IniParams()
ini_params = iniParamCreator.getJsonINIParams(iniFileName)


sys.exit(setup_config(ini_params, args.auto))

0 comments on commit fa50ae3

Please sign in to comment.