-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgit_test.py
More file actions
44 lines (37 loc) · 1.52 KB
/
Copy pathgit_test.py
File metadata and controls
44 lines (37 loc) · 1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import git
import tempfile
import os
from urllib.parse import quote
class GitParser(object):
def __init__(self):
self.git_user = "it.ops"
self.git_password = 'your_password'
self.git_server = 'http://git.nextop.cc/'
def init_repo_env(self, repoName=None):
if not self.git_user or not repoName or not self.git_password:
pass
elif len(repoName.split('://')) != 2:
pass
else:
if not self.git_server.startswith('http://'):
self.git_server = 'http://' + self.git_server
self.git_server = self.git_server.rstrip('/')
repo_dir = tempfile.TemporaryDirectory().name
user_passwd = ':'.join(
[quote(self.git_user), quote(self.git_password)])
head, git_repo = repoName.split('://')
return [head+"://"+user_passwd+"@"+git_repo, repo_dir]
def check_repo_isvalid(self, repoName):
_r = self.init_repo_env(repoName)
if _r:
os.system('mkdir -p '+_r[1])
try:
git.Repo.clone_from(_r[0],_r[1])
repo = git.Repo(_r[1])
print(repo.active_branch)
except Exception as e:
logger.error()
if __name__ == "__main__":
_git = GitParser()
_git.get_branch_current_uuid('http://git.nextop.cc/systempublic/nextop-user.git',branch='release-user-20201110-v1.0.0')
#_git.get_branch_current_uuid('http://git.nextop.cc/systempublic/nextop-user.git',branch='master')