Conversation
apluslms_roman/cli.py
Outdated
| from os import getcwd, path | ||
| from os.path import abspath, expanduser, expandvars | ||
| from sys import exit | ||
| from sys import exit, stderr, modules |
apluslms_roman/cli.py
Outdated
| @@ -1,23 +1,37 @@ | |||
| import argparse | |||
| from os import getcwd | |||
| from os import getcwd, path | |||
apluslms_roman/cli.py
Outdated
|
|
||
| def main(): | ||
|
|
||
|
|
apluslms_roman/validator.py
Outdated
|
|
||
| #mystinen lista schema directoryja - course.yamlissa jossain kentässä, joka sijaitsee käyttäjän paketin juuressa | ||
| def get_folders(config): | ||
| folders = config.__config__.get("custom_schema_locations", []) |
There was a problem hiding this comment.
Key schema_paths should be semantically better. In addition, it should be validated that it's a list.
if not isinstance(folders, list):
raise ValueError("Invalid type for 'schema_path' in config. Expected a llist.")
apluslms_roman/validator.py
Outdated
| schema_path = os.path.join(ext[0], schema_fullname) | ||
| logger.info(" Starting validation of %s with %s", filename, schema_fullname) | ||
| result = self.assert_valid(schema_path, filename) | ||
| logger.info(" Validation done", filename) |
There was a problem hiding this comment.
could probably contain the result
apluslms_roman/validator.py
Outdated
| for ff in os.listdir(folder): | ||
| logger.debug(" File-------------%s", ff) | ||
| if prog.match(ff) is not None: | ||
| found = prog.match(ff).groups() |
There was a problem hiding this comment.
match = prog.match(ff)
if match is not None:
major, minor, ext = match.groups()
...
better?
apluslms_roman/validator.py
Outdated
| logger.debug(" File-------------%s", ff) | ||
| if prog.match(ff) is not None: | ||
| found = prog.match(ff).groups() | ||
| schema_index.setdefault(schema, {}) |
There was a problem hiding this comment.
foo = schema_index.setdefault(...) store result in var and use it below in place of schema_index[schema].
apluslms_roman/validator.py
Outdated
|
|
||
|
|
||
| #idea = { schema_name: {(major, minor): location}} | ||
| schema_index = {} |
apluslms_roman/validator.py
Outdated
| logger.info(" Locating all valid schemas...") | ||
| self.find_all_matches(schema) | ||
| logger.info(" Locating matching version v%d...", major) | ||
| serial, ext = self.find_newest(schema, major, minor) |
There was a problem hiding this comment.
this is required only when minor is not known version: '3'. If minor is known, then test (major, minor) in schema_index[schema] is sufficient.
apluslms_roman/validator.py
Outdated
| logger.debug(" Index-------------%s", schema_index) | ||
| current = schema_index[schema].setdefault((int(found[0]), int(found[1])), None) | ||
| if current is None: | ||
| schema_index[schema][int(found[0]), int(found[1])] = (folder, found[2]) |
There was a problem hiding this comment.
You can store os.path.join(folder, ff) and then the filename doesn't need to be reconstructed later.
apluslms_roman/validator.py
Outdated
| return None | ||
|
|
||
| #filter(_ <= major.minor) and reduce(max(_,_)) | ||
| i = {k:v for k, v in schemas.items() if k[0]<major or k[0]==major and k[1]<=minor} |
There was a problem hiding this comment.
Finding newest with major should be simple as:
ver = max((v for v in schems if v[0] == major), default=None)
file_ = schemas[ver]
|
Files In addition, version could use do |
Created validator.py and some schemas for testing purposes.