simple change

This commit is contained in:
2024-05-20 19:48:17 +02:00
parent 049a6904b0
commit e27aa595d2
2 changed files with 26 additions and 3 deletions
+5
View File
@@ -0,0 +1,5 @@
dist/
build/
lib/
package.json
main.spec
+21 -3
View File
@@ -1,10 +1,13 @@
import urllib import urllib
import urllib.parse
import requests import requests
import os import os
from json import dump
import shutil import shutil
import zipfile import zipfile
from sys import argv from sys import argv
from urllib.parse import urlparse from urllib.parse import urlparse
import re
def extract(zip_file, pkgName): def extract(zip_file, pkgName):
os.makedirs("tmp", exist_ok=True) os.makedirs("tmp", exist_ok=True)
@@ -25,9 +28,7 @@ def downloadRelease(pkgName, repo, tag):
headers={"Accept": "application/vnd.github+json"}).json()['tag_name'] headers={"Accept": "application/vnd.github+json"}).json()['tag_name']
url = os.path.join(repo, f'archive/refs/tags/{tag}.zip') url = os.path.join(repo, f'archive/refs/tags/{tag}.zip')
urllib.request.urlretrieve(url, "temp.zip") urllib.request.urlretrieve(url, "temp.zip")
input_zip_path = 'temp.zip' extract('temp.zip', pkgName)
new_folder_name = pkgName
extract(input_zip_path, new_folder_name)
os.remove('temp.zip') os.remove('temp.zip')
def installPackage(packageName, packageVersion='latest'): def installPackage(packageName, packageVersion='latest'):
@@ -42,6 +43,14 @@ def installPackage(packageName, packageVersion='latest'):
print(f'Error ({packageName}): {data["message"]}') print(f'Error ({packageName}): {data["message"]}')
quit(1) quit(1)
def verify_repo(n) -> str:
re_match = re.match(r'^https://(github.com)/[a-zA-Z0-9\-]+/[a-zA-Z0-9\-]+', n)
if re_match:
return str(re_match.group())
else:
print(f'Error: invalid repo')
quit(1)
if __name__=="__main__": if __name__=="__main__":
argl = len(argv) argl = len(argv)
if argl > 1: if argl > 1:
@@ -54,4 +63,13 @@ if __name__=="__main__":
installPackage(package[0], package[1]) installPackage(package[0], package[1])
else: else:
installPackage(pkg) installPackage(pkg)
case "init":
pkg_json = {
'name': str(os.getcwd().split('/')[-1].split('\\')[-1]),
'repo': verify_repo(input("link to the repository (required) "))
}
if not os.path.exists:
os.mkdir("lib")
with open('package.json', 'w')as f:
dump(pkg_json, f)
case _:... case _:...