Skip to content

Validator#2

Open
ematan wants to merge 3 commits into
apluslms:milestone0.3from
ematan:validator
Open

Validator#2
ematan wants to merge 3 commits into
apluslms:milestone0.3from
ematan:validator

Conversation

@ematan
Copy link
Copy Markdown

@ematan ematan commented Jun 12, 2018

Created validator.py and some schemas for testing purposes.

Comment thread 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
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imports are not used

Comment thread apluslms_roman/cli.py Outdated
@@ -1,23 +1,37 @@
import argparse
from os import getcwd
from os import getcwd, path
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

path is not used

Comment thread apluslms_roman/cli.py Outdated

def main():


Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unneeded newlines

Comment thread 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", [])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.")

Comment thread 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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could probably contain the result

Comment thread 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()
Copy link
Copy Markdown
Contributor

@raphendyr raphendyr Jun 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

match = prog.match(ff)
if match is not None:
  major, minor, ext = match.groups()
  ...

better?

Comment thread 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, {})
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

foo = schema_index.setdefault(...) store result in var and use it below in place of schema_index[schema].

Comment thread apluslms_roman/validator.py Outdated


#idea = { schema_name: {(major, minor): location}}
schema_index = {}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

global

Comment thread 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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread 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])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can store os.path.join(folder, ff) and then the filename doesn't need to be reconstructed later.

Comment thread 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}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Finding newest with major should be simple as:

ver = max((v for v in schems if v[0] == major), default=None)
file_ = schemas[ver]

@raphendyr
Copy link
Copy Markdown
Contributor

Files config_v1_1.yml could be apluslms_grader_v1_1.yml and index_v1_1.yml should be apluslms_index_v1_1.yml.

In addition, version could use do v1.1. It's totally fine to have multiple dots in filename :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants