mirror of
https://github.com/netbox-community/Device-Type-Library-Import.git
synced 2025-06-10 20:07:18 +02:00
Delete gitcmd.py
This commit is contained in:
parent
8832370aba
commit
520c28dfed
45
gitcmd.py
45
gitcmd.py
@ -1,45 +0,0 @@
|
||||
from git import Repo, exc
|
||||
from sys import exit as system_exit
|
||||
import settings
|
||||
import os
|
||||
|
||||
class GitCMD:
|
||||
def __new__(cls, *args, **kwargs):
|
||||
return super().__new__(cls)
|
||||
|
||||
def __init__(self, args, repo_path):
|
||||
self.url = args.url
|
||||
self.repo_path = repo_path
|
||||
self.branch = args.branch
|
||||
# self.repo = Repo()
|
||||
self.cwd = os.getcwd()
|
||||
|
||||
if os.path.isdir(self.repo_path):
|
||||
self.pull_repo()
|
||||
else:
|
||||
self.clone_repo()
|
||||
|
||||
|
||||
def pull_repo(self):
|
||||
try:
|
||||
print("Package devicetype-library is already installed, "
|
||||
+ f"updating {os.path.join(self.cwd, self.repo_path)}")
|
||||
self.repo = Repo(self.repo_path)
|
||||
if not self.repo.remotes.origin.url.endswith('.git'):
|
||||
settings.handle.exception("GitInvalidRepositoryError", self.repo.remotes.origin.url, f"Origin URL {self.repo.remotes.origin.url} does not end with .git")
|
||||
self.repo.remotes.origin.pull()
|
||||
self.repo.git.checkout(self.branch)
|
||||
print(f"Pulled Repo {self.repo.remotes.origin.url}")
|
||||
except exc.GitCommandError as git_error:
|
||||
settings.handle.exception("GitCommandError", self.repo.remotes.origin.url, git_error)
|
||||
except Exception as git_error:
|
||||
settings.handle.exception("Exception", 'Git Repository Error', git_error)
|
||||
|
||||
def clone_repo(self):
|
||||
try:
|
||||
self.repo = Repo.clone_from(self.url, os.path.join(self.cwd, self.repo_path), branch=self.branch)
|
||||
print(f"Package Installed {self.repo.remotes.origin.url}")
|
||||
except exc.GitCommandError as git_error:
|
||||
settings.handle.exception("GitCommandError", self.url, git_error)
|
||||
except Exception as git_error:
|
||||
settings.handle.exception("Exception", 'Git Repository Error', git_error)
|
Loading…
x
Reference in New Issue
Block a user