Skip to content

Commit

Permalink
Merge 37dbd94 into 05f0aab
Browse files Browse the repository at this point in the history
  • Loading branch information
JinTotonic committed May 25, 2018
2 parents 05f0aab + 37dbd94 commit 21df991
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
/venv/
/.idea
/.vscode/

yaml-tools.iml

*.pyc
.coverage
8 changes: 5 additions & 3 deletions src/yaml_tools.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/usr/bin/env python

import sys
import argparse
import ruamel.yaml
Expand Down Expand Up @@ -61,7 +63,7 @@ def has_valid_brackets(s):
:param s: e.g. my_list[0]
:return: (True, key, index) or (None, None, None)
"""
list_regex = re.compile("\A\w+\[{1}\d+\]{1}\Z")
list_regex = re.compile(r"\A\w+\[{1}\d+\]{1}\Z")
if list_regex.match(s) is not None:
key = s[:int(s.find('['))]
index = int(s[s.find('[') + 1: len(s) - 1])
Expand Down Expand Up @@ -128,10 +130,10 @@ def delete():
is_array, key, index = has_valid_brackets(item_to_delete)
try:
if is_array:
tmp = item_parent[key][index] # to trigger a KeyError if not found
item_parent[key][index] # to trigger a KeyError if not found
del item_parent[key][index]
else:
tmp = item_parent[item_to_delete]
item_parent[item_to_delete]
del item_parent[item_to_delete]
except (AttributeError, KeyError, IndexError, TypeError):
print("An error occurred when deleting '{}' :".format(item_to_delete))
Expand Down

0 comments on commit 21df991

Please sign in to comment.