-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathore.py
58 lines (50 loc) · 1.91 KB
/
ore.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# Ore v0.2 - A package manager for Oranje
import os
import sys
import time
import fire
import shutil
import zipfile
import requests
import tempfile
import itertools
import threading
from tqdm import tqdm
ANIMATE = False
ANIMATE_TEXT = "Working Online"
TEMP = tempfile.gettempdir()
PROGRAM_DIR = os.path.dirname(os.path.realpath(__file__))
cycle = ['[ ]', '[= ]', '[== ]', '[=== ]', '[ ===]', '[ ==]', '[ =]']
def loadingAnimator():
global ANIMATE, ANIMATE_TEXT, cycle
for state in itertools.cycle(cycle):
if ANIMATE:
sys.stdout.write(f'\r{ANIMATE_TEXT} ' + state)
sys.stdout.flush()
time.sleep(0.1)
sys.stdout.write('\r')
class Ore:
animationThread = threading.Thread(target=loadingAnimator)
animationThread.daemon = True
animationThread.start()
def install(self, repo="whmsft/oranje", branch="main", dir=""):
global ANIMATE, ANIMATE_TEXT, animationThread
ANIMATE = True
url = f'https://github.com/{repo}/archive/refs/heads/{branch}.zip'
filename = f'{TEMP}/{repo.split("/")[1]}.zip'
response = requests.get(url, stream=True)
file_size = int(response.headers.get("Content-Length", 0))
ANIMATE = False
with open(filename, "wb") as f:
with tqdm(total=file_size, unit="B", unit_scale=True, unit_divisor=1024) as progress:
for chunk in response.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
progress.update(len(chunk))
with zipfile.ZipFile(filename) as archive:
archive.extractall(f'{TEMP}/{repo}')
shutil.rmtree(f'{PROGRAM_DIR}/package/{repo}/')
shutil.copytree(f'{TEMP}/{repo}/{repo.split("/")[1].lower()}-{branch}/{dir}', f'{PROGRAM_DIR}/package/{repo}/')
print(f"\nSuccessfully Installed {repo} from GitHub")
if __name__ == "__main__":
fire.Fire(Ore)