11# -*-coding: utf-8 -*-
22import json
3+ import os
4+ import re
35from pathlib import Path
46from typing import Dict , List , TypeVar
5- import re
6- import os
77
88# If adding a third-party library here, check CI workflows Python files
99# that are dependant on this and require pip install.
2020# constants
2121id_name = "ID"
2222language_name = "Language"
23- language_list = ("csharp" , "executable" , "fsharp" , "python" , "javascript" , "typescript" , "python_v2" , "executable_v2" , "javascript_v2" , "typescript_v2" )
23+ language_list = (
24+ "csharp" ,
25+ "executable" ,
26+ "fsharp" ,
27+ "python" ,
28+ "javascript" ,
29+ "typescript" ,
30+ "python_v2" ,
31+ "executable_v2" ,
32+ "javascript_v2" ,
33+ "typescript_v2" ,
34+ )
2435etag = "ETag"
2536version = "Version"
2637url_sourcecode = "UrlSourceCode"
@@ -54,16 +65,20 @@ def plugin_reader() -> P:
5465
5566 return manifests
5667
68+
5769def save_plugins_json_file (content : list [dict [str ]]) -> None :
5870 with open ("plugins.json" , "w" , encoding = "utf-8" ) as f :
5971 json .dump (content , f , indent = 4 , ensure_ascii = False )
6072
73+
6174def get_plugin_file_paths () -> list [str ]:
6275 return [os .path .join (plugin_dir , filename ) for filename in get_plugin_filenames ()]
6376
77+
6478def get_plugin_filenames () -> list [str ]:
6579 return os .listdir (plugin_dir )
6680
81+
6782def etag_reader () -> ETagsType :
6883 with open (etag_file , "r" , encoding = "utf-8" ) as f :
6984 return json .load (f )
@@ -74,6 +89,7 @@ def plugin_writer(content: P):
7489 with open (plugin_dir / f"{ plugin [plugin_name ]} -{ plugin [id_name ]} .json" , "w" , encoding = "utf-8" ) as f :
7590 json .dump (plugin , f , indent = 4 )
7691
92+
7793def etags_writer (content : ETagsType ):
7894 with open (etag_file , "w" , encoding = "utf-8" ) as f :
7995 json .dump (content , f , indent = 4 )
@@ -82,10 +98,12 @@ def etags_writer(content: ETagsType):
8298def clean (string : str , flag = "-" ) -> str :
8399 return string .lower ().replace (flag , "" ).strip ()
84100
101+
85102def version_tuple (version : str ) -> tuple :
86103 version = clean (version , "v" )
87104 return tuple (version .split ("." ))
88105
106+
89107def check_url (url : str ) -> bool :
90108 regex = re .compile (
91109 r"^(?:http|ftp)s?://" # http:// or https://
@@ -108,6 +126,7 @@ def get_file_plugins_json_info(required_key: str = "") -> list[dict[str, str]]:
108126
109127 return [{required_key : plugin [required_key ]} for plugin in data ]
110128
129+
111130def get_new_plugin_submission_ids () -> list [str ]:
112131 plugins_json_ids = [item ["ID" ] for item in get_file_plugins_json_info ("ID" )]
113132 existing_plugin_file_ids = [info ["ID" ] for info in plugin_reader ()]
0 commit comments