Skip to content

Commit 99a56b8

Browse files
authored
Improvements to .NET metadata management scripts (#925)
* Simplified metadata process script * Fixed warning in readme copy * Added script for calling readme copy and metadata sync * Improvements to readme_copy * Status prints for sample_sync * Fixed issue with android layout relative filepaths * Fix for edge case with display device location * Previously unsynced local server readme change * Fixed Local server map image layer readme
1 parent b177bf3 commit 99a56b8

File tree

12 files changed

+101
-67
lines changed

12 files changed

+101
-67
lines changed

src/Android/Xamarin.Android/Samples/Location/DisplayDeviceLocation/readme.metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
"DisplayDeviceLocation.cs"
3434
],
3535
"title": "Display device location with autopan modes"
36-
}
36+
}

src/Forms/Shared/Samples/Location/DisplayDeviceLocation/readme.metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@
3737
"DisplayDeviceLocation.xaml.cs"
3838
],
3939
"title": "Display device location with autopan modes"
40-
}
40+
}

src/UWP/ArcGISRuntime.UWP.Viewer/Samples/Location/DisplayDeviceLocation/readme.metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
"DisplayDeviceLocation.xaml.cs"
3535
],
3636
"title": "Display device location with autopan modes"
37-
}
37+
}

src/WPF/ArcGISRuntime.WPF.Viewer/Samples/Local Server/LocalServerMapImageLayer/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ The Local Server and local map service will automatically be started and, once r
1717
1. Create and run a local server with `LocalServer.Instance`.
1818
2. Start the server asynchronously with `server.StartAsync()`.
1919
3. Create and run a local service, example of running a `LocalMapService`.
20-
1. Instantiate `LocalMapService(Url)` to create a local map service with the given URL path to the map package (`mpk` file).
20+
1. Instantiate `LocalMapService(Url)` to create a local map service with the given URL path to the map package (`mpkx` file).
2121
2. Start the service asynchronously with `LocalMapService.StartAsync()`. The service is added to the Local Server automatically.
2222
4. Create an ArcGIS map image layer from local map service.
2323
1. Create a `ArcGISMapImageLayer(Url)` from local map service url provided by the `LocalMapService.Url` property.
@@ -44,4 +44,4 @@ Local Server can be downloaded for Windows and Linux platforms from the [develop
4444

4545
## Tags
4646

47-
image, layer, local, offline, server
47+
image, layer, local, offline, server

src/WPF/ArcGISRuntime.WPF.Viewer/Samples/Location/DisplayDeviceLocation/readme.metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
"DisplayDeviceLocation.xaml.cs"
3535
],
3636
"title": "Display device location with autopan modes"
37-
}
37+
}

src/WinUI/ArcGISRuntime.WinUI.Viewer/Samples/Local Server/LocalServerMapImageLayer/readme.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ The Local Server and local map service will automatically be started and, once r
2323
1. Create a `ArcGISMapImageLayer(Url)` from local map service url provided by the `LocalMapService.Url` property.
2424
2. Add the layer to the map's operational layers.
2525
3. Wait for the layer to load with `await myImageLayer.LoadAsync()`
26-
4. Set the map view extent to the layer full extent.
26+
4. Set the map view's extent to the layer's full extent.
2727

2828
## Relevant API
2929

@@ -44,4 +44,4 @@ Local Server can be downloaded for Windows and Linux platforms from the [develop
4444

4545
## Tags
4646

47-
image, layer, local, offline, server
47+
image, layer, local, offline, server

src/WinUI/ArcGISRuntime.WinUI.Viewer/Samples/Location/DisplayDeviceLocation/readme.metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,4 @@
3434
"DisplayDeviceLocation.xaml.cs"
3535
],
3636
"title": "Display device location with autopan modes"
37-
}
37+
}

src/iOS/Xamarin.iOS/Samples/Location/DisplayDeviceLocation/readme.metadata.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@
3333
"DisplayDeviceLocation.cs"
3434
],
3535
"title": "Display device location with autopan modes"
36-
}
36+
}

tools/metadata_tools/process_metadata.py

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -193,26 +193,16 @@ def update_attribute(sample, sample_dir):
193193

194194
def main():
195195
'''
196-
Usage: python process_metadata.py {operation} {path_to_samples (ends in src)} {path_to_secondary}
197-
Operations: toc; secondary path is empty
198-
improve; secondary path is common readme
199-
attributes; keep attributes in code in sync with readme
200-
sync; keep metadata in sync with readme
196+
Usage: python process_metadata.py {path_to_samples (ends in src)} (optional)
197+
Location of script being run will be used for a relative path if path to samples is not specified.
201198
'''
202199

203-
if len(sys.argv) < 3:
204-
print("Usage: python process_metadata.py {operation} {path_to_samples (ends in src)} {path_to_secondary}")
205-
print("Operations are toc, improve, attributes, and sync; secondary path is path to common readme source for the improve operation.")
206-
return
207-
208-
operation = sys.argv[1]
209-
sample_root = sys.argv[2]
210-
common_dir_path = ""
211-
if operation == "improve":
212-
if len(sys.argv) < 4:
213-
print("Usage: python process_metadata.py improve {path_to_samples (ends in src)} {path_to_readme_source}")
214-
return
215-
common_dir_path = sys.argv[3]
200+
if len(sys.argv) < 2:
201+
# get the location of the samples relative to this script in the tools folder
202+
script_location = os.path.dirname(os.path.realpath(__file__))
203+
sample_root = os.path.abspath(os.path.join(script_location, "..", "..", "src"))
204+
else:
205+
sample_root = sys.argv[1]
216206

217207
for platform in ["UWP", "WPF", "Android", "Forms", "iOS", "FormsAR", "WinUI"]:
218208
# make a list of samples, so that build_all_csproj.bat can be produced
@@ -234,27 +224,28 @@ def main():
234224
if platform == "FormsAR":
235225
sample.category = "Augmented reality"
236226
sample.populate_snippets_from_folder(platform, path_to_readme)
237-
if operation == "improve":
238-
sample.try_replace_with_common_readme(platform, common_dir_path, path_to_readme)
239-
if operation in ["improve", "sync"]:
240-
# read existing packages from metadata
241-
path_to_json = os.path.join(r, sample_dir, "readme.metadata.json")
242-
if os.path.exists(path_to_json):
243-
metadata_based_sample = sample_metadata()
244-
metadata_based_sample.populate_from_json(path_to_json)
245-
sample.nuget_packages = metadata_based_sample.nuget_packages
246-
sample.resync_nuget_packages(platform)
247-
sample.flush_to_json(path_to_json)
248-
if operation == "attributes":
249-
update_attribute(sample, os.path.join(r, sample_dir))
227+
228+
# read existing packages from metadata
229+
path_to_json = os.path.join(r, sample_dir, "readme.metadata.json")
230+
if os.path.exists(path_to_json):
231+
metadata_based_sample = sample_metadata()
232+
metadata_based_sample.populate_from_json(path_to_json)
233+
sample.nuget_packages = metadata_based_sample.nuget_packages
234+
sample.resync_nuget_packages(platform)
235+
sample.flush_to_json(path_to_json)
236+
237+
# update attributes in the sample code files
238+
update_attribute(sample, os.path.join(r, sample_dir))
239+
250240
list_of_sample_dirs.append(sample_dir)
241+
251242
# track samples in each category to enable TOC generation
252243
if sample.category in list_of_samples.keys():
253244
list_of_samples[sample.category].append(sample)
254245
else:
255246
list_of_samples[sample.category] = [sample]
256247
# write out samples TOC
257-
if operation in ["toc", "improve", "sync"] and platform != "FormsAR":
248+
if platform != "FormsAR":
258249
write_samples_toc(get_platform_samples_root(platform, sample_root), get_relative_path_to_samples_from_platform_root(platform), list_of_samples)
259250
return
260251

tools/metadata_tools/sample_metadata.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,9 @@ def populate_from_readme(self, platform, path_to_readme):
108108
redirect_string = f"/net/latest/{real_platform.lower()}/sample-code/{self.formal_name.lower()}.htm"
109109
self.redirect_from.append(redirect_string)
110110

111+
if self.formal_name == "DisplayDeviceLocation":
112+
self.redirect_from.append(f"/net/{real_platform.lower()}/sample-code/display-device-location/")
113+
111114
# category is the name of the folder containing the sample folder
112115
self.category = pathparts[-3]
113116

@@ -424,7 +427,7 @@ def populate_snippets_from_folder(self, platform, path_to_readme):
424427
# populate files in the directory
425428
sample_dir = os.path.split(path_to_readme)[0]
426429
for file in os.listdir(sample_dir):
427-
if os.path.splitext(file)[1] in [".axml", ".xaml", ".cs"]:
430+
if os.path.splitext(file)[1] in [".axml", ".xaml", ".cs", ".xml"]:
428431
self.source_files.append(file)
429432
# populate AXML layouts for Android
430433
if platform == "Android" and os.path.splitext(file)[1] == ".cs":
@@ -444,10 +447,13 @@ def populate_snippets_from_folder(self, platform, path_to_readme):
444447
layout_name = line.split("Layout.")[1].strip().strip(";").strip(", null)")
445448
if layout_name is not None:
446449
# determine if the file ending is .xml
447-
if (os.path.exists(os.path.join("..", "..", "src", "Android", "Xamarin.Android", "Resources", "layout", f"{layout_name}.xml"))):
450+
if (os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "src", "Android", "Xamarin.Android", "Resources", "layout", f"{layout_name}.xml"))):
448451
ending = ".xml"
449-
else:
452+
elif (os.path.exists(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..", "..", "src", "Android", "Xamarin.Android", "Resources", "layout", f"{layout_name}.axml"))):
450453
ending = ".axml"
454+
else:
455+
print(f"Couldnt find layout file for sample {layout_name}")
456+
continue
451457
# add the file path to the snippets list
452458
self.source_files.append(f"../../../Resources/layout/{layout_name}{ending}")
453459
# Manually add JoystickSeekBar control on Android for AR only
@@ -469,7 +475,7 @@ def rewrite_files_in_place(source_dir, replacements_dict):
469475
for sample_file_name in f:
470476
sample_file_fullpath = os.path.join(r, sample_file_name)
471477
extension = os.path.splitext(sample_file_fullpath)[1]
472-
if extension in [".cs", ".xaml", ".sln", ".slntemplate", ".md", ".csproj", ".shproj", ".axml"]:
478+
if extension in [".cs", ".xaml", ".sln", ".slntemplate", ".md", ".csproj", ".shproj", ".axml", ".xml"]:
473479
# open file, read into string
474480
original_contents = safe_read_contents(sample_file_fullpath)
475481
# make replacements

0 commit comments

Comments
 (0)