-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit.py
48 lines (36 loc) · 1.48 KB
/
git.py
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
44
45
46
47
48
import subprocess
from repository import Repository
from vcsrepository import VcsRepository
class Git:
storage_path = ''
def __init__(self, storage_path):
"""Creates git service.
:param str storage_path: Path of the folder to store repositories
"""
self.storage_path = storage_path.rstrip('/') + '/'
def download(self, vcs_repository):
"""Downloads repository from VCS.
:param VcsRepository vcs_repository: Repository to download from VCS
:return: Local repository instance
:rtype Repository
"""
working_dir = self.storage_path + vcs_repository.name
subprocess.call(['git', 'clone', '--mirror', vcs_repository.url, working_dir])
return Repository(working_dir)
@staticmethod
def upload(repository, vcs_repository):
"""Uploads local repository to VCS.
:param Repository repository: Local repository to upload
:param VcsRepository vcs_repository: Remote repository to upload to
:return: None
"""
with repository:
subprocess.call(['git', 'remote', 'add', 'migrator', vcs_repository.url])
subprocess.call(['git', 'push', '--mirror', 'migrator'])
@staticmethod
def cleanup(repository):
"""Removes directory where local repository has been downloaded to.
:param Repository repository: Local repository
:return: None
"""
subprocess.call(['rm', '-rf', repository.working_dir])