def metaUpdate(xml_file):
    global tree, tree_root, i
    # set xml tree element
    tree = meta.xmlMeta(xml_file)
    tree_root = tree.getroot()
    dataidinfoupdate("Title", "title", titleinput)
    searchkeys(searchkeywords)
    dataidinfoupdate("Summary (Purpose)", "summary", summaryinput)
    dataidinfoupdate("Description (Abstract)", "description", descinput)
    dataidinfoupdate("Credits", "credit", creditsinput)
    for i in option_list:
        i = i.replace("'", "")
        if i == "Resource Contact":
            contact("resContact")
        elif i == "Distribution Contact":
            contact("distContact")
        elif i == "Metadata Contact":
            contact("mdContact")
        elif i == "Use Limitation":
            uselimitConstraint()
        elif i == "Distribution Order Instruction":
            orderinstruction()
        elif i == "All":
            uselimitConstraint()
            contact("resContact")
            contact("distContact")
            orderinstruction()
            contact("mdContact")

    # delete data quality and lineage section
    if dq:
        target_dq_elem = tree.findxmltag(metaTag['dataQuality'])
        if target_dq_elem is not None:
            meta.printit("# Delete Data Quality and Lineage...")
            tree_root.remove(target_dq_elem)

    if langcnty:
        deleteLangCntyCode()

    if revise:
        reviseDate()

    # update thumbnail
    thumbnail(image)

    # write updates to xml file
    tree.writeXml(xml_file)
예제 #2
0
            tempElem = attrElem.find(tag)
            if tempElem is None:
                childElem = meta.ET.Element(tag)
                attrElem.append(childElem)
            # set target field attribute desc
            attrElem.find(tag).text = source_attr.text


dataDictionary = collections.OrderedDict(dataDictionary)
source_metadata = arcpy.GetParameterAsText(0)
target_metadata = arcpy.GetParameterAsText(1)

skip_fields = ['objectid', 'shape', 'shape_length', 'shape_area']
sourceXML = xmlout(source_metadata)
targetXML = xmlout(target_metadata)
sourcetree = meta.xmlMeta(sourceXML)
targettree = meta.xmlMeta(targetXML)

source_attrElem = sourcetree.findxmltagAll(metaTag["eainfoattr"])
source_attrElem_dict = {
    elem.find(dataDictionary['fieldname']).text.lower(): elem
    for elem in source_attrElem
}

target_attrElem = targettree.findxmltagAll(metaTag["eainfoattr"])
target_attrElem_dict = {
    elem.find(dataDictionary['fieldname']).text: elem
    for elem in target_attrElem
}

for attrElem in target_attrElem:

sourcemetadata = arcpy.GetParameterAsText(0)
source_metadatas = sourcemetadata.split(";")
ws = arcpy.GetParameterAsText(1)
domaindefsource = arcpy.GetParameterAsText(2)

meta.setscratchWS()

edomaindicts, rdomaindicts = domainDict(ws)

for dataset in source_metadatas:
    dataset = dataset.replace("'", "")
    if arcpy.Exists(dataset):
        sourceXML = xmlout(dataset)
        sourcetree = meta.xmlMeta(sourceXML)
        desc = arcpy.Describe(dataset)
        fields = arcpy.ListFields(dataset)
        # dictionary - {field name lowercase: domain name lowercase}
        fieldswithedomain, fieldswithrdomain = {}, {}
        for field in fields:
            if field.domain.lower() in edomaindicts:
                fieldswithedomain[field.name.lower()] = field.domain.lower()
            elif field.domain.lower() in rdomaindicts:
                fieldswithrdomain[field.name.lower()] = field.domain.lower()

        # all attribute elements
        source_attrElem = sourcetree.findxmltagAll(metaTag["eainfoattr"])
        source_attrElem_dict = {
            elem.find(dataDictionary['fieldname']).text.lower(): elem
            for elem in source_attrElem
예제 #4
0
elemList = TEMPLATE.keys()

# create feature dataset list include root
for index, input_meta in enumerate(src_metas):
    input_meta = input_meta.replace("'", "")
    arcpy.AddMessage(" ")
    arcpy.AddMessage("{} of {}: {}".format(index + 1, len(src_metas),
                                           input_meta))
    # set arcpy Describe object from input
    inputdesc = arcpy.Describe(input_meta)

    arcpy.AddMessage("  # Process: Export Metadata")
    xml_file = xmlout(input_meta)

    # set xml tree element
    tree = meta.xmlMeta(xml_file)
    # root element
    root = tree.getroot()

    # ---- Process step contact ----#
    arcpy.AddMessage("  # Process: Add Process Steps")
    # input FC data quality element
    dq_elem = tree.findxmltag(metaTag['dataQuality'])

    if dq_elem is None:
        tree.addRootChildxmlTag(metaTag['dataQuality'])
        # add data quality element
        tree.findaddmissingxmltagNoPrint(metaTag['dataLineage'])
    else:
        # add data quality element
        tree.findaddmissingxmltagNoPrint(metaTag['dataLineage'])
creditsinput = arcpy.GetParameterAsText(5)
options = arcpy.GetParameterAsText(6)
dq = arcpy.GetParameter(7)
langcnty = arcpy.GetParameter(8)
revise = arcpy.GetParameter(9)
image = arcpy.GetParameterAsText(10)

option_list = options.split(";")

# set xml element from default xml template
# python script (current) directory
# https://stackoverflow.com/questions/3718657/how-to-properly-determine-current-script-directory-in-python
filename = inspect.getframeinfo(inspect.currentframe()).filename
pypath = os.path.dirname(os.path.abspath(filename))
default_xml = os.path.join(pypath, "Metadata_Template.xml")
default_tree = meta.xmlMeta(default_xml)
# temp_root = temp_tree.getroot()

# local variables
contacts = collections.OrderedDict(contacts)
contactsDesc = collections.OrderedDict(contactsDesc)

# disable geoprocessing history logging
arcpy.SetLogHistory(False)


def dataidinfoupdate(elementname, tag, textinput):
    if len(textinput) > 0:
        meta.printit("# {}...".format(elementname))
        tempTag = metaTag[tag]
        # find element