From dcfaa4e6a91eb7cdfe6424fc41c895b06034365f Mon Sep 17 00:00:00 2001 From: jj Date: Thu, 21 Dec 2023 13:06:42 +0100 Subject: [PATCH] trying to use virtualenv for git --- gitlab2ssh.py | 83 ++++++++++++++++++++++++++++----------------------- 1 file changed, 45 insertions(+), 38 deletions(-) diff --git a/gitlab2ssh.py b/gitlab2ssh.py index 852e611..5ec96ae 100644 --- a/gitlab2ssh.py +++ b/gitlab2ssh.py @@ -4,43 +4,8 @@ from airflow.decorators import dag, task from airflow.operators.python import PythonOperator from airflow.models.param import Param -from decors import get_connection, remove, setup -from utils import walk_dir, clean_up_vaultid - -try: - import gitlab -except ImportError: - print("Unable to import gitlab library") - - -def get_gitlab_client(url): - return gitlab.Gitlab(url) - - -def get_project(client, name): - fn = [pr for pr in client.projects.list(iterator=True) if pr.name == name] - if not fn: - print("No project for given name found") - return None - - return client.projects.get(fn[0].id) - - -class GitFSC: - def __init__(self, client, **kwargs): - self.client = client - - def list(self, path, get_info=True): - if not get_info: - return [ - el["name"] - for el in self.client.repository_tree(path=path, get_all=True) - ] - return [ - {"path": el["path"], "isdir": el["type"] == "tree"} - for el in self.client.repository_tree(path=path, get_all=True) - ] - +from decors import remove, setup +from utils import clean_up_vaultid CHNK_SIZE = 1024 * 1000 @@ -62,8 +27,50 @@ def list(self, path, get_info=True): }, ) def git2ssh(): - @task + @task.virtualenv( + system_site_packages=True, + requirements=["python-gitlab==3.15.0"] + ) def stream_vupload(connection_id, **kwargs): + from decors import get_connection + from utils import walk_dir + + try: + import gitlab + print("Gitlab imported!") + except ImportError: + print("Unable to import gitlab library") + + + def get_gitlab_client(url): + return gitlab.Gitlab(url) + + + def get_project(client, name): + fn = [pr for pr in client.projects.list(iterator=True) if pr.name == name] + if not fn: + print("No project for given name found") + return None + + return client.projects.get(fn[0].id) + + + class GitFSC: + def __init__(self, client, **kwargs): + self.client = client + + def list(self, path, get_info=True): + if not get_info: + return [ + el["name"] + for el in self.client.repository_tree(path=path, get_all=True) + ] + return [ + {"path": el["path"], "isdir": el["type"] == "tree"} + for el in self.client.repository_tree(path=path, get_all=True) + ] + + params = kwargs["params"] target = params.get("target", "/tmp/") url = params.get("gitlab_url")