-
-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathmigrate_azure.py
More file actions
49 lines (39 loc) · 1.47 KB
/
migrate_azure.py
File metadata and controls
49 lines (39 loc) · 1.47 KB
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
#!/usr/bin/env python3
"""Migrate Azure option files from CliCommand to CliSubCommand."""
import os
import re
def migrate_file(filepath):
"""Migrate a single file from CliCommand to CliSubCommand."""
with open(filepath, 'r', encoding='utf-8-sig') as f:
content = f.read()
# Skip files that don't have CliCommand or already have CliSubCommand
if 'CliSubCommand' in content:
return False
if '[CliCommand(' not in content:
return False
# Skip base options file (AzOptions.cs) - it doesn't have CliCommand attribute
if 'AzOptions.cs' in filepath and ': CommandLineToolOptions' in content:
return False
# Replace [CliCommand(...)] with [CliSubCommand(...)]
new_content = re.sub(r'\[CliCommand\(', '[CliSubCommand(', content)
if new_content != content:
with open(filepath, 'w', encoding='utf-8') as f:
f.write(new_content)
return True
return False
def main():
options_dir = r'C:\git\ModularPipelines\src\ModularPipelines.Azure\Options'
migrated = 0
skipped = 0
for root, dirs, files in os.walk(options_dir):
for filename in files:
if filename.endswith('.cs'):
filepath = os.path.join(root, filename)
if migrate_file(filepath):
migrated += 1
else:
skipped += 1
print(f"Migrated: {migrated} files")
print(f"Skipped: {skipped} files")
if __name__ == '__main__':
main()