Пример #1
0
 matches_command.add_argument('--noExceptions', default=False, action='store_true')
 validation_command = subparsers.add_parser('validation')
 trans = etree.parse('translations.xml')
 values = trans.xpath('//value')
 matches_by_tag = {value.attrib['tag']: set() for value in values}
 matches_by_file_by_tag = {value.attrib['tag']: {} for value in values}
 matches_by_exiftag = {value.attrib['tag']: {} for value in values}
 matches_by_file = {}
 tags_command.set_defaults(func=print_tag2tag, matches_by_tag=matches_by_tag)
 matches_command.set_defaults(func=print_tag2file2tag, matches_by_file_by_tag=matches_by_file_by_tag)
 validation_command.set_defaults(func=print_validation_file, matches_by_exiftag=matches_by_exiftag)
 numtags_command.set_defaults(func=print_numtags, matches_by_file=matches_by_file)
 numtagscsv_command.set_defaults(func=print_csv, matches_by_file=matches_by_file)
 args = parser.parse_args()
 exceptions = []
 example_files = getExampleFiles(args.exampledir)
 for filename in example_files:
     exif = getExifXml(filename)
     matches_by_file[filename] = {}
     for value in values:
         all_matches = []
         for num, source in enumerate(value.getiterator('source')):
             valid = source.attrib["valid"]
             if valid == "false":
                 continue
             parent = source.getparent()
             if parent.tag == 'priorityGroup':
                 if 'ordered' in parent.attrib:
                     num = '%s.%s' % (parent.getparent().index(parent), parent.index(source))
                 else:
                     num = str(parent.getparent().index(parent))
Пример #2
0
    content = getExifXml(fname)
    nodes = content.xpath('/rdf:RDF/rdf:Description/*', namespaces=ns)
    names = set([nameElements(node) for node in nodes])
    return names


def writeNames(old_tags, new_tags):
    with open('tags.py', 'w') as f:
        f.write("tags=[\n")
        for (pre, uri, local) in old_tags:
            f.write("('%s','%s','%s'),\n" % (pre, uri, local))
        if new_tags:
            print "--- New tags!"
            f.write("# new tags\n")
            for (pre, uri, local) in new_tags:
                print "('%s','%s','%s'),\n" % (pre, uri, local)
                f.write("('%s','%s','%s'),\n" % (pre, uri, local))
        f.write(']\n')


if __name__ == '__main__':
    pool = Pool(cpu_count())
    example_files = getExampleFiles(sys.argv[1:])
    tags = pool.map(getKeys, example_files)
    tags = reduce(set.union, tags, set())
    old_tags_set = set(old_tags)
    new_tags = [tag for tag in tags if tag not in old_tags_set]
    old_tags.sort()
    new_tags.sort()
    writeNames(old_tags, new_tags)