Esempio n. 1
0
def module_action(export_dir, arg):
    strip = 0
    env.display(env.HEADER_OK, 'action breplace ' + arg['id'], env.OPTION_NONE)
    id = arg['id'].split('::', 1)
    filepath = id[0]
    label = id[1]
    tmpfilepath = env.temporary(env.OPTION_FILE)
    srcf = open(export_dir + '/' + filepath, 'r')
    dstf = open(tmpfilepath, 'w')
    line = srcf.readline()
    startpattern = re.compile(".*[[]block\:\:" + label + "[]].*")
    endpattern = re.compile(".*[[]/block\:\:" + label + "[]].*")
    while line != "":
        if strip == 0:
            if startpattern.match(line) != None:
                strip = 1
                dstf.write(arg['data'])
        if strip != 1:
            dstf.write(line)
        if strip == 1:
            if endpattern.match(line) != None:
                strip = 2
        line = srcf.readline()
    dstf.close()
    srcf.close()
    env.copy(tmpfilepath, export_dir + '/' + filepath, env.OPTION_NONE)
    env.remove(tmpfilepath, env.OPTION_NONE)
    if strip == 0:
        env.display(env.HEADER_ERROR,
                    'no block ' + label + ' in file ' + filepath,
                    env.OPTION_NONE)
        return -1
    return 0
Esempio n. 2
0
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)
Esempio n. 3
0
def module_action(export_dir, arg):
    strip = 0
    env.display(env.HEADER_OK, 'action breplace ' + arg['id'], env.OPTION_NONE)
    id = arg['id'].split('::', 1)
    filepath = id[0]
    label = id[1]
    tmpfilepath = env.temporary(env.OPTION_FILE)
    srcf = open(export_dir + '/' + filepath, 'r')
    dstf = open(tmpfilepath, 'w')
    line = srcf.readline()
    startpattern = re.compile(".*[[]block\:\:" + label + "[]].*")
    endpattern = re.compile(".*[[]/block\:\:" + label + "[]].*")
    while line != "":
        if strip == 0:
            if startpattern.match(line) != None:
                strip = 1
                dstf.write(arg['data'])
        if strip != 1:
            dstf.write(line)
        if strip == 1:
            if endpattern.match(line) != None:
                strip = 2
        line = srcf.readline()
    dstf.close()
    srcf.close()
    env.copy(tmpfilepath, export_dir + '/' + filepath, env.OPTION_NONE)
    env.remove(tmpfilepath, env.OPTION_NONE)
    if strip == 0:
        env.display(env.HEADER_ERROR, 'no block ' + label + ' in file ' + filepath, env.OPTION_NONE)
        return -1
    return 0
Esempio n. 4
0
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)
Esempio n. 5
0
def menu():
    global g_components
    global g_menu
    content = None
    component = None

    # initialize the file content.
    content = "timeout 0\n" +						\
              "title kaneton\n"

    # add information about how to boot.
    if (env._BOOT_MODE_ == "peripheral") or (env._BOOT_MODE_ == "image"):
        if env._BOOT_DEVICE_ == "floppy":
            content += "root (fd0)\n"
        elif env._BOOT_DEVICE_ == "hard-drive":
            content += "root (hd0)\n"
        else:
            env.display(env.HEADER_ERROR,
                        "unknown boot device '" + env._BOOT_DEVICE_ + "'",
                        env.OPTION_NONE)
            sys.exit(42)
    elif env._BOOT_MODE_ == "network":
        content += "ifconfig --address=" + env._ADDRESS_ + " --server=" +	\
                     env._TFTP_ADDRESS_ + "\n" +				\
                   "root (nd)\n"
    else:
        env.display(env.HEADER_ERROR,
                    "unknown boot mode '" + env._BOOT_MODE_ + "'",
                    env.OPTION_NONE)
        sys.exit(42)

    # retrieve the grub modules from the _COMPONENTS_ environment variables.
    g_components = re.split("[ \t]+", env._COMPONENTS_.strip())

    # set the first component as the grub kernel.
    content += re.sub("^.*\/", "kernel /modules/", g_components[0]) + "\n"

    # set the other components as grub modules.
    for component in g_components[1:]:
        content += re.sub("^.*\/", "module /modules/", component) + "\n"

    # create the temporary file and fill it.
    g_menu = env.temporary(env.OPTION_FILE)

    env.push(g_menu, content, env.OPTION_NONE)
Esempio n. 6
0
def			menu():
  global g_components
  global g_menu
  content = None
  component = None

  # initialize the file content.
  content = "timeout 0\n" +						\
            "title kaneton\n"

  # add information about how to boot.
  if (env._BOOT_MODE_ == "peripheral") or (env._BOOT_MODE_ == "image"):
    if env._BOOT_DEVICE_ == "floppy":
      content += "root (fd0)\n"
    elif env._BOOT_DEVICE_ == "hard-drive":
      content += "root (hd0)\n"
    else:
      env.display(env.HEADER_ERROR,
                  "unknown boot device '" + env._BOOT_DEVICE_ + "'",
                  env.OPTION_NONE)
      sys.exit(42)
  elif env._BOOT_MODE_ == "network":
    content += "ifconfig --address=" + env._ADDRESS_ + " --server=" +	\
                 env._TFTP_ADDRESS_ + "\n" +				\
               "root (nd)\n"
  else:
    env.display(env.HEADER_ERROR, "unknown boot mode '" + env._BOOT_MODE_ +
                "'", env.OPTION_NONE)
    sys.exit(42)

  # retrieve the grub modules from the _COMPONENTS_ environment variables.
  g_components = re.split("[ \t]+", env._COMPONENTS_.strip())

  # set the first component as the grub kernel.
  content += re.sub("^.*\/", "kernel /modules/", g_components[0]) + "\n"

  # set the other components as grub modules.
  for component in g_components[1:]:
    content += re.sub("^.*\/", "module /modules/", component) + "\n"

  # create the temporary file and fill it.
  g_menu = env.temporary(env.OPTION_FILE)

  env.push(g_menu, content, env.OPTION_NONE)
Esempio n. 7
0
def			init():
  global g_temporary

  g_temporary = env.temporary(env.OPTION_FILE)
Esempio n. 8
0
def init():
    global g_temporary

    g_temporary = env.temporary(env.OPTION_FILE)
Esempio n. 9
0
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
          } ]
Esempio n. 10
0
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
                  } ]