예제 #1
0
파일: cheat.py 프로젝트: fenollp/kaneton
def                     extract():
  student = None
  base = None

  # display a message.
  env.display(env.HEADER_OK,
              "extracting the students' snapshots",
              env.OPTION_NONE)

  # extract the history snapshots.
  for student in g_history:
    # message.
    env.display(env.HEADER_OK,
                "  " + student["name"],
                env.OPTION_NONE)

    env.mkdir(student["sources"], env.OPTION_NONE)

    if env.path(student["snapshot"], env.OPTION_EXIST):
      env.unpack(student["snapshot"],
                 student["sources"],
                 env.OPTION_QUIET)
    else:
      env.mkdir(student["sources"] + "/kaneton/", env.OPTION_NONE)

    # verify that the extracted snapshot has created a 'kaneton/' directory.
    if not (env.path(student["sources"] + "/kaneton/",
                     env.OPTION_EXIST)):
      env.display(env.HEADER_ERROR,
                  "the extracted student snapshot '" + student["name"] +
                  "' does not contain a 'kaneton/' directory",
                  env.OPTION_NONE)

    if len(env.list(student["sources"],
                    env.OPTION_FILE | env.OPTION_DIRECTORY)) != 1:
      env.display(env.HEADER_ERROR,
                  "the extracted student snapshot '" + student["name"] +
                  "' contains more than just the 'kaneton/' directory",
                  env.OPTION_NONE)

  # extract the bases.
  if g_base:
    env.unpack(g_base["snapshot"],
               g_base["path"],
                 env.OPTION_QUIET)

    # verify that the extracted snapshot has created a 'kaneton/' directory.
    if not (env.path(g_base["path"] + "/kaneton/",
                     env.OPTION_EXIST)):
      env.display(env.HEADER_ERROR,
                  "the extracted base snapshot '" + g_base["snapshot"] +
                  "' does not contain a 'kaneton/' directory",
                  env.OPTION_NONE)

    if len(env.list(g_base["path"],
                    env.OPTION_FILE | env.OPTION_DIRECTORY)) != 1:
      env.display(env.HEADER_ERROR,
                  "the extracted base snapshot '" + g_base["snapshot"] +
                  "' contains more than just the 'kaneton/' directory",
                  env.OPTION_NONE)
예제 #2
0
파일: cheat.py 프로젝트: fenollp/kaneton
def             walk(snapshot, base, directory):
  student = None
  reference = None
  directories = None
  files = None
  entry = None

  # adjust the directory:
  if not directory:
    directory = ""

  # retrieve the list of directories and files.
  files = env.list(snapshot + "/" + directory,
                   env.OPTION_FILE | env.OPTION_HIDDEN)

  # try to reduce every file
  for entry in files:
    reduce(snapshot + "/" + directory + "/" + entry,
           base + "/" + directory + "/" + entry)

  # keep walking through the hierarchy
  directories = env.list(snapshot + "/" + directory,
                         env.OPTION_DIRECTORY | env.OPTION_HIDDEN)

  for entry in directories:
    walk(snapshot, base, directory + "/" + entry)
예제 #3
0
파일: cheat.py 프로젝트: bbycode/tinyOs
def walk(snapshot, base, directory):
    student = None
    reference = None
    directories = None
    files = None
    entry = None

    # adjust the directory:
    if not directory:
        directory = ""

    # retrieve the list of directories and files.
    files = env.list(snapshot + "/" + directory,
                     env.OPTION_FILE | env.OPTION_HIDDEN)

    # try to reduce every file
    for entry in files:
        reduce(snapshot + "/" + directory + "/" + entry,
               base + "/" + directory + "/" + entry)

    # keep walking through the hierarchy
    directories = env.list(snapshot + "/" + directory,
                           env.OPTION_DIRECTORY | env.OPTION_HIDDEN)

    for entry in directories:
        walk(snapshot, base, directory + "/" + entry)
예제 #4
0
파일: cheat.py 프로젝트: bbycode/tinyOs
def extract():
    student = None
    base = None

    # display a message.
    env.display(env.HEADER_OK, "extracting the students' snapshots",
                env.OPTION_NONE)

    # extract the history snapshots.
    for student in g_history:
        # message.
        env.display(env.HEADER_OK, "  " + student["name"], env.OPTION_NONE)

        env.mkdir(student["sources"], env.OPTION_NONE)

        if env.path(student["snapshot"], env.OPTION_EXIST):
            env.unpack(student["snapshot"], student["sources"],
                       env.OPTION_QUIET)
        else:
            env.mkdir(student["sources"] + "/kaneton/", env.OPTION_NONE)

        # verify that the extracted snapshot has created a 'kaneton/' directory.
        if not (env.path(student["sources"] + "/kaneton/", env.OPTION_EXIST)):
            env.display(
                env.HEADER_ERROR, "the extracted student snapshot '" +
                student["name"] + "' does not contain a 'kaneton/' directory",
                env.OPTION_NONE)

        if len(
                env.list(student["sources"],
                         env.OPTION_FILE | env.OPTION_DIRECTORY)) != 1:
            env.display(
                env.HEADER_ERROR,
                "the extracted student snapshot '" + student["name"] +
                "' contains more than just the 'kaneton/' directory",
                env.OPTION_NONE)

    # extract the bases.
    if g_base:
        env.unpack(g_base["snapshot"], g_base["path"], env.OPTION_QUIET)

        # verify that the extracted snapshot has created a 'kaneton/' directory.
        if not (env.path(g_base["path"] + "/kaneton/", env.OPTION_EXIST)):
            env.display(
                env.HEADER_ERROR,
                "the extracted base snapshot '" + g_base["snapshot"] +
                "' does not contain a 'kaneton/' directory", env.OPTION_NONE)

        if len(env.list(g_base["path"],
                        env.OPTION_FILE | env.OPTION_DIRECTORY)) != 1:
            env.display(
                env.HEADER_ERROR,
                "the extracted base snapshot '" + g_base["snapshot"] +
                "' contains more than just the 'kaneton/' directory",
                env.OPTION_NONE)
예제 #5
0
파일: export.py 프로젝트: Jupotter/kaneton
def main():
  global g_modules
  global g_action_data
  global g_export_dir

  if (len(sys.argv) != 2):
    env.display(env.HEADER_ERROR, "usage: export.py [behaviour]",
                env.OPTION_NONE)
    env.display(env.HEADER_NONE, "",
                env.OPTION_NONE)
    env.display(env.HEADER_ERROR, "behaviours:",
                env.OPTION_NONE)
    for i in env.list(env._EXPORT_DIR_ + "/behaviours", env.OPTION_FILE):
      env.display(env.HEADER_ERROR, "  " + i[:-4], env.OPTION_NONE)
    return 1

  modules_load()

  work_dir = env.temporary(env.OPTION_DIRECTORY)

  g_export_dir =  work_dir + "/kaneton"

  env.display(env.HEADER_OK, 'exporting to ' + g_export_dir, env.OPTION_NONE)

  env.display(env.HEADER_OK, 'running export actions', env.OPTION_NONE)

  parse_data_file("behaviours/" + sys.argv[1])

  env.display(env.HEADER_OK, 'cleaning temporary directory', env.OPTION_NONE)
  env.remove(work_dir, env.OPTION_NONE)

  env.display(env.HEADER_OK, 'export finished', env.OPTION_NONE)
예제 #6
0
파일: export.py 프로젝트: bbycode/tinyOs
def main():
    global g_modules
    global g_action_data
    global g_export_dir

    if (len(sys.argv) != 2):
        env.display(env.HEADER_ERROR, "usage: export.py [behaviour]",
                    env.OPTION_NONE)
        env.display(env.HEADER_NONE, "", env.OPTION_NONE)
        env.display(env.HEADER_ERROR, "behaviours:", env.OPTION_NONE)
        for i in env.list(env._EXPORT_DIR_ + "/behaviours", env.OPTION_FILE):
            env.display(env.HEADER_ERROR, "  " + i[:-4], env.OPTION_NONE)
        return 1

    modules_load()

    work_dir = env.temporary(env.OPTION_DIRECTORY)

    g_export_dir = work_dir + "/kaneton"

    env.display(env.HEADER_OK, 'exporting to ' + g_export_dir, env.OPTION_NONE)

    env.display(env.HEADER_OK, 'running export actions', env.OPTION_NONE)

    parse_data_file("behaviours/" + sys.argv[1])

    env.display(env.HEADER_OK, 'cleaning temporary directory', env.OPTION_NONE)
    env.remove(work_dir, env.OPTION_NONE)

    env.display(env.HEADER_OK, 'export finished', env.OPTION_NONE)
예제 #7
0
def			load(directories, pattern, option):
  content = ""

  directory = None
  includes = None
  include = None
  handle = None
  files = None
  line = None
  file = None
  cwd = None

  for directory in directories:
    files = env.list(directory, env.OPTION_FILE)

    for file in files:
      if not re.match(pattern, file):
        continue

      content += env.pull(directory + "/" + file, env.OPTION_NONE) + "\n"

      if (option & OPTION_COMMENTS):
        content = comments(content)

      if (option & OPTION_INCLUDES):
        includes = re.findall("("					\
                                "^"					\
                                "include"				\
                                "[ \t]*"				\
                                "(.*)"					\
                                "\n"					\
                              ")", content, re.MULTILINE);

        for include in includes:
          content = content.replace(include[0],
                                    load([env.path(directory + "/" +
                                                   include[1],
                                                   env.OPTION_DIRECTORY)],
                                         "^" + env.path(directory +
                                                        "/" +
                                                        include[1],
                                                   env.OPTION_FILE) +
                                         "$",
                                         OPTION_COMMENTS | OPTION_INCLUDES))

  return content
예제 #8
0
파일: export.py 프로젝트: Jupotter/kaneton
def modules_load():
  global g_modules

  env.display(env.HEADER_OK, 'loading action modules', env.OPTION_NONE)
  if (env.path(sys.argv[0], env.OPTION_DIRECTORY) == ""):
    moduledir = './modules'
  else:
    moduledir = env.path(sys.argv[0], env.OPTION_DIRECTORY) + '/modules'
  sys.path.append(moduledir)
  for i in env.list(moduledir, env.OPTION_FILE):
    if i.endswith('.py'):
      mod = __import__(i[:-3])
      try:
        init_str = mod.module_init()
      except AttributeError:
        sys.stderr.write('error: The module file ' + i +
                         ' is missing the module_init function\n')
        sys.exit(1)
      g_modules[init_str[0]] = mod
      g_modules_parameters[init_str[0]] = init_str
      env.display(env.HEADER_OK, "  loaded module " + init_str[0], env.OPTION_NONE)
예제 #9
0
파일: export.py 프로젝트: bbycode/tinyOs
def modules_load():
    global g_modules

    env.display(env.HEADER_OK, 'loading action modules', env.OPTION_NONE)
    if (env.path(sys.argv[0], env.OPTION_DIRECTORY) == ""):
        moduledir = './modules'
    else:
        moduledir = env.path(sys.argv[0], env.OPTION_DIRECTORY) + '/modules'
    sys.path.append(moduledir)
    for i in env.list(moduledir, env.OPTION_FILE):
        if i.endswith('.py'):
            mod = __import__(i[:-3])
            try:
                init_str = mod.module_init()
            except AttributeError:
                sys.stderr.write('error: The module file ' + i +
                                 ' is missing the module_init function\n')
                sys.exit(1)
            g_modules[init_str[0]] = mod
            g_modules_parameters[init_str[0]] = init_str
            env.display(env.HEADER_OK, "  loaded module " + init_str[0],
                        env.OPTION_NONE)
예제 #10
0
파일: cheat.py 프로젝트: fenollp/kaneton
def                     prepare():
  global g_history
  global g_directory
  global g_output
  global g_base
  years = None
  year = None
  stages = None
  stage = None
  base = None

  # a message.
  env.display(env.HEADER_OK,
              "preparing the verification process",
              env.OPTION_NONE)

  # create a temporary directory for holding unpacked snapshots.
  g_directory = env.temporary(env.OPTION_DIRECTORY)

  # set the output file path.
  g_output = env._HISTORY_DIR_ + "/" + g_school + "/" + g_year + "/" +  \
             g_stage + ".html"

  # build the CTC tool
  env.launch(env._CTC_DIR_ + "/Makefile", "", env.OPTION_QUIET)

  # look for a base snapshot.
  if env.path(env._HISTORY_DIR_ + "/" + g_school + "/" + g_year +       \
              "/snapshot.tar.bz2", env.OPTION_EXIST):
    g_base = { "snapshot": env._HISTORY_DIR_ + "/" + g_school + "/" + \
                 g_year + "/snapshot.tar.bz2",
               "path": g_directory + "/snapshot" }

    env.mkdir(g_base["path"], env.OPTION_NONE)
  else:
    g_base = None

  # retreive the list of other snapshots to compare. neighbours are the
  # students in the same year while alumni are old students.
  years = sorted(env.list(env._HISTORY_DIR_ + "/" + g_school,
                          env.OPTION_DIRECTORY))

  for year in years:
    # skip the younger works.
    if year > g_year:
      continue

    # for the work from the same year, simply compare the same stages.
    if year == g_year:
      # retrieve the students in this year.
      students = sorted(env.list(env._HISTORY_DIR_ + "/" +              \
                                   g_school + "/" + year,
                                 env.OPTION_DIRECTORY))

      # for every student.
      for student in students:
        # add the student to the list.
        g_history += [                                                  \
          {
            "name": year + "/" + student + "/" + g_stage,
            "year": year,
            "student": student,
            "stage": g_stage,
            "people": transform(env.pull(env._HISTORY_DIR_ + "/" +      \
                                         g_school + "/" + year + "/" +  \
                                         student + "/people",
                                         env.OPTION_NONE)),
            "snapshot": env._HISTORY_DIR_ + "/" + g_school + "/" + year + "/" +
                        student + "/sources/" + g_stage + ".tar.bz2",
            "sources": g_directory + "/" + year + "/" +                 \
                       student + "/" + g_stage,
            "fingerprint": g_directory + "/" + year + "/" + student + "/" +
                           g_stage + ".ctf",
            "base": base,
            "database": g_directory + "/" + year + "/" + student + "/tokens",
            "trace": g_directory + "/" + year + "/" + student + "/trace"
          } ]

    # for older work, take the most recent work from every older student.
# XXX this feature has been disabled because it generates too much code to process.
    if (year < g_year) and (0 == 1):
      # retrieve the students in this year.
      students = sorted(env.list(env._HISTORY_DIR_ + "/" + g_school + "/" + year,
                                 env.OPTION_DIRECTORY))

      # for every student.
      for student in students:
        # find the works for this student.
        stages = sorted(env.list(env._HISTORY_DIR_ + "/" + g_school + "/" +
                                 year + "/" + student + "/sources/",
                                 env.OPTION_FILE))

        # ignore students that skipped the project.
        if len(stages) == 0:
          continue

        # find the most recent work.
        match = re.match("^(.*)\.tar\.bz2$", stages[len(stages) - 1])

        if not match:
          continue

        # retrieve the stage name.
        stage = match.group(1)

        # add the last student's work to the list.
        g_history += [                                                  \
          {
            "name": year + "/" + student + "/" + stage,
            "year": year,
            "student": student,
            "stage": stage,
            "people": transform(env.pull(env._HISTORY_DIR_ + "/" +      \
                                         g_school + "/" + year + "/" +  \
                                         student + "/people",
                                         env.OPTION_NONE)),
            "snapshot": env._HISTORY_DIR_ + "/" + g_school + "/" + year + "/" +
                        student + "/sources/" + stage + ".tar.bz2",
            "sources": g_directory + "/" + year + "/" + student + "/" + stage,
            "fingerprint": g_directory + "/" + year + "/" + student + "/" +
                           stage + ".ctf",
            "base": base
          } ]
예제 #11
0
"""
Production Settings for Heroku
"""

import env

# If using in your own project, update the project namespace below
from django_project.settings import *

env = environ.Env(
    # set casting, default value
    DEBUG=(bool, False))

# False if not in os.environ
DEBUG = env('DEBUG')

# Raises django's ImproperlyConfigured exception if SECRET_KEY not in os.environ
SECRET_KEY = env('SECRET_KEY')

ALLOWED_HOSTS = env.list('ALLOWED_HOSTS')

# Parse database connection url strings like psql://user:[email protected]:8458/db
DATABASES = {
    # read os.environ['DATABASE_URL'] and raises ImproperlyConfigured exception if not found
    'default': env.db(),
}
예제 #12
0
def                     school():
  code = None
  students = None
  student = None
  people = None
  members = None
  member = None
  match = None
  components = None
  school = None
  year = None
  group = None
  name = None
  path = None
  capability = None

  # display.
  env.display(env.HEADER_OK,
              "generating students' capabilities for the school '" +    \
                g_path + "'",
              env.OPTION_NONE)

  # retrieve the server's code.
  code = ktp.code.Load(env._TEST_STORE_CODE_DIR_ + "/server" +          \
                         ktp.code.Extension)

  # extract the components from the path.
  components = g_path.strip("/").split("/")

  # compute the school and year.
  school = components[0]
  year = components[1]

  # retrieve the list of students.
  students = env.list(env._HISTORY_DIR_ + "/" + g_path,
                      env.OPTION_DIRECTORY)

  # for each student, extract the information from the
  # 'people' file.
  for student in students:
    # display.
    env.display(env.HEADER_OK,
                "  " + student,
                env.OPTION_NONE)

    # complete the attributes with the group name.
    group = student
    name = school + "::" + year + "::" + group

    # read the 'people' file.
    people = env.pull(env._HISTORY_DIR_ + "/" + g_path + "/" +
                      student + "/people",
                      env.OPTION_NONE).strip("\n").split("\n")

    # initialize the members list.
    members = []

    # for every member, extract the first email email.
    for member in people:
      # apply a regexp to locate the elements.
      match = re.match("^(.+) <(.+)>$", member)

      if not match:
        env.display(env.HEADER_ERROR,
                    "  unable to extract the name and email from the "
                    "student '" + student + "'",
                    env.OPTION_NONE)
        continue
      else:
        # register the member.
        members += [ { "name": match.group(1),
                       "email": match.group(2),
                       "login": match.group(1).lower().replace(" ", ".") } ]

    # compute the file name.
    path = env._TEST_STORE_CAPABILITY_DIR_ + "/" +                      \
      name + ktp.capability.Extension

    # create the capability.
    capability = ktp.capability.Create(code,
                                       name,
                                       ktp.capability.TypeGroup,
                                       { "school": school,
                                         "year": year,
                                         "group": group },
                                       members)

    # store it.
    ktp.capability.Store(path,
                         capability)

    # go through the list of members attached to this group.
    for member in members:
      # generate a student name.
      name = school+ "::" + year + "::" + group + "::" + member["login"]

      # compute the file name.
      path = env._TEST_STORE_CAPABILITY_DIR_ + "/" +                    \
        name + ktp.capability.Extension

      # create a specific capability for the member.
      capability = ktp.capability.Create(code,
                                         name,
                                         ktp.capability.TypeStudent,
                                         { "school": school,
                                           "year": year,
                                           "group": group,
                                           "student": member["login"] },
                                         [ { "name": member["name"],
                                             "email": member["email"],
                                             "login": member["login"] } ])

      # store it.
      ktp.capability.Store(path,
                           capability)

  # display.
  env.display(env.HEADER_OK,
              "the school student capabilities have been generated " +  \
                "succesfully",
              env.OPTION_NONE)
예제 #13
0
파일: cheat.py 프로젝트: bbycode/tinyOs
def prepare():
    global g_history
    global g_directory
    global g_output
    global g_base
    years = None
    year = None
    stages = None
    stage = None
    base = None

    # a message.
    env.display(env.HEADER_OK, "preparing the verification process",
                env.OPTION_NONE)

    # create a temporary directory for holding unpacked snapshots.
    g_directory = env.temporary(env.OPTION_DIRECTORY)

    # set the output file path.
    g_output = env._HISTORY_DIR_ + "/" + g_school + "/" + g_year + "/" +  \
               g_stage + ".html"

    # build the CTC tool
    env.launch(env._CTC_DIR_ + "/Makefile", "", env.OPTION_QUIET)

    # look for a base snapshot.
    if env.path(env._HISTORY_DIR_ + "/" + g_school + "/" + g_year +       \
                "/snapshot.tar.bz2", env.OPTION_EXIST):
        g_base = { "snapshot": env._HISTORY_DIR_ + "/" + g_school + "/" + \
                     g_year + "/snapshot.tar.bz2",
                   "path": g_directory + "/snapshot" }

        env.mkdir(g_base["path"], env.OPTION_NONE)
    else:
        g_base = None

    # retreive the list of other snapshots to compare. neighbours are the
    # students in the same year while alumni are old students.
    years = sorted(
        env.list(env._HISTORY_DIR_ + "/" + g_school, env.OPTION_DIRECTORY))

    for year in years:
        # skip the younger works.
        if year > g_year:
            continue

        # for the work from the same year, simply compare the same stages.
        if year == g_year:
            # retrieve the students in this year.
            students = sorted(env.list(env._HISTORY_DIR_ + "/" +              \
                                         g_school + "/" + year,
                                       env.OPTION_DIRECTORY))

            # for every student.
            for student in students:
                # add the student to the list.
                g_history += [                                                  \
                  {
                    "name": year + "/" + student + "/" + g_stage,
                    "year": year,
                    "student": student,
                    "stage": g_stage,
                    "people": transform(env.pull(env._HISTORY_DIR_ + "/" +      \
                                                 g_school + "/" + year + "/" +  \
                                                 student + "/people",
                                                 env.OPTION_NONE)),
                    "snapshot": env._HISTORY_DIR_ + "/" + g_school + "/" + year + "/" +
                                student + "/sources/" + g_stage + ".tar.bz2",
                    "sources": g_directory + "/" + year + "/" +                 \
                               student + "/" + g_stage,
                    "fingerprint": g_directory + "/" + year + "/" + student + "/" +
                                   g_stage + ".ctf",
                    "base": base,
                    "database": g_directory + "/" + year + "/" + student + "/tokens",
                    "trace": g_directory + "/" + year + "/" + student + "/trace"
                  } ]

        # for older work, take the most recent work from every older student.
# XXX this feature has been disabled because it generates too much code to process.
        if (year < g_year) and (0 == 1):
            # retrieve the students in this year.
            students = sorted(
                env.list(env._HISTORY_DIR_ + "/" + g_school + "/" + year,
                         env.OPTION_DIRECTORY))

            # for every student.
            for student in students:
                # find the works for this student.
                stages = sorted(
                    env.list(
                        env._HISTORY_DIR_ + "/" + g_school + "/" + year + "/" +
                        student + "/sources/", env.OPTION_FILE))

                # ignore students that skipped the project.
                if len(stages) == 0:
                    continue

                # find the most recent work.
                match = re.match("^(.*)\.tar\.bz2$", stages[len(stages) - 1])

                if not match:
                    continue

                # retrieve the stage name.
                stage = match.group(1)

                # add the last student's work to the list.
                g_history += [                                                  \
                  {
                    "name": year + "/" + student + "/" + stage,
                    "year": year,
                    "student": student,
                    "stage": stage,
                    "people": transform(env.pull(env._HISTORY_DIR_ + "/" +      \
                                                 g_school + "/" + year + "/" +  \
                                                 student + "/people",
                                                 env.OPTION_NONE)),
                    "snapshot": env._HISTORY_DIR_ + "/" + g_school + "/" + year + "/" +
                                student + "/sources/" + stage + ".tar.bz2",
                    "sources": g_directory + "/" + year + "/" + student + "/" + stage,
                    "fingerprint": g_directory + "/" + year + "/" + student + "/" +
                                   stage + ".ctf",
                    "base": base
                  } ]
예제 #14
0
파일: database.py 프로젝트: fenollp/kaneton
def                     school():
  students = None
  student = None
  school = None
  group = None
  name = None
  configuration = None
  name = None
  capability = None
  database = None

  # display.
  env.display(env.HEADER_OK,
              "generating students' databases for the school '" +       \
                g_path + "'",
              env.OPTION_NONE)

  # retrieve the list of students.
  students = env.list(env._HISTORY_DIR_ + "/" + g_path,
                      env.OPTION_DIRECTORY)

  # for each student.
  for student in students:
    # display.
    env.display(env.HEADER_OK,
                "  " + student,
                env.OPTION_NONE)

    # retrieve the components.
    components = g_path.strip("/").split("/")

    # compute the school, year and group.
    school = components[0]
    year = components[1]
    group = student

    # compute the group capability/database name.
    name = school + "::" + year + "::" + group

    # compute the file name.
    path = env._TEST_STORE_DATABASE_DIR_ + "/" + name + ktp.database.Extension

    # load the group capability.
    capability = ktp.capability.Load(env._TEST_STORE_CAPABILITY_DIR_ +  \
                                       "/" + name + ktp.capability.Extension)

    # load the configuration.
    configuration = ktp.configuration.Load(env._TEST_CONFIGURATION_DIR_ + \
                                             "/" + school + "::" +        \
                                             year + "#group" +            \
                                             ktp.configuration.Extension)

    # generate the database.
    database = ktp.database.Generate(configuration)

    # store the database.
    ktp.database.Store(database, path)

    # go through the list of members attached to this group.
    for member in capability["members"]:
      # compute the name.
      name = school + "::" + year + "::" + group + "::" + member["login"]

      # compute the file name.
      path = env._TEST_STORE_DATABASE_DIR_ + "/" +                      \
        name + ktp.database.Extension

      # load the configuration.
      configuration = ktp.configuration.Load(env._TEST_CONFIGURATION_DIR_ + \
                                               "/" + school + "::" +        \
                                               year + "#student" +          \
                                               ktp.configuration.Extension)

      # generate the database.
      database = ktp.database.Generate(configuration)

      # store the database.
      ktp.database.Store(database, path)

  # display message.
  env.display(env.HEADER_OK,
              "the school's group capabilities have been generated " +  \
                "succesfully",
              env.OPTION_NONE)
예제 #15
0
def school():
    students = None
    student = None
    school = None
    group = None
    name = None
    configuration = None
    name = None
    capability = None
    database = None

    # display.
    env.display(env.HEADER_OK,
                "generating students' databases for the school '" +       \
                  g_path + "'",
                env.OPTION_NONE)

    # retrieve the list of students.
    students = env.list(env._HISTORY_DIR_ + "/" + g_path, env.OPTION_DIRECTORY)

    # for each student.
    for student in students:
        # display.
        env.display(env.HEADER_OK, "  " + student, env.OPTION_NONE)

        # retrieve the components.
        components = g_path.strip("/").split("/")

        # compute the school, year and group.
        school = components[0]
        year = components[1]
        group = student

        # compute the group capability/database name.
        name = school + "::" + year + "::" + group

        # compute the file name.
        path = env._TEST_STORE_DATABASE_DIR_ + "/" + name + ktp.database.Extension

        # load the group capability.
        capability = ktp.capability.Load(env._TEST_STORE_CAPABILITY_DIR_ +  \
                                           "/" + name + ktp.capability.Extension)

        # load the configuration.
        configuration = ktp.configuration.Load(env._TEST_CONFIGURATION_DIR_ + \
                                                 "/" + school + "::" +        \
                                                 year + "#group" +            \
                                                 ktp.configuration.Extension)

        # generate the database.
        database = ktp.database.Generate(configuration)

        # store the database.
        ktp.database.Store(database, path)

        # go through the list of members attached to this group.
        for member in capability["members"]:
            # compute the name.
            name = school + "::" + year + "::" + group + "::" + member["login"]

            # compute the file name.
            path = env._TEST_STORE_DATABASE_DIR_ + "/" +                      \
              name + ktp.database.Extension

            # load the configuration.
            configuration = ktp.configuration.Load(env._TEST_CONFIGURATION_DIR_ + \
                                                     "/" + school + "::" +        \
                                                     year + "#student" +          \
                                                     ktp.configuration.Extension)

            # generate the database.
            database = ktp.database.Generate(configuration)

            # store the database.
            ktp.database.Store(database, path)

    # display message.
    env.display(env.HEADER_OK,
                "the school's group capabilities have been generated " +  \
                  "succesfully",
                env.OPTION_NONE)
예제 #16
0
def school():
    code = None
    students = None
    student = None
    people = None
    members = None
    member = None
    match = None
    components = None
    school = None
    year = None
    group = None
    name = None
    path = None
    capability = None

    # display.
    env.display(env.HEADER_OK,
                "generating students' capabilities for the school '" +    \
                  g_path + "'",
                env.OPTION_NONE)

    # retrieve the server's code.
    code = ktp.code.Load(env._TEST_STORE_CODE_DIR_ + "/server" +          \
                           ktp.code.Extension)

    # extract the components from the path.
    components = g_path.strip("/").split("/")

    # compute the school and year.
    school = components[0]
    year = components[1]

    # retrieve the list of students.
    students = env.list(env._HISTORY_DIR_ + "/" + g_path, env.OPTION_DIRECTORY)

    # for each student, extract the information from the
    # 'people' file.
    for student in students:
        # display.
        env.display(env.HEADER_OK, "  " + student, env.OPTION_NONE)

        # complete the attributes with the group name.
        group = student
        name = school + "::" + year + "::" + group

        # read the 'people' file.
        people = env.pull(
            env._HISTORY_DIR_ + "/" + g_path + "/" + student + "/people",
            env.OPTION_NONE).strip("\n").split("\n")

        # initialize the members list.
        members = []

        # for every member, extract the first email email.
        for member in people:
            # apply a regexp to locate the elements.
            match = re.match("^(.+) <(.+)>$", member)

            if not match:
                env.display(
                    env.HEADER_ERROR,
                    "  unable to extract the name and email from the "
                    "student '" + student + "'", env.OPTION_NONE)
                continue
            else:
                # register the member.
                members += [{
                    "name": match.group(1),
                    "email": match.group(2),
                    "login": match.group(1).lower().replace(" ", ".")
                }]

        # compute the file name.
        path = env._TEST_STORE_CAPABILITY_DIR_ + "/" +                      \
          name + ktp.capability.Extension

        # create the capability.
        capability = ktp.capability.Create(code, name,
                                           ktp.capability.TypeGroup, {
                                               "school": school,
                                               "year": year,
                                               "group": group
                                           }, members)

        # store it.
        ktp.capability.Store(path, capability)

        # go through the list of members attached to this group.
        for member in members:
            # generate a student name.
            name = school + "::" + year + "::" + group + "::" + member["login"]

            # compute the file name.
            path = env._TEST_STORE_CAPABILITY_DIR_ + "/" +                    \
              name + ktp.capability.Extension

            # create a specific capability for the member.
            capability = ktp.capability.Create(
                code, name, ktp.capability.TypeStudent, {
                    "school": school,
                    "year": year,
                    "group": group,
                    "student": member["login"]
                }, [{
                    "name": member["name"],
                    "email": member["email"],
                    "login": member["login"]
                }])

            # store it.
            ktp.capability.Store(path, capability)

    # display.
    env.display(env.HEADER_OK,
                "the school student capabilities have been generated " +  \
                  "succesfully",
                env.OPTION_NONE)