Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

issue #64 - correct script fetcher to new metadata format in core-scr… #65

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,12 @@ def add_arguments(self, parser):
def handle(self, *args, **options):
repo_url = "https://github.com/OS2borgerPC/os2borgerpc-core-scripts.git"
self.stdout.write(f"Fetching scripts from {repo_url} repository...")
scripts = fetch_scripts("https://github.com/OS2borgerPC/os2borgerpc-core-scripts.git", options['versionTag'], options['commitHash'])
scripts = fetch_scripts(repo_url, options['versionTag'], options['commitHash'])

for script in scripts:
versionedName = script.title + " " + options['versionTag']
uid = script.metadata.get("uid", None)
is_security_script = script.metadata.get("security", False)
is_hidden = script.metadata.get("hidden", False)
versionedName = f'{script.title} (version: {script.version})'

if uid and Script.objects.filter(uid=uid).exists():
if script.uid and Script.objects.filter(uid=script.uid).exists():
Script.objects.filter(uid=uid).delete()

if not Script.objects.filter(name=versionedName).exists():
Expand All @@ -40,11 +37,11 @@ def handle(self, *args, **options):
description=script.description,
site=None, # None means global script
executable_code=django.core.files.File(file),
is_security_script=is_security_script,
is_hidden=is_hidden,
is_security_script=script.security,
is_hidden=script.hidden,
maintained_by_magenta=False,
feature_permission=None,
uid=uid
uid=script.uid
)
tag, created = ScriptTag.objects.get_or_create(name=script.tag)
db_script.tags.add(tag)
Expand Down
18 changes: 8 additions & 10 deletions admin_site/system/script_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ def fetch_scripts(repoUrl, versionTag, commitHash):

return scripts

@dataclass
class Metadata:
uid: Optional[str]
security: Optional[bool]
hidden: Optional[bool]

@dataclass
class Parameter:
Expand All @@ -82,15 +77,18 @@ class Parameter:
@dataclass
class Script:
title: str
version: str
parent: str
sourcePath: str
compatible_versions: Optional[str]
compatible_images: List[str]
description: str
tag: str
partners: Optional[str]
hidden: Optional[bool]
security: Optional[bool]
uid: Optional[str]
parameters: List[Parameter] = field(default_factory=list)
metadata: Optional[Metadata] = None

def parse_md_to_script(content: str, clone_path: Path) -> Script:
# Split YAML and Markdown content
Expand All @@ -101,9 +99,6 @@ def parse_md_to_script(content: str, clone_path: Path) -> Script:
# Parse the YAML content
yaml_content = yaml.safe_load(yaml_string)

# Parse metadata
metadata_content = yaml_content.get('metadata', {})

# Parse parameters
params = yaml_content.get('parameters', [])
params = params if params is not None else []
Expand All @@ -121,6 +116,7 @@ def parse_md_to_script(content: str, clone_path: Path) -> Script:

return Script(
title=yaml_content.get('title'),
version=yaml_content.get('version'),
parent=yaml_content.get('parent'),
sourcePath=str(clone_path / yaml_content.get('source')),
compatible_versions=yaml_content.get('compatible_versions'),
Expand All @@ -129,7 +125,9 @@ def parse_md_to_script(content: str, clone_path: Path) -> Script:
tag=yaml_content.get('parent'),
partners=yaml_content.get('partners'),
parameters=parameters,
metadata=metadata_content
hidden=yaml_content.get('hidden', False),
security=yaml_content.get('security', False),
uid=yaml_content.get('uid', None),
)

def get_repo_name(repo_url):
Expand Down