Skip to content

Instantly share code, notes, and snippets.

@syldrathecat
Created August 1, 2019 13:25
Show Gist options
  • Save syldrathecat/68b671fb278077e75ff17b778817f229 to your computer and use it in GitHub Desktop.
Save syldrathecat/68b671fb278077e75ff17b778817f229 to your computer and use it in GitHub Desktop.
diff --git a/decode.py b/decode.py
index 9c427f8..cab1595 100644
--- a/decode.py
+++ b/decode.py
@@ -261,7 +261,7 @@ def get_value(pp_bin_file, var_path, data_dict=None, debug=False):
else:
data = data_dict.copy()
for category in var_path:
- if category:
+ if category is not None:
# helper that allows skipping the 'Entries' key name
if (isinstance(category, int)
and isinstance(data, dict) and 'Entries' in data):
@@ -274,7 +274,7 @@ def get_value(pp_bin_file, var_path, data_dict=None, debug=False):
return None
except (TypeError, IndexError):
if isinstance(data, list):
- indices = [str(i) for i in range(len(data)-1)]
+ indices = [str(i) for i in range(len(data))]
else:
indices = []
msg = 'ERROR: Invalid parameter "{}", available ones are: {}'
diff --git a/upp.py b/upp.py
index 84ff015..6d8e7d0 100755
--- a/upp.py
+++ b/upp.py
@@ -15,7 +15,7 @@ def _normalize_var_path(var_path_str):
def _validate_set_pair(set_pair):
valid = False
- if '=' in set_pair and set_pair.split('=')[-1].isdigit():
+ if '=' in set_pair:
return set_pair.split('=')
else:
print("ERROR: Invalid variable assignment '{}'. ".format(set_pair),
@@ -143,7 +143,10 @@ def set(ctx, variable_path_set, write):
var_path = _normalize_var_path(var)
res = decode.get_value(input_file, var_path)
if res:
- set_pairs += [var_path + [int(val)]]
+ if (val.isdigit()):
+ set_pairs += [var_path + [int(val)]]
+ else:
+ set_pairs += [var_path + [float(val)]]
else:
print('ERROR: Incorrect variable path:', var)
return 2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment