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
7+
8+ # If adding a third-party library here, check CI workflows Python files
9+ # that are dependant on this and require pip install.
710
811# path
912utils_path = Path (__file__ ).resolve ()
1720# constants
1821id_name = "ID"
1922language_name = "Language"
20- 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+ )
2135etag = "ETag"
2236version = "Version"
2337url_sourcecode = "UrlSourceCode"
3044github_url = "https://github.com"
3145release_date = "LatestReleaseDate"
3246date_added = "DateAdded"
47+ website = "Website"
3348
3449# typing
3550PluginType = Dict [str , str ]
@@ -51,12 +66,20 @@ def plugin_reader() -> P:
5166
5267 return manifests
5368
69+
70+ def save_plugins_json_file (content : list [dict [str ]]) -> None :
71+ with open ("plugins.json" , "w" , encoding = "utf-8" ) as f :
72+ json .dump (content , f , indent = 4 , ensure_ascii = False )
73+
74+
5475def get_plugin_file_paths () -> list [str ]:
5576 return [os .path .join (plugin_dir , filename ) for filename in get_plugin_filenames ()]
5677
78+
5779def get_plugin_filenames () -> list [str ]:
5880 return os .listdir (plugin_dir )
5981
82+
6083def etag_reader () -> ETagsType :
6184 with open (etag_file , "r" , encoding = "utf-8" ) as f :
6285 return json .load (f )
@@ -66,7 +89,8 @@ def plugin_writer(content: P):
6689 for plugin in content :
6790 with open (plugin_dir / f"{ plugin [plugin_name ]} -{ plugin [id_name ]} .json" , "w" , encoding = "utf-8" ) as f :
6891 json .dump (plugin , f , indent = 4 )
69-
92+
93+
7094def etags_writer (content : ETagsType ):
7195 with open (etag_file , "w" , encoding = "utf-8" ) as f :
7296 json .dump (content , f , indent = 4 )
@@ -75,10 +99,12 @@ def etags_writer(content: ETagsType):
7599def clean (string : str , flag = "-" ) -> str :
76100 return string .lower ().replace (flag , "" ).strip ()
77101
102+
78103def version_tuple (version : str ) -> tuple :
79104 version = clean (version , "v" )
80105 return tuple (version .split ("." ))
81106
107+
82108def check_url (url : str ) -> bool :
83109 regex = re .compile (
84110 r"^(?:http|ftp)s?://" # http:// or https://
@@ -100,3 +126,19 @@ def get_file_plugins_json_info(required_key: str = "") -> list[dict[str, str]]:
100126 return data
101127
102128 return [{required_key : plugin [required_key ]} for plugin in data ]
129+
130+
131+ def get_new_plugin_submission_ids () -> list [str ]:
132+ plugins_json_ids = [item ["ID" ] for item in get_file_plugins_json_info ("ID" )]
133+ existing_plugin_file_ids = [info ["ID" ] for info in plugin_reader ()]
134+
135+ new_ids = []
136+
137+ for id in existing_plugin_file_ids :
138+ # plugins.json would not contain new submission's ID.
139+ if id in plugins_json_ids :
140+ continue
141+
142+ new_ids .append (id )
143+
144+ return new_ids
0 commit comments