-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmetadata_test.py
125 lines (105 loc) · 3.82 KB
/
metadata_test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
from arcgis import features
from arcgis import mapping
import sys
from pathlib import Path
from arcpy import metadata as md
import os, shutil
import xml.dom.minidom as DOM
from arcgis import GIS
elmer_geo_conn_path = r'C:\Users\cpeak\OneDrive - Puget Sound Regional Council\Documents\ArcGIS\Projects\metadata_test\AWS-PROD-SQL.sde'
elmer_geo_conn_path = r'T:\2024May\cpeak\AWS-PROD-SQL.sde'
arcpy.env.workspace = f"{elmer_geo_conn_path}"
#aprx_path = r'C:\Users\scoe\Documents\publish_elmer_geo\elmer_geo\elmer_geo.aprx'
dataset = 'political'
centers = r"ElmerGeo.DBO.urban_centers"
#outdir = r'C:\Users\scoe\Documents\publish_elmer_geo\service_definitions'
centers_path = Path(elmer_geo_conn_path)/dataset/centers
# Set the standard-format metadata XML file's path
src_file_path = r'T:\2024May\cpeak\metadata.xml'
target_item_md = md.Metadata(centers_path)
target_item_md.isReadOnly
mdata = md.Metadata(centers_path)
dir(target_item_md)
target_item_md.credits
# Import and apply to target
if not target_item_md.isReadOnly:
target_item_md.importMetadata(src_file_path)
target_item_md.save()
target_item_md.synchronize('ALWAYS')
target_item_md.save()
print(f"target item updated")
target_item_md.importMetadata(src_file_path)
target_item_md.save()
target_item_md.synchronize('ALWAYS')
target_item_md.save()
target_item_md.synchronize()
target_item_md.xml
target_item_md.title
# loop through each dataset example
for dataset in arcpy.ListDatasets():
dataset_name = dataset.split(".")[2]
for fc in arcpy.ListFeatureClasses("*", "", dataset_name):
print(f"{dataset}, {fc}")
# create dict of datasets per feature classes
fc_dict = {}
for dataset in arcpy.ListDatasets():
dataset_name = dataset.split(".")[2]
for fc in arcpy.ListFeatureClasses("*", "", dataset_name):
fc_name = fc.split(".")[2]
fc_dict[fc_name] = dataset_name
metadata_path = Path('./workspace/metadata')
def get_dataset(layer):
try:
return(fc_dict[l])
except Exception as e:
return('nothing')
run_files = os.listdir(metadata_path)
src_file_path = r'.'
for f in run_files:
print(f"{metadata_path}\{f}")
run_files = os.listdir(metadata_path)
src_file_path = r'.'
for f in run_files:
l = f.replace('_metadata.xml','').lower()
dataset = get_dataset(l)
# print(f"layer {l} is in dataset {dataset}")
layer_path = Path(elmer_geo_conn_path)/dataset/l
target_item_md = md.Metadata(layer_path)
mdata_path = f"{metadata_path}\{f}"
new_md = md.Metadata(mdata_path)
target_item_md.copy(new_md)
target_item_md.save()
if l == 'block2000_nowater':
if not target_item_md.isReadOnly:
#target_item_md.importMetadata(src_file_path)
target_item_md.importMetadata(mdata_path)
target_item_md.save()
target_item_md.synchronize('ALWAYS')
target_item_md.save()
print(f"exported metadata for {l}")
else:
print(f"layer {l} is read-only")
new_md = md.Metadata('./workspace/metadata/safety_rest_area_metadata.xml')
print(new_md)
for f in run_files:
l = f.replace('_metadata.xml','').lower()
dataset = get_dataset(l)
# print(f"layer {l} is in dataset {dataset}")
layer_path = Path(elmer_geo_conn_path)/dataset/l
target_item_md = md.Metadata(layer_path)
if target_item_md.isReadOnly:
print(f"{l}: READONLY")
else:
print(f"{l}:not readonly")
username = arcpy.Describe(elmer_geo_conn_path).connectionProperties.user
conn_properties = arcpy.Describe(elmer_geo_conn_path).connectionProperties
conn_properties = arcpy.Describe(elmer_geo_conn_path)
print(conn_properties)
conn_properties.dataType
dir(conn_properties)
arcpy.ListUsers()
arcpy.Describe(elmer_geo_conn_path)
arcpy.ListUsers(arcpy.env.workspace)[0]
w = arcpy.env.workspace
for u in arcpy.ListUsers(w):
print(u)