Skip to content

Validator#2

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

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

Conversation

@ematan
Copy link

@ematan ematan commented Jun 12, 2018

Created validator.py and some schemas for testing purposes.

from os import getcwd, path
from os.path import abspath, expanduser, expandvars
from sys import exit
from sys import exit, stderr, modules
Copy link
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

@@ -1,23 +1,37 @@
import argparse
from os import getcwd
from os import getcwd, path
Copy link
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


def main():


Copy link
Contributor

Choose a reason for hiding this comment

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

unneeded newlines


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

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
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

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
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?

logger.debug(" File-------------%s", ff)
if prog.match(ff) is not None:
found = prog.match(ff).groups()
schema_index.setdefault(schema, {})
Copy link
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].



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

Choose a reason for hiding this comment

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

global

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

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

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
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
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