Exemple #1
0
                    help=('Generate Django templates from localized '
                          'HTML articles in `./_localized`.'))
  parser.add_option('--yaml', dest='yaml_infile', default='',
                    help=('Generate localizable template from a specified YAML '
                          'file. Output is written to `./[filename].html`'))

  options = parser.parse_args()[0]
  if not (options.generate_html or options.import_html):
    parser.error('You must specify either `--generate` or `--import`.')

  l7r = Localizer(original_root=Article.ROOT,
                   localized_root=Article.LOCALIZED_ROOT)

  if options.generate_html and options.yaml_infile:
    try:
      l7r.GenerateLocalizableYaml(options.yaml_infile)
    except YamlProcessorException:
      parser.error('`%s` couldn\'t be read.' % options.yaml_infile)
  elif options.generate_html:
    try:
      os.mkdir(Article.UNLOCALIZED_ROOT)
    except OSError:
      pass
    l7r.GenerateLocalizableFiles()
  elif options.import_html:
    try:
      os.mkdir(Article.LOCALIZED_ROOT)
    except OSError:
      pass
    l7r.ImportLocalizedFiles()