@@ -49,7 +49,7 @@ def fatal(text, error=1):
4949 version2schema = name2version2schema .setdefault (schema .name ,{})
5050 version2schema [schema .version ] = schema
5151
52- note ("selecting domains" )
52+ note ("selecting domains" , 1 )
5353domains = domain2name2version2schema .keys ()
5454note (f"onnx operator schemas have { len (domains )} domains: { ', ' .join (domains )} " ,2 )
5555if "all" in args .domains :
@@ -101,7 +101,7 @@ def fatal(text, error=1):
101101 for name in names :
102102 del domain2name2version2schema [domain ][name ]
103103
104- note ("selecting onnx operator schema versions" )
104+ note ("selecting onnx operator schema versions" , 1 )
105105delete_versions = {}
106106for domain , name2version2schema in domain2name2version2schema .items ():
107107 for name , version2schema in name2version2schema .items ():
@@ -134,6 +134,25 @@ def fatal(text, error=1):
134134 for schema in version2schema .values ():
135135 schemas .append (schema )
136136
137+ if args .list_domains or args .list_operators or args .list_versions :
138+ empty = True
139+ for domain , name2version2schema in domain2name2version2schema .items ():
140+ if args .list_domains :
141+ empty = False
142+ print (domain )
143+ for name , version2schema in name2version2schema .items ():
144+ if args .list_operators :
145+ empty = False
146+ print (f"{ domain } { name } " )
147+ for version in version2schema .keys ():
148+ if args .list_versions :
149+ empty = False
150+ print (f"{ domain } { name } { version } " )
151+ if empty :
152+ sys .exit (1 )
153+ else :
154+ sys .exit (0 )
155+
137156note ("generating onnx operator headers" )
138157path = f"{ args .path [- 1 ]} /{ args .header [- 1 ]} /"
139158headers = [ OperatorHeader .Header (s ,path ) for s in schemas ]
@@ -162,18 +181,39 @@ def fatal(text, error=1):
162181 files .extend (map (lambda x : (bool (args .force_info ),x ),info ))
163182
164183writecount = 0
184+ existcount = 0
185+ skipcount = 0
165186note ("Writing files" ,1 )
166187if not args .path [- 1 ]:
167188 warning ("skipping write because args.path is not set" )
168189else :
169190 for force ,obj in files :
170191 path = obj .filepath ()
171- if path .exists () and not (args .force or force ):
172- warning (f"skipping existing file '{ path } '" ,1 )
173- continue
174- note (f"writing file { path } " ,3 )
192+ overwrite = args .force or force
193+ if not overwrite :
194+ for pattern in args .force_pattern :
195+ if re .match (pattern ,str (path )):
196+ overwrite = True
197+ break
198+ skip = False
199+ for pattern in args .skip_pattern :
200+ if re .match (pattern ,str (path )):
201+ skip = True
202+ break
203+ if not overwrite :
204+ if path .exists ():
205+ existcount += 1
206+ warning (f"skipping existing file '{ path } '" ,2 )
207+ continue
208+ elif skip :
209+ skipcount += 1
210+ warning (f"skipping file '{ path } '" ,2 )
211+ continue
212+ note (f"writing file { path } " ,1 )
213+ else :
214+ warning (f"overwriting file { path } " ,1 )
175215 if not args .dryrun :
176216 os .makedirs (path .parent ,exist_ok = True )
177217 path .open ("w" ).write (str (obj ))
178218 writecount += 1
179- note (f"wrote { writecount } of { len (files )} files" )
219+ note (f"wrote { writecount } of { len (files )} files ( { existcount } already existed, { skipcount } skipped) " )
0 commit comments