Skip to content

Commit 879cd86

Browse files
committed
Add IronPPT & Version Check Support
1 parent 68f1ce0 commit 879cd86

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+13272
-48
lines changed

.vscode/launch.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@
1010
"request": "launch",
1111
"program": "${file}",
1212
"console": "integratedTerminal"
13+
},
14+
{
15+
"name": "check-apidocs",
16+
"type": "debugpy",
17+
"request": "launch",
18+
"program": "${workspaceFolder}/check-apidocs.py",
19+
"console": "integratedTerminal",
20+
"args": [
21+
"--product-code=ironpdfnodejs",
22+
"--latest-version",
23+
"--docs-exists"
24+
]
1325
}
1426
]
1527
}

__pycache__/apidocs.cpython-312.pyc

6.34 KB
Binary file not shown.
2.96 KB
Binary file not shown.

apidocs.py

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import requests, json, re
2+
import os
3+
4+
NUGET_ENDPOINT_FORMAT = "https://api-v2v3search-0.nuget.org/query?q=packageid:{}"
5+
MAVEN_ENDPOINT_FORMAT = "https://search.maven.org/solrsearch/select?q=g:{groupId}+AND+a:{artifactId}&core=gav&rows=1000&wt=json"
6+
NPM_ENDPOINT_FORMAT = "https://registry.npmjs.org/{package_name}"
7+
PYPI_ENDPOINT_FORMAT = "https://pypi.org/pypi/{package_name}/json"
8+
PRODUCTS_CATALOG = os.path.join(os.path.dirname(os.path.abspath(__file__)), "iron-products.json")
9+
APIDOCS_STORAGE_PATH = os.path.join(os.path.dirname(os.path.abspath(__file__)), "object-reference")
10+
APIDOCS_DESTINATION_PATH_TEMPLATE = APIDOCS_STORAGE_PATH + os.path.sep + "{}" + os.path.sep + "{}"
11+
12+
def get_apidoc_path(info:dict, version_string:str) -> str:
13+
destination_path = APIDOCS_DESTINATION_PATH_TEMPLATE.format(info["code"], version_string)
14+
return destination_path
15+
16+
def apidoc_already_exists(info:dict, version_string:str) -> bool:
17+
destination_path = get_apidoc_path(info, version_string)
18+
return os.path.exists(destination_path)
19+
20+
def get_maven_package_versions(group_id:str, artifact_id:str) -> dict:
21+
response = requests.get(url=MAVEN_ENDPOINT_FORMAT.format(groupId = group_id, artifactId = artifact_id))
22+
data = response.json()
23+
versions = data["response"]["docs"];
24+
return versions;
25+
26+
def get_pip_package_versions(package_name:str) -> dict:
27+
response = requests.get(url=PYPI_ENDPOINT_FORMAT.format(package_name = package_name))
28+
data = response.json()
29+
versions = data["releases"];
30+
return versions;
31+
32+
33+
def get_npm_package_versions(package_name:str) -> dict:
34+
response = requests.get(url=NPM_ENDPOINT_FORMAT.format(package_name = package_name))
35+
data = response.json()
36+
versions = data["versions"];
37+
return versions;
38+
39+
def get_nuget_package_versions(package:str) -> dict:
40+
response = requests.get(url=NUGET_ENDPOINT_FORMAT.format(package))
41+
data = response.json()
42+
versions = data["data"][0]["versions"];
43+
return versions;
44+
45+
def query_product_info(product_code:str, product_name:str=None) -> dict|None:
46+
selected_product=None
47+
package_versions=None
48+
latest_version=None
49+
with open(PRODUCTS_CATALOG, 'r') as file:
50+
products = json.load(file)
51+
52+
53+
for product in products["libraries"]:
54+
if product["code"] == product_code or (product_name is not None and product["name"] == product_name):
55+
selected_product = product
56+
break
57+
58+
if selected_product is not None:
59+
if selected_product["packageType"] == "nuget":
60+
package_versions = get_nuget_package_versions(selected_product["packageName"])
61+
elif product["packageType"] == "maven":
62+
package_versions = get_maven_package_versions(selected_product["groupId"], selected_product["artifactId"])
63+
elif product["packageType"] == "pip":
64+
package_versions = get_pip_package_versions(selected_product["packageName"])
65+
elif product["packageType"] == "npm":
66+
package_versions = get_npm_package_versions(selected_product["packageName"])
67+
68+
if len(package_versions) > 0:
69+
if selected_product["packageType"] == "pip" or selected_product["packageType"] == "npm":
70+
versions = list(package_versions.keys())
71+
latest_version = package_versions[versions[-1]]
72+
if selected_product["packageType"] == "pip":
73+
latest_version = latest_version[0]
74+
if "version" not in latest_version.keys():
75+
latest_version["version"] = versions[-1]
76+
product_versions = []
77+
for version in versions:
78+
package_version = package_versions[version]
79+
if selected_product["packageType"] == "pip":
80+
package_version = package_version[0]
81+
package_version["version"] = version
82+
product_versions.append(package_version)
83+
package_versions = product_versions
84+
elif selected_product["packageType"] == "maven":
85+
latest_version = package_versions[0]
86+
else:
87+
latest_version = package_versions[-1]
88+
89+
return {"product": selected_product, "available_versions": package_versions, "latest_version": latest_version}
90+
91+
def get_product_version(product_data:dict, version:str = "", get_latest_version:bool = True) -> str:
92+
version="N/A"
93+
if get_latest_version:
94+
if product_data["product"]["packageType"] == "maven":
95+
version = product_data["latest_version"]["v"]
96+
else:
97+
version = product_data["latest_version"]["version"]
98+
elif version != "":
99+
for product in product_data['available_versions']:
100+
if product_data["product"]["packageType"] == "maven":
101+
version = product["v"]
102+
else:
103+
version = product["version"]
104+
return version
105+
106+
def check_if_product_and_version_exists(product_data:dict, product_version:str)-> bool:
107+
exists = False
108+
for product in product_data["available_versions"]:
109+
version = ""
110+
if product_data["product"]["packageType"] == "maven":
111+
version = product["v"]
112+
else:
113+
version = product["version"]
114+
if version == product_version:
115+
exists = apidoc_already_exists(product_data["product"], product_version)
116+
break
117+
return exists

check-apidocs.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import shutil, subprocess, sys, os, getopt, re, json
2+
from apidocs import *
3+
from statuslogger import *
4+
5+
6+
def main(arguments):
7+
product_code = None
8+
product_name = None
9+
version = None
10+
get_latest_version = False
11+
check_if_exists = False
12+
13+
opts, args = getopt.getopt(arguments, "p:n:v:Va", ["product-code=", "product-name=", "version=", "latest-version", "docs-exists"])
14+
for opt, arg in opts:
15+
if opt in ("-p", "--product-code"):
16+
product_code = arg
17+
elif opt in ("-n", "--product-name"):
18+
product_name = arg
19+
elif opt in ("-v", "--version"):
20+
version = arg
21+
elif opt in ("-V", "--latest-version"):
22+
get_latest_version = True
23+
elif opt in ("-a", "--docs-exists"):
24+
check_if_exists = True
25+
26+
if product_code is None and product_name is None:
27+
StatusLogger.error("Please specify product code or product name (-p , --product-code|-n, --product-name)")
28+
exit(1)
29+
else:
30+
product_data = query_product_info(product_code, product_name)
31+
if product_data['product'] is None:
32+
StatusLogger.error("Specified product does not exist")
33+
exit(1)
34+
else:
35+
output = ""
36+
name = product_data["product"]["name"]
37+
output += f"Name: {name}\n"
38+
product_version = get_product_version(product_data, version, get_latest_version)
39+
output += f"Version: {product_version}\n"
40+
if check_if_exists:
41+
docs_exists = check_if_product_and_version_exists(product_data, product_version)
42+
output += f"API Docs Built: {str(docs_exists)}\n"
43+
if docs_exists:
44+
docs_path = get_apidoc_path(product_data["product"], product_version)
45+
output += f"API Docs Path: {docs_path}"
46+
print(output)
47+
if __name__ == "__main__":
48+
main(sys.argv[1:])

iron-products.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,16 @@
2121
{
2222
"name": "IronPDF for Python",
2323
"code": "ironpdfpython",
24+
"packageName": "IronPdf",
2425
"packageType": "pip",
26+
"packageUrl": "https://pypi.org/project/IronPdf/",
2527
"domain": "ironpdf.com",
2628
"path": "/python"
2729
},
2830
{
2931
"name": "IronPDF for Node.js",
3032
"code": "ironpdfnodejs",
33+
"packageName": "@ironsoftware/ironpdf",
3134
"packageType": "npm",
3235
"domain": "ironpdf.com",
3336
"path": "/nodejs"
@@ -59,6 +62,15 @@
5962
"domain": "ironsoftware.com",
6063
"path": "/csharp/word"
6164
},
65+
{
66+
"name": "IronPPT",
67+
"code": "ironppt",
68+
"packageType": "nuget",
69+
"packageName": "IronPPT",
70+
"packageUrl": "https://www.nuget.org/packages/IronPPT/",
71+
"domain": "ironsoftware.com",
72+
"path": "/csharp/ppt"
73+
},
6274
{
6375
"name": "IronZIP",
6476
"code": "ironzip",
@@ -77,6 +89,15 @@
7789
"domain": "ironsoftware.com",
7890
"path": "/csharp/excel"
7991
},
92+
{
93+
"name": "IronXL for Python",
94+
"code": "ironxlpython",
95+
"packageType": "pip",
96+
"packageName": "IronXL",
97+
"packageUrl": "https://pypi.org/project/IronXL/",
98+
"domain": "ironsoftware.com",
99+
"path": "/python/excel"
100+
},
80101
{
81102
"name": "IronPrint",
82103
"code": "ironprint",

0 commit comments

Comments
 (0)