Exemple #1
0
def main():
  fetch = '/tmp/udhr/zip'
  udhr = '[tools]/third_party/udhr'
  samples = '[tools]/sample_texts'

  epilog = """The general flow is as follows:
  1) ensure attributions.tsv is in [tools]/third_party/ohchr, using
     extract_ohchr_attributions.py.
  2) use -uu to fetch and stage changes to [tools]/third_party/udhr
  3) use -us --sample_dir=/tmp/foo to generate samples
  4) use -c --sample_dir=/tmp/foo to compare the staged samples
  5) tweak the mapping, use -m to see that it's doing what we want
  6) use --us to generate the samples and stage them to [tools]/sample_texts

  This will not overwrite samples whose most recent log entry does
  not start with 'Updated by tool'.
  """

  parser = argparse.ArgumentParser(epilog=epilog,
    formatter_class=argparse.RawTextHelpFormatter)
  parser.add_argument('--fetch_dir', help='directory into which to fetch xml.zip '
                      '(default %s)' % fetch, metavar='dir', default=fetch)
  parser.add_argument('--udhr_dir', help='location into which to unpack udhr files '
                      '(default %s)' % udhr, metavar='dir', default=udhr)
  parser.add_argument('--sample_dir', help='directory into which to extract samples '
                      '(default %s)' % samples, metavar='dir', default=samples)
  parser.add_argument('-f', '--fetch', help='fetch files from unicode.org/udhr to fetch dir',
                      action='store_true')
  parser.add_argument('-uu', '--update_udhr', help='unpack from fetched files to clean udhr dir\n'
                      '(will stage if in repo and not no_stage)', action='store_true')
  parser.add_argument('-us', '--update_sample', help='extract samples from udhr to sample dir, '
                      'using the bcp to code mapping\n(will stage if in repo and not no_stage)',
                      action='store_true')
  parser.add_argument('-m', '--mapping', help='print the bcp to code mapping generated from the '
                      'udhr dir', action='store_true')
  parser.add_argument('-c', '--compare', help='compare sample changes from base dir '
                      '(default %s)\nto sample dir' % samples,
                      metavar='base_dir',  nargs='?', const=samples,
                      dest='base_sample_dir')
  parser.add_argument('-co', '--compare_opts', help='options for comparison, provide any of:\n'
                      '  \'missing\' to show samples files not in base, and/or\n'
                      '  \'diffs\' to show full diffs of samples',
                      metavar='opt', nargs='+')
  parser.add_argument('-ts', '--test_script', help='test script of samples in sample dir',
                      action='store_true')
  parser.add_argument('-n', '--no_stage', help='do not stage changes in repo', action='store_true')

  args = parser.parse_args()

  # Check arguments

  if not (args.fetch or args.update_udhr or args.update_sample or args.mapping
          or args.base_sample_dir or args.test_script):
    print 'nothing to do.'
    return

  def fix_noto_prefix(argname):
    newval = tool_utils.resolve_path(getattr(args, argname))
    setattr(args, argname, newval)

  if args.update_udhr or args.update_sample or args.mapping:
    fix_noto_prefix('udhr_dir')

  if args.update_sample or args.base_sample_dir or args.test_script:
    fix_noto_prefix('sample_dir')

  if args.base_sample_dir:
    fix_noto_prefix('base_sample_dir')

  if args.sample_dir == args.base_sample_dir:
    parser.error('Compare is no-op when base and target sample dirs are the same.')

  # Perform operations.  Some might still fail despite arg checks.
  try:
    if args.fetch:
      fetch_udhr(args.fetch_dir)

    if args.update_udhr:
      in_repo = args.udhr_dir == tool_utils.resolve_path(udhr)
      update_udhr(args.udhr_dir, args.fetch_dir, in_repo and not args.no_stage)

    if args.update_sample or args.mapping:
      ohchr_dir = tool_utils.resolve_path('[tools]/third_party/ohchr')
      bcp_to_code_attrib = get_bcp_to_code_attrib(args.udhr_dir, ohchr_dir)

    if args.update_sample:
      in_repo = args.sample_dir == tool_utils.resolve_path(samples)
      update_samples(args.sample_dir, args.udhr_dir, bcp_to_code_attrib,
                     in_repo and not args.no_stage)

    if args.mapping:
      print_bcp_to_code_attrib(bcp_to_code_attrib)

    if args.base_sample_dir:
      compare_samples(args.base_sample_dir, args.sample_dir, opts=args.compare_opts)

    if args.test_script:
      test_sample_scripts(args.sample_dir)
  except ValueError as e:
      print 'Error:', e
Exemple #2
0
 def fix_noto_prefix(argname):
   newval = tool_utils.resolve_path(getattr(args, argname))
   setattr(args, argname, newval)
def main():
    fetch = "/tmp/udhr/zip"
    udhr = "[tools]/third_party/udhr"
    samples = "[tools]/sample_texts"

    epilog = """The general flow is as follows:
  1) ensure attributions.tsv is in [tools]/third_party/ohchr, using
     extract_ohchr_attributions.py.
  2) use -uu to fetch and stage changes to [tools]/third_party/udhr
  3) use -us --sample_dir=/tmp/foo to generate samples
  4) use -c --sample_dir=/tmp/foo to compare the staged samples
  5) tweak the mapping, use -m to see that it's doing what we want
  6) use --us to generate the samples and stage them to [tools]/sample_texts

  This will not overwrite samples whose most recent log entry does
  not start with 'Updated by tool'.
  """

    parser = argparse.ArgumentParser(epilog=epilog, formatter_class=argparse.RawTextHelpFormatter)
    parser.add_argument(
        "--fetch_dir",
        help="directory into which to fetch xml.zip " "(default %s)" % fetch,
        metavar="dir",
        default=fetch,
    )
    parser.add_argument(
        "--udhr_dir",
        help="location into which to unpack udhr files " "(default %s)" % udhr,
        metavar="dir",
        default=udhr,
    )
    parser.add_argument(
        "--sample_dir",
        help="directory into which to extract samples " "(default %s)" % samples,
        metavar="dir",
        default=samples,
    )
    parser.add_argument("-f", "--fetch", help="fetch files from unicode.org/udhr to fetch dir", action="store_true")
    parser.add_argument(
        "-uu",
        "--update_udhr",
        help="unpack from fetched files to clean udhr dir\n" "(will stage if in repo and not no_stage)",
        action="store_true",
    )
    parser.add_argument(
        "-us",
        "--update_sample",
        help="extract samples from udhr to sample dir, "
        "using the bcp to code mapping\n(will stage if in repo and not no_stage)",
        action="store_true",
    )
    parser.add_argument(
        "-m", "--mapping", help="print the bcp to code mapping generated from the " "udhr dir", action="store_true"
    )
    parser.add_argument(
        "-c",
        "--compare",
        help="compare sample changes from base dir " "(default %s)\nto sample dir" % samples,
        metavar="base_dir",
        nargs="?",
        const=samples,
        dest="base_sample_dir",
    )
    parser.add_argument(
        "-co",
        "--compare_opts",
        help="options for comparison, provide any of:\n"
        "  'missing' to show samples files not in base, and/or\n"
        "  'diffs' to show full diffs of samples",
        metavar="opt",
        nargs="+",
    )
    parser.add_argument("-ts", "--test_script", help="test script of samples in sample dir", action="store_true")
    parser.add_argument("-n", "--no_stage", help="do not stage changes in repo", action="store_true")

    args = parser.parse_args()

    # Check arguments

    if not (
        args.fetch or args.update_udhr or args.update_sample or args.mapping or args.base_sample_dir or args.test_script
    ):
        print "nothing to do."
        return

    def fix_noto_prefix(argname):
        newval = tool_utils.resolve_path(getattr(args, argname))
        setattr(args, argname, newval)

    if args.update_udhr or args.update_sample or args.mapping:
        fix_noto_prefix("udhr_dir")

    if args.update_sample or args.base_sample_dir or args.test_script:
        fix_noto_prefix("sample_dir")

    if args.base_sample_dir:
        fix_noto_prefix("base_sample_dir")

    if args.sample_dir == args.base_sample_dir:
        parser.error("Compare is no-op when base and target sample dirs are the same.")

    # Perform operations.  Some might still fail despite arg checks.
    try:
        if args.fetch:
            fetch_udhr(args.fetch_dir)

        if args.update_udhr:
            in_repo = args.udhr_dir == tool_utils.resolve_path(udhr)
            update_udhr(args.udhr_dir, args.fetch_dir, in_repo and not args.no_stage)

        if args.update_sample or args.mapping:
            ohchr_dir = tool_utils.resolve_path("[tools]/third_party/ohchr")
            bcp_to_code_attrib = get_bcp_to_code_attrib(args.udhr_dir, ohchr_dir)

        if args.update_sample:
            in_repo = args.sample_dir == tool_utils.resolve_path(samples)
            update_samples(args.sample_dir, args.udhr_dir, bcp_to_code_attrib, in_repo and not args.no_stage)

        if args.mapping:
            print_bcp_to_code_attrib(bcp_to_code_attrib)

        if args.base_sample_dir:
            compare_samples(args.base_sample_dir, args.sample_dir, opts=args.compare_opts)

        if args.test_script:
            test_sample_scripts(args.sample_dir)
    except ValueError as e:
        print "Error:", e