Example #1
0
def generate_full_config(config_file_path, slides):
  ''' Generates a full configuration from a simplified configuration
  '''
  global current_module
  register()

  conf_data = read_conf_file(config_file_path)
  validate_glob_config(conf_data)

  full_config = OrderedDict()
  full_config = conf_data.copy()
  full_config['chapters'] = OrderedDict()
  del full_config['glob_ka_options']
  del full_config['glob_ss_options']
  del full_config['glob_pe_options']
  del full_config['glob_extr_options']

  mod_files = get_chapter_module_files(conf_data)
  for chapter, files in mod_files.iteritems():
    full_config['chapters'][chapter] = OrderedDict()
    for x in files:
      rst_dir_name = x.split(os.sep)[-2]
      rst_fname = os.path.basename(x).partition('.')[0]
      if rst_dir_name == conf_data['lang']:
        mod_path = rst_fname
      else:
        mod_path = rst_dir_name + '/' + rst_fname
      
      current_module = mod_path

      if not os.path.isfile(x):
        print_err("ERROR: '{0}' is not a valid module path".format(mod_path))
        sys.exit(1)

      with open(x, 'r') as rstfile:
        source = rstfile.read()

      source = remove_markup(source)

      rst_parts = publish_parts(source,
                  settings_overrides={'output_encoding': 'utf8',
                  'initial_header_level': 2},
                  writer_name="xml",
		  source_path=mod_path)

      mod_json = xmltodict.parse(rst_parts['whole'])
      mod_config = extract_mod_config(mod_json)

      full_config['chapters'][chapter][mod_path] = mod_config

  if not slides:
    for mod_name, exercises in ex_options.iteritems():
      for exer in exercises:
        print_err('WARNING: the exercise "{0}" does not exist in module "{1}"'.format(exer, mod_name))
    for mod_name, sections in sect_options.iteritems():
      for sect in sections:
        print_err('WARNING: the section "{0}" does not exist in module "{1}"'.format(sect, mod_name))
  return full_config
Example #2
0
                        if exercise['points'] == defaults[ex_type]['points']:
                            del exercise['points']

                        if len(exercise) == 0:
                            del section[ex_name]
                        else:
                            module[ex_name] = exercise
                            del section[ex_name]

            for section_name, section in module['sections'].iteritems():
                if len(section) > 0:
                    module[section_name] = section

            del module['sections']

    return simple_conf


if __name__ == '__main__':
    args = sys.argv
    if len(args) != 3:
        print('Usage: {0} config_file output_file', args[0])
        sys.exit(1)

    config_file = args[1]
    output_file = args[2]
    conf_data = read_conf_file(config_file)
    simple_conf = gen_simple_config(conf_data)

    with open(output_file, 'w') as outfile:
        json.dump(simple_conf, outfile, indent=2)
Example #3
0
def generate_full_config(config_file_path, slides):
  ''' Generates a full configuration from a simplified configuration
  '''
  global current_module
  register()

  conf_data = read_conf_file(config_file_path)
  validate_glob_config(conf_data)

  full_config = OrderedDict()
  full_config = conf_data.copy()
  full_config['chapters'] = OrderedDict()
  if 'glob_ka_options' in full_config:
    del full_config['glob_ka_options']
  if 'glob_ss_options' in full_config:
    del full_config['glob_ss_options']
  if 'glob_ff_options' in full_config:
    del full_config['glob_ff_options']
  if 'glob_pe_options' in full_config:
    del full_config['glob_pe_options']
  if 'glob_extr_options' in full_config:
    del full_config['glob_extr_options']

  mod_files = get_chapter_module_files(conf_data)
  for chapter, files in mod_files.iteritems():
    full_config['chapters'][chapter] = OrderedDict()
    for x in files:
      rst_dir_name = x.split(os.sep)[-2]
      rst_fname = os.path.basename(x).partition('.')[0]
      if rst_dir_name == conf_data['lang']:
        mod_path = rst_fname
      else:
        mod_path = rst_dir_name + '/' + rst_fname
      
      current_module = mod_path

      if not os.path.isfile(x):
        print_err("ERROR: '{0}' is not a valid module path".format(mod_path))
        sys.exit(1)

      with open(x, 'r') as rstfile:
        source = rstfile.read()

      source = remove_markup(source)

      rst_parts = publish_parts(source,
                  settings_overrides={'output_encoding': 'utf8',
                  'initial_header_level': 2},
                  writer_name="xml",
      source_path=mod_path)

      mod_json = xmltodict.parse(rst_parts['whole'])
      mod_config = extract_mod_config(mod_json)

      full_config['chapters'][chapter][mod_path] = mod_config

  if not slides:
    for mod_name, exercises in ex_options.iteritems():
      for exer in exercises:
        print_err('WARNING: the exercise "{0}" does not exist in module "{1}"'.format(exer, mod_name))
    for mod_name, sections in sect_options.iteritems():
      for sect in sections:
        print_err('WARNING: the section "{0}" does not exist in module "{1}"'.format(sect, mod_name))
  return full_config
Example #4
0
              del exercise['threshold']
            if exercise['points'] == defaults[ex_type]['points']:
              del exercise['points']

            if len(exercise) == 0:
              del section[ex_name]
            else:
              module[ex_name] = exercise
              del section[ex_name]
          
      for section_name, section in module['sections'].iteritems():
        if len(section) > 0:
          module[section_name] = section
      
      del module['sections']

  return simple_conf

if __name__ == '__main__':
  args = sys.argv
  if len(args) != 3:
      print('Usage: {0} config_file output_file', args[0])
      sys.exit(1)

  config_file = args[1]
  output_file = args[2]
  conf_data = read_conf_file(config_file)
  simple_conf = gen_simple_config(conf_data)

  with open(output_file, 'w') as outfile:
    json.dump(simple_conf, outfile, indent=2)