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

Storage, rBoot and profile editor updates #2302

Merged
merged 44 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
1977720
Fix bash comparison
mikee47 Mar 31, 2021
f237839
Change default partition alignment to 0x1000 (was 4)
mikee47 Apr 1, 2021
936e51d
Allow floating point values with size multipliers (e.g. 1.5m), and al…
mikee47 Apr 2, 2021
bd8f9df
Change partition sort order so devices are in same order as listed
mikee47 Apr 2, 2021
e27e18a
Add `json_loads()`, `json_load()` and `json_save()` to common, create…
mikee47 Mar 30, 2021
3ef1753
Ensure option lists are presented in sorted order
mikee47 Mar 30, 2021
e682f86
Ensure selected item is visible in tree view
mikee47 Mar 30, 2021
aee9496
Update view if 'add device' is cancelled
mikee47 Mar 30, 2021
6ebe8eb
Fix edit sizing
mikee47 Mar 30, 2021
a9c691a
Add internal enumerations to global schema
mikee47 Mar 30, 2021
6360f8c
Simplify
mikee47 Mar 30, 2021
261ec65
Pad button frames out a little
mikee47 Mar 31, 2021
54270aa
Update README, add TODO
mikee47 Mar 31, 2021
e75994f
Add `HWCONFIG_BUILDSPECS`
mikee47 Mar 30, 2021
a4dc4b1
Support custom project build specs.
mikee47 Mar 31, 2021
99e8d61
TkMap manages device selection internally
mikee47 Mar 31, 2021
b7b6ade
Support build configuration
mikee47 Mar 31, 2021
b7f11ae
Tidy
mikee47 Mar 31, 2021
8dc672e
Hide inapplicable controls rather than disable them, and clear build.…
mikee47 Mar 31, 2021
dfb8b90
Size after visibility change
mikee47 Apr 1, 2021
95ddc5a
Show selected field description in status bar
mikee47 Apr 1, 2021
76077a4
Add scale controls for address/size fields
mikee47 Apr 1, 2021
702017a
unused before/after WIP
mikee47 Apr 1, 2021
73990b6
Move stuff into Field
mikee47 Apr 1, 2021
b8b05df
Refinements
mikee47 Apr 1, 2021
69a7dee
Change address/size text color if range is 0
mikee47 Apr 1, 2021
950cb90
Align sizes to 4K
mikee47 Apr 1, 2021
d79aefe
Add config `bootloader_size` field
mikee47 Apr 1, 2021
0d57c0c
Move partitions.offset into config.partition_table_offset (simplifica…
mikee47 Apr 1, 2021
4cfd90d
Bind escape/return keys
mikee47 Apr 2, 2021
7057f07
Add 'next' field
mikee47 Apr 2, 2021
f41927a
Simplify `verify_config()` and output partitions in address (map) order
mikee47 Apr 2, 2021
f5beb19
+DEBUG_VARS
mikee47 Apr 2, 2021
b802824
Revise 'array' handling, keep 'enum' as per JsonSchema spec. which MU…
mikee47 Apr 3, 2021
ae57d0d
Add ConfigVars class
mikee47 Apr 3, 2021
9c7cba7
Add browse button for string fields marked with 'filename' or 'dirnam…
mikee47 Apr 3, 2021
a48231e
Fix error when file dialog cancelled
mikee47 Apr 3, 2021
329b57f
Simplify toolbar construction
mikee47 Apr 3, 2021
ce30a87
Fix identification of core profiles
mikee47 Apr 5, 2021
e603b4a
Fix `SpiFlash::getId()` declaration (override)
mikee47 Apr 5, 2021
4585dc2
Must rebuild Storage library if partition table offset changes
mikee47 Apr 5, 2021
8dba41f
Add `PARTITION_TABLE_OFFSET` relink dependency to rboot Component
mikee47 Apr 8, 2021
999cdc3
Clean up after 'apply' to avoid empty objects or arrays.
mikee47 Apr 8, 2021
b5fb09d
Fix LGTM warning
mikee47 Apr 8, 2021
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
Prev Previous commit
Next Next commit
Add json_loads(), json_load() and json_save() to common, create…
… global config.schema object
  • Loading branch information
mikee47 committed Apr 8, 2021
commit e27e18a3bfae174ab992babf93ad17d50198683c
13 changes: 13 additions & 0 deletions Sming/Components/Storage/Tools/hwconfig/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
#

import sys, json, platform
from rjsmin import jsmin
from collections import OrderedDict

quiet = False

Expand Down Expand Up @@ -91,6 +93,17 @@ def contains_whitespace(s):
return ''.join(s.split()) != s


def json_loads(s):
return json.loads(jsmin(s), object_pairs_hook=OrderedDict)

def json_load(filename):
with open(filename) as f:
return json_loads(f.read())

def json_save(data, filename):
with open(filename, "w") as f:
json.dump(data, f, indent=4)

def to_json(obj):
return json.dumps(obj, indent=4)

Expand Down
17 changes: 13 additions & 4 deletions Sming/Components/Storage/Tools/hwconfig/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,22 @@
#

import os, partition, storage, copy
from rjsmin import jsmin
from common import *
from builtins import classmethod

HW_EXT = '.hw'

class Schema(dict):
def __init__(self, filename):
self.schema = json_load(filename)

def __getitem__(self, name):
return self.schema['definitions'][name]



schema = Schema(os.environ['HWCONFIG_SCHEMA'])

def get_config_dirs():
s = os.environ['HWCONFIG_DIRS']
dirs = s.replace(' ', ' ').split(' ')
Expand All @@ -21,7 +31,7 @@ def load_option_library():
filename = fixpath(d) + '/options.json'
if os.path.exists(filename):
with open(filename) as f:
data = json.loads(jsmin(f.read()))
data = json_loads(f.read())
library.update(data)
return library

Expand Down Expand Up @@ -82,8 +92,7 @@ def load(self, name):
"""
filename = find_config(name)
self.depends.append(filename)
with open(filename) as f:
data = json.loads(jsmin(f.read()))
data = json_load(filename)
self.parse_dict(data)

def parse_options(self, options):
Expand Down
28 changes: 7 additions & 21 deletions Sming/Components/Storage/Tools/hwconfig/editor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import argparse, os, partition, configparser, string
import argparse, os, config, partition, configparser, string
from common import *
from config import *
import tkinter as tk
Expand Down Expand Up @@ -68,9 +68,6 @@ def resolve_id(config, id):
if part is not None:
return part

def json_loads(s):
return json.loads(jsmin(s), object_pairs_hook=OrderedDict)

class Field:
"""Manages widget and associated variable
"""
Expand Down Expand Up @@ -99,7 +96,7 @@ def __init__(self, editor, objectType, dictName, obj, enumDict):
self.enumDict = enumDict
self.obj = obj
self.name = obj.name
self.schema = editor.schema[objectType]
self.schema = config.schema[objectType]
self.allow_delete = False
baseConfig = self.editor.getBaseConfig()
optionBaseConfig = self.editor.getOptionBaseConfig()
Expand Down Expand Up @@ -752,15 +749,6 @@ def select(self):
tree.selection_set(id)


class Schema(dict):
def __init__(self, filename):
with open(filename) as f:
self.schema = json.load(f, object_pairs_hook=OrderedDict)

def __getitem__(self, name):
return self.schema['definitions'][name]


class Editor:
def __init__(self, root):
root.title(app_name)
Expand All @@ -774,8 +762,6 @@ def __init__(self, root):
def initialise(self):
self.main.option_add('*tearOff', False)

self.schema = Schema(os.environ['HWCONFIG_SCHEMA'])

hwFilter = [('Hardware Profiles', '*' + HW_EXT)]

# Menus
Expand Down Expand Up @@ -803,8 +789,7 @@ def fileSave():
ext = os.path.splitext(filename)[1]
if ext != HW_EXT:
filename += HW_EXT
with open(filename, "w") as f:
json.dump(self.json, f, indent=4)
json_save(self.json, filename)

# Toolbar
toolbar = ttk.Frame(self.main)
Expand Down Expand Up @@ -939,16 +924,17 @@ def verify_config(self, json_config):

def set_json(self, json_config):
# Keep output order consistent
self.json = {}
for k in self.schema['Config']['properties'].keys():
self.json = OrderedDict()
for k in config.schema['Config']['properties'].keys():
if k in json_config:
self.json[k] = json_config[k]

def reset(self):
self.tree.clear()
self.map.clear()
self.status.set('')
self.json = {"name": "New Profile"}
self.json = OrderedDict()
self.json['name'] = 'New Profile'
self.json['base_config'] = 'standard'
self.reload()
self.updateWindowTitle()
Expand Down
7 changes: 3 additions & 4 deletions Sming/Components/Storage/Tools/hwconfig/hwconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import common, argparse, os, partition
from common import *
from config import Config
from config import schema as config_schema

def openOutput(path):
if path == '-':
Expand All @@ -24,10 +25,8 @@ def handle_validate(args, config, part):
# Validate resulting hardware configuration against schema
try:
from jsonschema import Draft7Validator
inst = json.loads(config.to_json())
with open(os.environ['HWCONFIG_SCHEMA']) as f:
schema = json.load(f)
v = Draft7Validator(schema)
inst = json_loads(config.to_json())
v = Draft7Validator(config_schema)
errors = sorted(v.iter_errors(inst), key=lambda e: e.path)
if errors != []:
for e in errors:
Expand Down