Skip to content

Commit

Permalink
Minor 'promote' fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
lowell80 committed Jun 5, 2019
1 parent 1c9a974 commit f887733
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
4 changes: 2 additions & 2 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ Release v0.7.3 (DRAFT)
- Added the new ``ref:ksconf_cmd_xmlformat`` command.

- The ``ksconf xml-format`` command brings format consistency to your XML representations of Simple XML dashboards and navigation files by fixing indention and automatically adding ``<![CDATA[ ... ]]>`` blocks, as needed, to reduce the need for XML escaping, resulting in more readable source.
- Additionally, a new pre-commit hook named ``pchook_ksconf_xml-format` was added to leverage this new functionality. It looks specifically for xml views and navigation files based on path. This may also include Advanced XML, which hasn't been tested; So if you use Advanced XML, proceed with caution.
- Additionally, a new pre-commit hook named `pchook_ksconf_xml-format` was added to leverage this new functionality. It looks specifically for xml views and navigation files based on path. This may also include Advanced XML, which hasn't been tested; So if you use Advanced XML, proceed with caution.
- Note that this adds ``lxml`` as a packaging dependency which is needed for pre-commit hooks, but not strictly required at run time for other ksconf commands. This is NOT ideal, and may change in the future in attempts to keep ksconf as light-weight and standalone as possible. One possible alternative is setting up a different repo for pre-commit hooks. Python packaging and distribution tips welcome.

- Fixed data loss bug in ``promote`` (inteactive mode only) and improved some UI text and prompts.
- Fixed colorization of ``ksconf diff`` output where certain lines failed to showup in the correct color.
- Extended the output of ``ksconf --version`` to show the names and version of external modules, when present.
- Minor improvements to ``promote`` prompts in interactive mode. (NOTE that some bugs were found but not yet fixed in the promote command.)
- Improved some resource allocation in corner cases.


Expand Down
13 changes: 9 additions & 4 deletions ksconf/commands/promote.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ksconf.commands import ConfDirProxy
from ksconf.commands import KsconfCmd, dedent, ConfFileType
from ksconf.conf.delta import compare_cfgs, DIFF_OP_DELETE, summarize_cfg_diffs, show_diff, \
DIFF_OP_EQUAL, DiffStanza
DIFF_OP_EQUAL, DiffStanza, DiffStzKey
from ksconf.conf.merge import merge_conf_dicts
from ksconf.conf.parser import PARSECONF_STRICT_NC, PARSECONF_STRICT
from ksconf.consts import EXIT_CODE_FAILED_SAFETY_CHECK, EXIT_CODE_NOTHING_TO_DO, \
Expand Down Expand Up @@ -321,12 +321,16 @@ def prompt_yes_no(prompt):
diff = compare_cfgs(cfg_tgt, cfg_src, allow_level0=False)
for op in diff:
if op.tag == DIFF_OP_DELETE:
# This is normal. Not all default entries will be updated in local.
# This is normal. Only changed attributes are copied & updated in local.
continue
elif op.tag == DIFF_OP_EQUAL:
# Q: Should we simply remove everything from the source file that already lines
# up with the target? (Probably?) For now just skip...
if prompt_yes_no("Remove matching entry {0} ".format(op.location)):
# up with the target? Just ask
if isinstance(op.location, DiffStzKey):
msg = "[{0.stanza}] {0.key}".format(op.location)
elif isinstance(op.location, DiffStanza):
msg = "[{0.stanza}]".format(op.location)
if prompt_yes_no("Remove matching entry {0} ".format(msg)):
if isinstance(op.location, DiffStanza):
del out_src[op.location.stanza]
else:
Expand All @@ -344,6 +348,7 @@ def prompt_yes_no(prompt):
del out_src[op.location.stanza]
else:
show_diff(self.stdout, [op])
# Logically, this must be either an INSERT or REPLACE
if prompt_yes_no("Apply [{0}] {1}".format(op.location.stanza, op.location.key)):
# Move key
out_cfg[op.location.stanza][op.location.key] = op.b
Expand Down

0 comments on commit f887733

Please sign in to comment.