File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Load diff This file was deleted.
Original file line number Diff line number Diff line change 1+ #!/usr/bin/env python3
2+ import os
3+ import sys
4+
5+ def parse_tool_versions (filepath ):
6+ tools = {}
7+ if not os .path .exists (filepath ):
8+ return tools
9+ with open (filepath , 'r' ) as f :
10+ for line in f :
11+ line = line .strip ()
12+ if not line or line .startswith ('#' ):
13+ continue
14+ parts = line .split ()
15+ if len (parts ) >= 2 :
16+ tools [parts [0 ]] = parts [1 ]
17+ return tools
18+
19+ def generate_a2ml_scm (tools ):
20+ lines = []
21+ lines .append ("(scm-dialect" )
22+ lines .append (" (metadata" )
23+ lines .append (" (schema-version \" 1.0\" )" )
24+ lines .append (" (generator \" opsm-mise-translator\" ))" )
25+ lines .append (" (dependencies" )
26+
27+ for tool , version in tools .items ():
28+ lines .append (f" (package (name \" { tool } \" ) (version \" { version } \" ) (provider \" mise\" ))" )
29+
30+ lines .append (" )" )
31+ lines .append (")" )
32+ return "\n " .join (lines )
33+
34+ def main ():
35+ if len (sys .argv ) < 3 :
36+ print ("Usage: mise_to_a2ml.py <path_to_tool_versions> <output_a2ml_path>" )
37+ sys .exit (1 )
38+
39+ input_file = sys .argv [1 ]
40+ output_file = sys .argv [2 ]
41+
42+ tools = parse_tool_versions (input_file )
43+ if not tools :
44+ print (f"No tools found or file missing: { input_file } " )
45+ sys .exit (0 )
46+
47+ a2ml_content = generate_a2ml_scm (tools )
48+
49+ with open (output_file , 'w' ) as f :
50+ f .write (a2ml_content )
51+
52+ print (f"Successfully translated { len (tools )} tools into A2ML SCM dialect at { output_file } " )
53+
54+ if __name__ == "__main__" :
55+ main ()
You can’t perform that action at this time.
0 commit comments