Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update merge options #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -154,3 +154,5 @@ tags
.history

# End of https://www.gitignore.io/api/vim,python,visualstudiocode

.env3
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
'pytest-runner'
],
install_requires=[
'pysigsci>=2.0.7'
'pysigsci>=3.3.4'
],
tests_require=[
'pytest'
Expand Down
17 changes: 14 additions & 3 deletions sigsci_site_manager/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
ADVANCED_RULES)
from sigsci_site_manager.util import add_new_user, filter_data, equal_rules

OVERWRITE_TEMPLATED_RULES = False

def _find_match(needle: dict, haystack: list, keys: list):
"""Find a dictionary in a list of dictionary based on a set of keys"""
Expand Down Expand Up @@ -178,12 +179,18 @@ def merge_templated_rules(api, data):

# Loop through the templated rules
for item in data:
if item in rule_names:
if item in rule_names and not OVERWRITE_TEMPLATED_RULES:
# Rule name in the list of already configured rules so skip
print(' Skipping %s (configured)' % item)
else:
print(' Adding %s' % item)

try:
if OVERWRITE_TEMPLATED_RULES:
print(' Overwritting %s (configured)' % item)
api.delete_templated_rule(item)
else:
print(' Adding %s' % item)

api.add_templated_rules(item, data[item])
except Exception as e: # pylint: disable=broad-except
print(' Failed: %s' % e)
Expand Down Expand Up @@ -374,7 +381,9 @@ def merges(api, site_name, data, categories):
print('Skipping %s (excluded)' % k)


def merge(api, dst_site, src_site=None, file_name=None, categories=None):
def merge(api, dst_site, src_site=None, file_name=None, categories=None, overwrite_templated_rules=False):
global OVERWRITE_TEMPLATED_RULES

if src_site:
print('=' * 80)
print("Merging site '%s' onto site '%s'..." % (src_site, dst_site))
Expand All @@ -384,4 +393,6 @@ def merge(api, dst_site, src_site=None, file_name=None, categories=None):
with open(file_name, 'r') as f:
data = json.loads(f.read())

OVERWRITE_TEMPLATED_RULES = overwrite_templated_rules

merges(api, dst_site, data, categories)
6 changes: 5 additions & 1 deletion sigsci_site_manager/site_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ def do_merge(args):
if exact_match or args.yes or cont.lower() in ['y', 'yes']:
for site in sites:
merge(api, site, args.src_site, args.file_name,
build_category_list(args.include, args.exclude))
build_category_list(args.include, args.exclude),
args.overwrite_templated_rules)


def do_validate(args):
Expand Down Expand Up @@ -219,6 +220,9 @@ def _validate_category_list(value: str):
merge_parser.add_argument('--dry-run', required=False,
action='store_true', dest='dry_run',
help='Print actions without making any changes')
merge_parser.add_argument('--overwrite-templated-rules', default=False,
action='store_true', dest='overwrite_templated_rules',
help='Overwrite existing template rules.')
merge_cat_group = merge_parser.add_mutually_exclusive_group()
merge_cat_group.add_argument(
'--include', required=False, metavar='CATEGORY_LIST',
Expand Down