Repository navigation
Expand file tree
/
Copy pathpush_to_github.py
More file actions
115 lines (100 loc) · 4.75 KB
/
Copy pathpush_to_github.py
File metadata and controls
115 lines (100 loc) · 4.75 KB
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import os
import base64
import httpx
import sys
GITHUB_USERNAME = "joelcabraham06"
REPO_NAME = "AetherOS"
PROJECT_DIR = os.path.dirname(os.path.abspath(__file__)) if '__file__' in globals() else os.getcwd()
IGNORE_DIRS = {".git", "__pycache__", "node_modules", ".venv", "venv"}
IGNORE_FILES = {".DS_Store"}
def is_ignored(path):
rel_path = os.path.relpath(path, PROJECT_DIR)
parts = rel_path.split(os.sep)
for part in parts:
if part in IGNORE_DIRS or part in IGNORE_FILES:
return True
return False
def get_all_files():
files_to_upload = []
for root, dirs, files in os.walk(PROJECT_DIR):
dirs[:] = [d for d in dirs if d not in IGNORE_DIRS]
for f in files:
full_path = os.path.join(root, f)
if not is_ignored(full_path):
rel_path = os.path.relpath(full_path, PROJECT_DIR).replace("\\", "/")
files_to_upload.append((full_path, rel_path))
return files_to_upload
def upload_to_github(pat_token):
headers = {
"Authorization": f"Bearer {pat_token}",
"Accept": "application/vnd.github+json",
"X-GitHub-Api-Version": "2022-11-28"
}
files = get_all_files()
print(f"Found {len(files)} files to upload to https://github.com/{GITHUB_USERNAME}/{REPO_NAME}...", flush=True)
with httpx.Client(timeout=30.0, follow_redirects=True) as client:
# Step 1: Ensure repository exists
repo_res = client.get(f"https://api.github.com/repos/{GITHUB_USERNAME}/{REPO_NAME}", headers=headers)
if repo_res.status_code == 404:
print(f"Creating repository {GITHUB_USERNAME}/{REPO_NAME}...", flush=True)
create_payload = {
"name": REPO_NAME,
"description": "⚡ AetherOS - Live Real-Time Web Operating System & Kernel Simulator (POSIX VFS, Virtual Memory, CPU Scheduler, Gantt Chart, Desktop WM).",
"private": False,
"auto_init": True
}
create_res = client.post("https://api.github.com/user/repos", headers=headers, json=create_payload)
if create_res.status_code in (200, 201):
print(f"[OK] Created repository {GITHUB_USERNAME}/{REPO_NAME}!", flush=True)
else:
print(f"[FAIL] Error creating repo: {create_res.status_code} - {create_res.text}", flush=True)
return False
# Step 2: Upload Files
success_count = 0
fail_count = 0
for full_path, rel_path in files:
try:
with open(full_path, "rb") as fp:
content_bytes = fp.read()
content_b64 = base64.b64encode(content_bytes).decode("utf-8")
url = f"https://api.github.com/repos/{GITHUB_USERNAME}/{REPO_NAME}/contents/{rel_path}"
get_res = client.get(url, headers=headers)
sha = None
if get_res.status_code == 200:
sha = get_res.json().get("sha")
payload = {
"message": f"Add/Update {rel_path} via AetherOS Deployer",
"content": content_b64,
"branch": "main"
}
if sha:
payload["sha"] = sha
put_res = client.put(url, headers=headers, json=payload)
if put_res.status_code in (200, 201):
print(f"[OK] Uploaded: {rel_path}", flush=True)
success_count += 1
else:
print(f"[FAIL] Failed: {rel_path} ({put_res.status_code}: {put_res.text})", flush=True)
fail_count += 1
except Exception as e:
print(f"[FAIL] Error uploading {rel_path}: {e}", flush=True)
fail_count += 1
# Step 3: Update topics & metadata
topics_payload = {
"names": [
"operating-system", "web-os", "kernel-simulator",
"javascript", "cpu-scheduler", "virtual-file-system",
"memory-management", "gantt-chart", "desktop-environment"
]
}
client.put(f"https://api.github.com/repos/{GITHUB_USERNAME}/{REPO_NAME}/topics", headers=headers, json=topics_payload)
print(f"\n==========================================", flush=True)
print(f"Upload Complete! {success_count} succeeded, {fail_count} failed.", flush=True)
print(f"Repository: https://github.com/{GITHUB_USERNAME}/{REPO_NAME}", flush=True)
print(f"==========================================\n", flush=True)
return fail_count == 0
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python push_to_github.py <PAT_TOKEN>")
sys.exit(1)
upload_to_github(sys.argv[1])