From 42764d4faa7ac0b0eddcc39bc63247bb7063f6df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tom=C3=A1=C5=A1=20Valenta?= <git@imaniti.org> Date: Wed, 19 Apr 2023 09:34:46 +0200 Subject: [PATCH] add git sync management command --- contracts/management/__init__.py | 0 contracts/management/commands/__init__.py | 0 .../commands/import_old_contracts.py | 50 +++++++++++++++++++ requirements/base.txt | 2 + 4 files changed, 52 insertions(+) create mode 100644 contracts/management/__init__.py create mode 100644 contracts/management/commands/__init__.py create mode 100644 contracts/management/commands/import_old_contracts.py diff --git a/contracts/management/__init__.py b/contracts/management/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/contracts/management/commands/__init__.py b/contracts/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/contracts/management/commands/import_old_contracts.py b/contracts/management/commands/import_old_contracts.py new file mode 100644 index 0000000..0c12660 --- /dev/null +++ b/contracts/management/commands/import_old_contracts.py @@ -0,0 +1,50 @@ +import os + +from django.conf import settings +from django.core.management.base import BaseCommand +from git import Repo +from markdown import Markdown + + +class Command(BaseCommand): + help = "Sync contract data from a remote Git repository." + + def add_arguments(self, parser): + parser.add_argument( + "repo_url", + type=str, + help="URL of the Git repository to clone", + ) + parser.add_argument( + "branch", + type=str, + help="Branch to use", + ) + parser.add_argument( + "--directory", + type=str, + help="Directory to store the cloned repository in", + ) + + def handle(self, *args, **options): + git_dir = os.path.join( + os.getcwd(), + ( + options["directory"] + if options["directory"] is not None + else "git" + ) + ) + + Repo.clone_from( + options["repo_url"], + git_dir, + branch=options["branch"], + ) + + md = markdown.Markdown(extensions=['meta']) + parsed_metadata = md.convert("").Meta + + + + self.stdout.write("\nGit repository sync complete.") diff --git a/requirements/base.txt b/requirements/base.txt index a1283e8..39653cd 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -15,4 +15,6 @@ django-markdownx==4.0.0b1 django-environ==0.9.0 django-http-exceptions==1.4.0 django-guardian==2.4.0 +GitPython==3.1.31 +Markdown==3.4.3 PyJWT==2.6.0 -- GitLab