-
Notifications
You must be signed in to change notification settings - Fork 149
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
196 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import os | ||
import yaml | ||
from pathlib import Path | ||
from typing import Tuple, Optional | ||
import git | ||
from git import RemoteProgress | ||
|
||
# TODO add env var to set this | ||
REMOTES_DIR = os.path.join(os.path.dirname(__file__), "remotes") | ||
REMOTE_CONFIG = os.path.join(os.path.dirname(__file__), "modules_remote.yml") | ||
|
||
|
||
class CloneProgress(RemoteProgress): | ||
def update(self, op_code, cur_count, max_count=None, message=''): | ||
if message: | ||
print(message) | ||
|
||
|
||
def ensure_dir(d, chmod=0o777): | ||
""" | ||
Ensures a folder exists. | ||
Returns True if the folder already exists | ||
""" | ||
if not os.path.exists(d): | ||
os.makedirs(d, chmod) | ||
os.chmod(d, chmod) | ||
return False | ||
return True | ||
|
||
|
||
def read_remotes(): | ||
if not os.path.isfile(REMOTE_CONFIG): | ||
raise Exception(f"Error: Remotes config file not found: {REMOTE_CONFIG}") | ||
with open(REMOTE_CONFIG,'r') as f: | ||
output = yaml.safe_load(f) | ||
return output | ||
|
||
def get_remote_module(module: str) -> Tuple[bool, Optional[str]]: | ||
""" Gets the remote module and saves it to cache. Returns True if found, else false""" | ||
print(f"INFO: Module {module}, looking for remote module and downloading") | ||
modules_remotes = read_remotes() | ||
print(modules_remotes.keys()) | ||
|
||
if "modules" not in modules_remotes.keys() and module not in modules_remotes["modules"].keys(): | ||
return False, None | ||
|
||
ensure_dir(REMOTES_DIR) | ||
|
||
if "remotes" not in modules_remotes.keys() and module not in modules_remotes["modules"].keys(): | ||
return False, None | ||
|
||
module_config = modules_remotes["modules"][module] | ||
|
||
remote_for_module = module_config["remote"] | ||
remote_config = modules_remotes["remotes"][remote_for_module] | ||
|
||
if remote_config.get("type", "git") == "git": | ||
if "repo" not in remote_config.keys(): | ||
print(f"Error: repo field not set for remote: {remote_for_module} used by remote module {module}") | ||
return False, None | ||
|
||
if "tag" not in remote_config.keys(): | ||
print(f"Error: repo tag field not set for remote: {remote_for_module} used by remote module {module}") | ||
return False, None | ||
|
||
repo_url = remote_config["repo"] | ||
branch = remote_config["tag"] | ||
|
||
# credentials = base64.b64encode(f"{GHE_TOKEN}:".encode("latin-1")).decode("latin-1") | ||
# TODO: Handle update of remote | ||
remote_to_path = os.path.join(REMOTES_DIR, remote_for_module) | ||
if not os.path.exists(remote_to_path): | ||
git.Repo.clone_from( | ||
url=repo_url, | ||
single_branch=True, | ||
depth=1, | ||
to_path=f"{remote_to_path}", | ||
branch=branch, | ||
) | ||
|
||
if "path" not in module_config.keys(): | ||
print(f"Error: repo tag field not set for remote: {remote_for_module} used by remote module {module}") | ||
return False, None | ||
module_path = os.path.join(remote_to_path, module_config["path"]) | ||
return True, module_path | ||
|
||
else: | ||
print(f"Error: unsupported type {modules_remotes[module]['type']} for module {module}") | ||
return False, None | ||
return False, None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
modules: | ||
armbian: | ||
remote: MainsailOS | ||
path: src/modules/armbian | ||
|
||
armbian_net: | ||
remote: MainsailOS | ||
path: src/modules/armbian_net | ||
|
||
crowsnest: | ||
remote: MainsailOS | ||
path: src/modules/crowsnest | ||
|
||
is_req_preinstall: | ||
remote: MainsailOS | ||
path: src/modules/is_req_preinstall | ||
|
||
klipper: | ||
remote: MainsailOS | ||
path: src/modules/klipper | ||
|
||
mainsail: | ||
remote: MainsailOS | ||
path: src/modules/mainsail | ||
|
||
mainsailos: | ||
remote: MainsailOS | ||
path: src/modules/mainsailos | ||
|
||
moonraker: | ||
remote: MainsailOS | ||
path: src/modules/moonraker | ||
|
||
orangepi: | ||
remote: MainsailOS | ||
path: src/modules/orangepi | ||
|
||
orangepi_net: | ||
remote: MainsailOS | ||
path: src/modules/orangepi_net | ||
|
||
piconfig: | ||
remote: MainsailOS | ||
path: src/modules/piconfig | ||
|
||
postrename: | ||
remote: MainsailOS | ||
path: src/modules/postrename | ||
|
||
sonar: | ||
remote: MainsailOS | ||
path: src/modules/sonar | ||
|
||
timelapse: | ||
remote: MainsailOS | ||
path: src/modules/timelapse | ||
|
||
udev_fix: | ||
remote: MainsailOS | ||
path: src/modules/udev_fix | ||
|
||
remotes: | ||
MainsailOS: | ||
repo: https://github.com/mainsail-crew/MainsailOS.git | ||
type: git | ||
tag: develop |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
GitPython |