コード例 #1
0
ファイル: cheat.py プロジェクト: fenollp/kaneton
def             reduce(student, reference):
  differences = None
  contents = None
  differ = None
  status = None
  line = None
  r = None
  s = None

  if not ((env.path(reference, env.OPTION_EXIST)) and                   \
          (env.path(reference, env.OPTION_FILE))):
    return

  # load the reference and student files.
  r = env.pull(reference, env.OPTION_NONE).split("\n")
  s = env.pull(student, env.OPTION_NONE).split("\n")

  # build an differ object.
  differ = difflib.Differ()

  # look for the differences.
  differences = differ.compare(r, s)

  # only keep the added lines.
  status = STATUS_EQUAL

  contents=""

  # for each line.
  for line in differences:
    if line[len(line) - 1] == "\n":
      line = line[:len(line) - 1]

    # we insert a CTC-GATE token so that the CTC tool does not match code
    # regions including such a token.
    # this is done because code has been removed. therefore, a match has
    # no sense here.
    if (line[0] == STATUS_INSERT) and (line[0] != status):
      contents += "_____ctc_gate_____\n";

    status = line[0]

    # add the line to the final file since we only keep added stuff.
    if line[0] == STATUS_INSERT:
      contents += line[2:] + "\n"

  # save the contents in the student file.
  env.push(student, contents, env.OPTION_NONE)
コード例 #2
0
ファイル: cheat.py プロジェクト: bbycode/tinyOs
def reduce(student, reference):
    differences = None
    contents = None
    differ = None
    status = None
    line = None
    r = None
    s = None

    if not ((env.path(reference, env.OPTION_EXIST)) and                   \
            (env.path(reference, env.OPTION_FILE))):
        return

    # load the reference and student files.
    r = env.pull(reference, env.OPTION_NONE).split("\n")
    s = env.pull(student, env.OPTION_NONE).split("\n")

    # build an differ object.
    differ = difflib.Differ()

    # look for the differences.
    differences = differ.compare(r, s)

    # only keep the added lines.
    status = STATUS_EQUAL

    contents = ""

    # for each line.
    for line in differences:
        if line[len(line) - 1] == "\n":
            line = line[:len(line) - 1]

        # we insert a CTC-GATE token so that the CTC tool does not match code
        # regions including such a token.
        # this is done because code has been removed. therefore, a match has
        # no sense here.
        if (line[0] == STATUS_INSERT) and (line[0] != status):
            contents += "_____ctc_gate_____\n"

        status = line[0]

        # add the line to the final file since we only keep added stuff.
        if line[0] == STATUS_INSERT:
            contents += line[2:] + "\n"

    # save the contents in the student file.
    env.push(student, contents, env.OPTION_NONE)
コード例 #3
0
ファイル: dialog.py プロジェクト: bbycode/tinyOs
def menu(title, description, entries):
    choice = None
    height = None
    menu = ""

    for i in range(len(entries)):
        menu += "\"" + entries[i] + "\"" + " " + "\"\""

        if (i + 1) < len(entries):
            menu += " "

    description = "\n" + description + "\n "

    env.launch("dialog", "--title \"" + title + "\" " +			\
                         "--menu \"" + description + "\" " +		\
                         str(WINDOW_HEIGHT) + " " + str(WINDOW_WIDTH) +	\
                         " " + str(MENU_HEIGHT) + " " + menu + " 2> " +	\
                         g_temporary, env.OPTION_NONE)

    choice = env.pull(g_temporary, env.OPTION_NONE)

    if not choice:
        return None

    return entries.index(choice)
コード例 #4
0
ファイル: dialog.py プロジェクト: bbycode/tinyOs
def radio(title, description, entries, current):
    choice = None
    menu = ""

    for i in range(len(entries)):
        if current == entries[i]:
            status = "\"on\""
        else:
            status = "\"off\""

        menu += "\"" + entries[i] + "\"" + " " + "\"\"" + " " + status

        if (i + 1) < len(entries):
            menu += " "

    description = "\n" + description + "\n "

    env.launch("dialog", "--title \"" + title + "\" " +			\
                         " --radiolist \"" + description + "\" " +	\
                         str(WINDOW_HEIGHT) + " " + str(WINDOW_WIDTH) +	\
                         " " + str(MENU_HEIGHT) + " " + menu + " 2> " +	\
                         g_temporary, env.OPTION_NONE)

    choice = env.pull(g_temporary, env.OPTION_NONE)

    if not choice:
        return None

    return entries.index(choice)
コード例 #5
0
ファイル: dialog.py プロジェクト: fenollp/kaneton
def			menu(title, description, entries):
  choice = None
  height = None
  menu = ""

  for i in range(len(entries)):
    menu += "\"" + entries[i] + "\"" + " " + "\"\""

    if (i + 1) < len(entries):
      menu += " "

  description="\n" + description + "\n "

  env.launch("dialog", "--title \"" + title + "\" " +			\
                       "--menu \"" + description + "\" " +		\
                       str(WINDOW_HEIGHT) + " " + str(WINDOW_WIDTH) +	\
                       " " + str(MENU_HEIGHT) + " " + menu + " 2> " +	\
                       g_temporary, env.OPTION_NONE)

  choice = env.pull(g_temporary, env.OPTION_NONE)

  if not choice:
    return None

  return entries.index(choice)
コード例 #6
0
ファイル: dialog.py プロジェクト: fenollp/kaneton
def			radio(title, description, entries, current):
  choice = None
  menu = ""

  for i in range(len(entries)):
    if current == entries[i]:
      status = "\"on\""
    else:
      status = "\"off\""

    menu += "\"" + entries[i] + "\"" + " " + "\"\"" + " " + status

    if (i + 1) < len(entries):
      menu += " "

  description="\n" + description + "\n "

  env.launch("dialog", "--title \"" + title + "\" " +			\
                       " --radiolist \"" + description + "\" " +	\
                       str(WINDOW_HEIGHT) + " " + str(WINDOW_WIDTH) +	\
                       " " + str(MENU_HEIGHT) + " " + menu + " 2> " +	\
                       g_temporary, env.OPTION_NONE)

  choice = env.pull(g_temporary, env.OPTION_NONE)

  if not choice:
    return None

  return entries.index(choice)
コード例 #7
0
ファイル: dialog.py プロジェクト: bbycode/tinyOs
def input(title, description, current):
    choice = None

    description = "\n" + description + "\n "

    env.launch("dialog", "--title \"" + title + "\" " +			\
                         " --inputbox \"" + description + "\" " +		\
                         str(WINDOW_HEIGHT) + " " + str(WINDOW_WIDTH) +	\
                         " " + current + " 2> " + g_temporary,
                         env.OPTION_NONE)

    choice = env.pull(g_temporary, env.OPTION_NONE)

    return choice
コード例 #8
0
ファイル: dialog.py プロジェクト: fenollp/kaneton
def			input(title, description, current):
  choice = None

  description="\n" + description + "\n "

  env.launch("dialog", "--title \"" + title + "\" " +			\
                       " --inputbox \"" + description + "\" " +		\
                       str(WINDOW_HEIGHT) + " " + str(WINDOW_WIDTH) +	\
                       " " + current + " 2> " +	g_temporary,
                       env.OPTION_NONE)

  choice = env.pull(g_temporary, env.OPTION_NONE)

  return choice
コード例 #9
0
ファイル: environment.py プロジェクト: bbycode/tinyOs
def			modify(variable, assignment):
  content = None
  matches = None
  object = None
  match = None

  # update the database
  for object in g_database:
    if variable == object.variable:

      # if the value is the same, just ignore the call
      if object.assignment == assignment:
        return

      object.assignment = assignment

      break

  # load the user profile configuration file.
  content = env.pull(env._PROFILE_USER_DIR_ + "/" + env._USER_ + ".conf",
                     env.OPTION_NONE) + "\n"

  # find the assignments related to the given variable
  matches = re.findall("(" +						\
                         "^" +						\
                         "(" +						\
                           "[ \t]*" +					\
                           variable +					\
                           "[ \t]*" +					\
                           "\+?=" +					\
                           "[ \t]*" +					\
                         ")" +						\
                         "((?:(?:\\\\\n)|[^\n])+)" +			\
                         "\n" +						\
                       ")", content, re.MULTILINE);

  if not matches:
    # add a new entry to the file.
    content = content +							\
              variable + "		=	" + assignment + "\n"
  else:
    # replace the value part with the given value.
    for match in matches:
      content = content.replace(match[0], match[1] + assignment + "\n")

  # finally, write back the content.
  env.push(env._PROFILE_USER_DIR_ + "/" + env._USER_ + ".conf",
           content, env.OPTION_NONE)
コード例 #10
0
ファイル: environment.py プロジェクト: bbycode/tinyOs
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
コード例 #11
0
ファイル: grub.py プロジェクト: Jupotter/kaneton
def			build():
  # warn the user before performing any action.
  warning()

  # display some stuff.
  env.display(env.HEADER_NONE, "", env.OPTION_NONE)
  env.display(env.HEADER_OK, "initializing the boot device", env.OPTION_NONE)

  # for each boot mode, initialize the boot device.
  if (env._BOOT_MODE_ == "peripheral") or (env._BOOT_MODE_ == "network"):
    env.push(env._UDEVICE_,
             env.pull(g_image, env.OPTION_NONE),
             env.OPTION_NONE)
  elif env._BOOT_MODE_ == "image":
    env.copy(g_image, env._IMAGE_, env.OPTION_NONE)
  else:
    env.display(env.HEADER_ERROR, "unknown boot mode '" + env._BOOT_MODE_ +
                "'", env.OPTION_NONE)
    sys.exit(42)
コード例 #12
0
ファイル: grub.py プロジェクト: bbycode/tinyOs
def build():
    # warn the user before performing any action.
    warning()

    # display some stuff.
    env.display(env.HEADER_NONE, "", env.OPTION_NONE)
    env.display(env.HEADER_OK, "initializing the boot device", env.OPTION_NONE)

    # for each boot mode, initialize the boot device.
    if (env._BOOT_MODE_ == "peripheral") or (env._BOOT_MODE_ == "network"):
        env.push(env._UDEVICE_, env.pull(g_image, env.OPTION_NONE),
                 env.OPTION_NONE)
    elif env._BOOT_MODE_ == "image":
        env.copy(g_image, env._IMAGE_, env.OPTION_NONE)
    else:
        env.display(env.HEADER_ERROR,
                    "unknown boot mode '" + env._BOOT_MODE_ + "'",
                    env.OPTION_NONE)
        sys.exit(42)
コード例 #13
0
ファイル: capability.py プロジェクト: fenollp/kaneton
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)
コード例 #14
0
ファイル: client.py プロジェクト: Jupotter/kaneton
def                     Test(server, capability, arguments):
  snapshot = None
  suite = None
  environment = None
  identifier = None

  # warning
  Warning()

  # check the arguments
  if len(arguments) != 2:
    Usage()
    sys.exit(42)

  # retrieve the arguments.
  environment = arguments[0]
  suite = arguments[1]

  # check if there is a 'snapshot.tar.bz2' in the client/ directory.
  if env.path(env._TEST_CLIENT_DIR_ + "/snapshot.tar.bz2",
              env.OPTION_EXIST):
    # display a message.
    env.display(env.HEADER_OK,
                "loading the snapshot '" +                              \
                  env._TEST_CLIENT_DIR_ + "/snapshot.tar.bz2'",
                env.OPTION_NONE)

    # read the snapshot.
    snapshot = env.pull(env._TEST_CLIENT_DIR_ + "/snapshot.tar.bz2",
                        env.OPTION_NONE)

    # warn the user.
    env.display(env.HEADER_NONE, "", env.OPTION_NONE)
    env.display(env.HEADER_INTERACTIVE,
                "are you sure you want the local snapshot to be submitted?",
                env.OPTION_NONE)
    env.display(env.HEADER_INTERACTIVE,
                "press CTRL^C to stop the script, ENTER to continue...",
                env.OPTION_NONE)
    env.input(env.OPTION_NONE)
  else:
    # display a message.
    env.display(env.HEADER_OK,
                "generating the kaneton snapshot",
                env.OPTION_NONE)

    # export the current kaneton implementation.
    env.launch(env._EXPORT_SCRIPT_,
               "test:" + capability["type"],
               env.OPTION_QUIET)

    # display a message.
    env.display(env.HEADER_OK,
                "loading the kaneton snapshot",
                env.OPTION_NONE)

    # read the snapshot.
    snapshot = env.pull(env._EXPORT_DIR_ + "/output/" +                 \
                          "test:" + capability["type"] + ".tar.bz2",
                        env.OPTION_NONE)

  # display a message.
  env.display(env.HEADER_OK,
              "requesting the server",
              env.OPTION_NONE)

  # trigger a test.
  identifier = ktp.xmlrpc.Call(server.Test(capability,
                                           ktp.miscellaneous.Binary(snapshot),
                                           g_platform,
                                           g_architecture,
                                           environment,
                                           suite))

  # display the received report.
  env.display(env.HEADER_OK,
              "the snapshot has been scheduled for testing under the "  \
              "identifier: " + identifier,
              env.OPTION_NONE)
コード例 #15
0
ファイル: client.py プロジェクト: Jupotter/kaneton
def                     Submit(server, capability, arguments):
  snapshot = None
  stage = None

  # warning
  Warning()

  # check the arguments
  if len(arguments) != 1:
    Usage()
    sys.exit(42)

  # retrieve the arguments.
  stage = arguments[0]

  # check if there is a 'snapshot.tar.bz2' in the client/ directory.
  if env.path(env._TEST_CLIENT_DIR_ + "/snapshot.tar.bz2",
              env.OPTION_EXIST):
    # display a message.
    env.display(env.HEADER_OK,
                "loading the snapshot '" +                              \
                  env._TEST_CLIENT_DIR_ + "/snapshot.tar.bz2'",
                env.OPTION_NONE)

    # read the snapshot.
    snapshot = env.pull(env._TEST_CLIENT_DIR_ + "/snapshot.tar.bz2",
                        env.OPTION_NONE)

    # warn the user.
    env.display(env.HEADER_NONE, "", env.OPTION_NONE)
    env.display(env.HEADER_INTERACTIVE,
                "are you sure you want the local snapshot to be submitted?",
                env.OPTION_NONE)
    env.display(env.HEADER_INTERACTIVE,
                "press CTRL^C to stop the script, ENTER to continue...",
                env.OPTION_NONE)
    env.input(env.OPTION_NONE)
  else:
    # display a message.
    env.display(env.HEADER_OK,
                "generating the kaneton snapshot",
                env.OPTION_NONE)

    # export the current kaneton implementation.
    env.launch(env._EXPORT_SCRIPT_,
               "test:" + capability["type"],
               env.OPTION_QUIET)

    # display a message.
    env.display(env.HEADER_OK,
                "loading the kaneton snapshot",
                env.OPTION_NONE)

    # read the snapshot.
    snapshot = env.pull(env._EXPORT_DIR_ + "/output/" +                 \
                          "test:" + capability["type"] + ".tar.bz2",
                        env.OPTION_NONE)

  # display a message.
  env.display(env.HEADER_OK,
              "requesting the server",
              env.OPTION_NONE)

  # submit the snapshot.
  ktp.xmlrpc.Call(server.Submit(capability,
                                ktp.miscellaneous.Binary(snapshot),
                                stage))

  # display a message.
  env.display(env.HEADER_OK,
              "the snapshot has been submitted successfully",
              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)
コード例 #17
0
def student():
    code = None
    components = None
    school = None
    year = None
    group = None
    name = None
    people = None
    members = None
    member = None
    path = None
    capability = None

    # display.
    env.display(env.HEADER_OK,
                "generating a capability for the group '" + g_path + "'",
                env.OPTION_NONE)

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

    # compute the school, year, group and identifier name.
    components = g_path.strip("/").split("/")

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

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

    # initialize the members list.
    members = []

    # for every member, extract name and 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 '" +
                g_path + "'", env.OPTION_NONE)
            continue
        else:
            # remember the member.
            member = {
                "name": match.group(1),
                "email": match.group(2),
                "login": match.group(1).lower().replace(" ", ".")
            }

        # display.
        env.display(env.HEADER_OK, "  " + member["login"], env.OPTION_NONE)

        # compute the unique name.
        name = school + "::" + year + "::" + group + "::" + member["login"]

        # 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.TypeStudent, {
                "school": school,
                "year": year,
                "group": group,
                "student": member["login"]
            }, [member])

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

    # display.
    env.display(
        env.HEADER_OK,
        "the group member capabilities have been generated succesfully",
        env.OPTION_NONE)
コード例 #18
0
def Test(server, capability, arguments):
    snapshot = None
    suite = None
    environment = None
    identifier = None

    # warning
    Warning()

    # check the arguments
    if len(arguments) != 2:
        Usage()
        sys.exit(42)

    # retrieve the arguments.
    environment = arguments[0]
    suite = arguments[1]

    # check if there is a 'snapshot.tar.bz2' in the client/ directory.
    if env.path(env._TEST_CLIENT_DIR_ + "/snapshot.tar.bz2", env.OPTION_EXIST):
        # display a message.
        env.display(env.HEADER_OK,
                    "loading the snapshot '" +                              \
                      env._TEST_CLIENT_DIR_ + "/snapshot.tar.bz2'",
                    env.OPTION_NONE)

        # read the snapshot.
        snapshot = env.pull(env._TEST_CLIENT_DIR_ + "/snapshot.tar.bz2",
                            env.OPTION_NONE)

        # warn the user.
        env.display(env.HEADER_NONE, "", env.OPTION_NONE)
        env.display(
            env.HEADER_INTERACTIVE,
            "are you sure you want the local snapshot to be submitted?",
            env.OPTION_NONE)
        env.display(env.HEADER_INTERACTIVE,
                    "press CTRL^C to stop the script, ENTER to continue...",
                    env.OPTION_NONE)
        env.input(env.OPTION_NONE)
    else:
        # display a message.
        env.display(env.HEADER_OK, "generating the kaneton snapshot",
                    env.OPTION_NONE)

        # export the current kaneton implementation.
        env.launch(env._EXPORT_SCRIPT_, "test:" + capability["type"],
                   env.OPTION_QUIET)

        # display a message.
        env.display(env.HEADER_OK, "loading the kaneton snapshot",
                    env.OPTION_NONE)

        # read the snapshot.
        snapshot = env.pull(env._EXPORT_DIR_ + "/output/" +                 \
                              "test:" + capability["type"] + ".tar.bz2",
                            env.OPTION_NONE)

    # display a message.
    env.display(env.HEADER_OK, "requesting the server", env.OPTION_NONE)

    # trigger a test.
    identifier = ktp.xmlrpc.Call(
        server.Test(capability, ktp.miscellaneous.Binary(snapshot), g_platform,
                    g_architecture, environment, suite))

    # display the received report.
    env.display(env.HEADER_OK,
                "the snapshot has been scheduled for testing under the "  \
                "identifier: " + identifier,
                env.OPTION_NONE)
コード例 #19
0
ファイル: cheat.py プロジェクト: fenollp/kaneton
def                     output():
  student = None

  # display a message.
  env.display(env.HEADER_OK,
              "generating the output file '" + g_output + "'",
              env.OPTION_NONE)

  # initialise the output file.
  initialise()

  # write the basic info.
  write(HTML_HEADER)
  write("<title>[" + g_school + " :: " + g_year + " :: " +
        g_stage + "]</title>")
  write(HTML_STYLE)
  write(HTML_SCRIPT)
  write(HTML_INNER)

  # for every student to test, retrieve the trace and include it in the
  # output HTML page.
  for student in g_history:
    data = None
    trace = None

    # only treat the student from the given year and stage.
    if not ((student["year"] == g_year) and                     \
            (student["stage"] == g_stage)):
      continue

    # load the trace.
    data = env.pull(student["trace"], env.OPTION_NONE).strip("\n").split("\n")

    # build a meaningful trace from the chaotic records
    trace = build(student["name"], data)

    # initialise the output for this student.
    write("""
<div class="instance">
  <span class="student">""" + student["student"] + """</span>
  <span class="people">""" + student["people"] + """</span>
  <div class="categories">
""")

    # go through every level of the trace.
    for level in [ LEVEL_CRITIC, LEVEL_SUSPECT, LEVEL_BENIGN ]:
      L = None

      # skip empty categories.
      if len(trace[level]) == 0:
        continue

      # generate a label for the category.
      L = label()

      # output the category header.
      write("""
<div class="category-""" + level + """">
  <div class="header-""" + level + """">
    <div class="symbol"><a href="javascript:Show('""" + L +
"""');" id="symbol:""" + L + """">+</a></div>
    <div class="matches">""" + str(len(trace[level])) + """ matches</div>
    <div class="clear"></div>
  </div>
  <div class="traces" id="traces:""" + L + """">
""")

      # for every record in this level.
      for record in trace[level]:
        bar = None

        # is this the first record in this level?
        if record != trace[level][0]:
          bar = " bar"
        else:
          bar = ""

        # write the content.
        write("""
<table class="description""" + bar +
"""" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="me">""" +
record["student"]["name"] + """ :: """ + record["student"]["file"] + """</td>
    <td class="tokens"><a href="javascript:Open('""" + record["label"] +
"""');" id="symbol:""" + record["label"] + """">""" + str(record["tokens"]) +
""" tokens</a></td>
    <td class="you">""" + record["neighbour"]["file"] + """ :: """ +
record["neighbour"]["name"] + """</td>
  </tr>
</table>
<table class="trace" id="trace:""" + record["label"] + """">
  <tr>
    <td class="left">
      <pre class="sources">""" + record["student"]["code"] + """</pre>
    </td>
    <td class="right">
      <pre class="sources">""" + record["neighbour"]["code"] + """</pre>
    </td>
  </tr>
</table>
""")

      # close the category.
      write("""
      </div>
    </div>
""")

    # finish the generation for this student.
    write("""
  </div>
</div>
<br/>
""")

  # finish the HTML generation.
  write(HTML_FOOTER)

  clean()
コード例 #20
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
          } ]
コード例 #21
0
def Submit(server, capability, arguments):
    snapshot = None
    stage = None

    # warning
    Warning()

    # check the arguments
    if len(arguments) != 1:
        Usage()
        sys.exit(42)

    # retrieve the arguments.
    stage = arguments[0]

    # check if there is a 'snapshot.tar.bz2' in the client/ directory.
    if env.path(env._TEST_CLIENT_DIR_ + "/snapshot.tar.bz2", env.OPTION_EXIST):
        # display a message.
        env.display(env.HEADER_OK,
                    "loading the snapshot '" +                              \
                      env._TEST_CLIENT_DIR_ + "/snapshot.tar.bz2'",
                    env.OPTION_NONE)

        # read the snapshot.
        snapshot = env.pull(env._TEST_CLIENT_DIR_ + "/snapshot.tar.bz2",
                            env.OPTION_NONE)

        # warn the user.
        env.display(env.HEADER_NONE, "", env.OPTION_NONE)
        env.display(
            env.HEADER_INTERACTIVE,
            "are you sure you want the local snapshot to be submitted?",
            env.OPTION_NONE)
        env.display(env.HEADER_INTERACTIVE,
                    "press CTRL^C to stop the script, ENTER to continue...",
                    env.OPTION_NONE)
        env.input(env.OPTION_NONE)
    else:
        # display a message.
        env.display(env.HEADER_OK, "generating the kaneton snapshot",
                    env.OPTION_NONE)

        # export the current kaneton implementation.
        env.launch(env._EXPORT_SCRIPT_, "test:" + capability["type"],
                   env.OPTION_QUIET)

        # display a message.
        env.display(env.HEADER_OK, "loading the kaneton snapshot",
                    env.OPTION_NONE)

        # read the snapshot.
        snapshot = env.pull(env._EXPORT_DIR_ + "/output/" +                 \
                              "test:" + capability["type"] + ".tar.bz2",
                            env.OPTION_NONE)

    # display a message.
    env.display(env.HEADER_OK, "requesting the server", env.OPTION_NONE)

    # submit the snapshot.
    ktp.xmlrpc.Call(
        server.Submit(capability, ktp.miscellaneous.Binary(snapshot), stage))

    # display a message.
    env.display(env.HEADER_OK, "the snapshot has been submitted successfully",
                env.OPTION_NONE)
コード例 #22
0
ファイル: capability.py プロジェクト: fenollp/kaneton
def                     student():
  code = None
  components = None
  school = None
  year = None
  group = None
  name = None
  people = None
  members = None
  member = None
  path = None
  capability = None

  # display.
  env.display(env.HEADER_OK,
              "generating a capability for the group '" + g_path + "'",
              env.OPTION_NONE)

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

  # compute the school, year, group and identifier name.
  components = g_path.strip("/").split("/")

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

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

  # initialize the members list.
  members = []

  # for every member, extract name and 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 '" +
                  g_path + "'",
                  env.OPTION_NONE)
      continue
    else:
      # remember the member.
      member = { "name": match.group(1),
                 "email": match.group(2),
                 "login": match.group(1).lower().replace(" ", ".") }

    # display.
    env.display(env.HEADER_OK,
                "  " + member["login"],
                env.OPTION_NONE)

    # compute the unique name.
    name = school + "::" + year + "::" + group + "::" + member["login"]

    # 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.TypeStudent,
                                       { "school": school,
                                         "year": year,
                                         "group": group,
                                         "student": member["login"] },
                                       [ member ])

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

  # display.
  env.display(env.HEADER_OK,
              "the group member capabilities have been generated succesfully",
              env.OPTION_NONE)
コード例 #23
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
                  } ]
コード例 #24
0
ファイル: cheat.py プロジェクト: bbycode/tinyOs
def output():
    student = None

    # display a message.
    env.display(env.HEADER_OK, "generating the output file '" + g_output + "'",
                env.OPTION_NONE)

    # initialise the output file.
    initialise()

    # write the basic info.
    write(HTML_HEADER)
    write("<title>[" + g_school + " :: " + g_year + " :: " + g_stage +
          "]</title>")
    write(HTML_STYLE)
    write(HTML_SCRIPT)
    write(HTML_INNER)

    # for every student to test, retrieve the trace and include it in the
    # output HTML page.
    for student in g_history:
        data = None
        trace = None

        # only treat the student from the given year and stage.
        if not ((student["year"] == g_year) and                     \
                (student["stage"] == g_stage)):
            continue

        # load the trace.
        data = env.pull(student["trace"],
                        env.OPTION_NONE).strip("\n").split("\n")

        # build a meaningful trace from the chaotic records
        trace = build(student["name"], data)

        # initialise the output for this student.
        write("""
<div class="instance">
  <span class="student">""" + student["student"] + """</span>
  <span class="people">""" + student["people"] + """</span>
  <div class="categories">
""")

        # go through every level of the trace.
        for level in [LEVEL_CRITIC, LEVEL_SUSPECT, LEVEL_BENIGN]:
            L = None

            # skip empty categories.
            if len(trace[level]) == 0:
                continue

            # generate a label for the category.
            L = label()

            # output the category header.
            write("""
<div class="category-""" + level + """">
  <div class="header-""" + level + """">
    <div class="symbol"><a href="javascript:Show('""" + L +
                  """');" id="symbol:""" + L + """">+</a></div>
    <div class="matches">""" + str(len(trace[level])) + """ matches</div>
    <div class="clear"></div>
  </div>
  <div class="traces" id="traces:""" + L + """">
""")

            # for every record in this level.
            for record in trace[level]:
                bar = None

                # is this the first record in this level?
                if record != trace[level][0]:
                    bar = " bar"
                else:
                    bar = ""

                # write the content.
                write("""
<table class="description""" + bar +
                      """" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td class="me">""" + record["student"]["name"] + """ :: """ +
                      record["student"]["file"] + """</td>
    <td class="tokens"><a href="javascript:Open('""" + record["label"] +
                      """');" id="symbol:""" + record["label"] + """">""" +
                      str(record["tokens"]) + """ tokens</a></td>
    <td class="you">""" + record["neighbour"]["file"] + """ :: """ +
                      record["neighbour"]["name"] + """</td>
  </tr>
</table>
<table class="trace" id="trace:""" + record["label"] + """">
  <tr>
    <td class="left">
      <pre class="sources">""" + record["student"]["code"] + """</pre>
    </td>
    <td class="right">
      <pre class="sources">""" + record["neighbour"]["code"] + """</pre>
    </td>
  </tr>
</table>
""")

            # close the category.
            write("""
      </div>
    </div>
""")

        # finish the generation for this student.
        write("""
  </div>
</div>
<br/>
""")

    # finish the HTML generation.
    write(HTML_FOOTER)

    clean()