|
|
|
@ -40,15 +40,15 @@ class RepositoryStorageInterface(object):
|
|
|
|
|
class RepositoryStorage(RepositoryStorageInterface):
|
|
|
|
|
directory = '/tmp'
|
|
|
|
|
|
|
|
|
|
def __init__(self, directory):
|
|
|
|
|
def __init__(self, git, directory):
|
|
|
|
|
self.directory = directory
|
|
|
|
|
self.git = git
|
|
|
|
|
makeDirectory(directory)
|
|
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
|
git = Git()
|
|
|
|
|
for dn in listDirectory(self.directory, onlyDir=True, fullPath=True):
|
|
|
|
|
if git.is_git(dn):
|
|
|
|
|
yield ProfileRepository(path.basename(dn), self)
|
|
|
|
|
if self.git.is_git(dn):
|
|
|
|
|
yield ProfileRepository(self.git, path.basename(dn), self)
|
|
|
|
|
|
|
|
|
|
def get_profiles(self, url, branch=DEFAULT_BRANCH):
|
|
|
|
|
return []
|
|
|
|
@ -89,7 +89,8 @@ class CacheStorage(ProfileStorage):
|
|
|
|
|
if rep.is_like(url, branch):
|
|
|
|
|
return rep
|
|
|
|
|
else:
|
|
|
|
|
return ProfileRepository.clone(url, self, branch or DEFAULT_BRANCH)
|
|
|
|
|
return ProfileRepository.clone(self.git, url, self,
|
|
|
|
|
branch or DEFAULT_BRANCH)
|
|
|
|
|
|
|
|
|
|
class RepositoryStorageSet(RepositoryStorageInterface):
|
|
|
|
|
"""
|
|
|
|
@ -172,9 +173,10 @@ class ProfileRepository(object):
|
|
|
|
|
"""
|
|
|
|
|
Репозиторий либо скачивается, либо берется из кэша
|
|
|
|
|
"""
|
|
|
|
|
def __init__(self, name, storage):
|
|
|
|
|
def __init__(self, git, name, storage):
|
|
|
|
|
self._storage = storage
|
|
|
|
|
self.name = name
|
|
|
|
|
self.git = git
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def storage(self):
|
|
|
|
@ -196,23 +198,22 @@ class ProfileRepository(object):
|
|
|
|
|
str(e))
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def clone(cls, url, storage, branch=DEFAULT_BRANCH):
|
|
|
|
|
def clone(cls, git, url, storage, branch=DEFAULT_BRANCH):
|
|
|
|
|
name = path.basename(url)
|
|
|
|
|
if name.endswith(".git"):
|
|
|
|
|
name = name[:-4]
|
|
|
|
|
git = Git()
|
|
|
|
|
rpath = path.join(storage.directory, name)
|
|
|
|
|
if path.exists(rpath):
|
|
|
|
|
removeDir(rpath)
|
|
|
|
|
git.cloneRepository(url, rpath, branch)
|
|
|
|
|
pr = cls(name, storage)
|
|
|
|
|
pr = cls(git, name, storage)
|
|
|
|
|
repo_name = pr.repo_name
|
|
|
|
|
if name != repo_name:
|
|
|
|
|
rpath_new = path.join(storage.directory, repo_name)
|
|
|
|
|
if path.exists(rpath_new):
|
|
|
|
|
removeDir(rpath_new)
|
|
|
|
|
shutil.move(rpath, rpath_new)
|
|
|
|
|
pr = cls(repo_name, storage)
|
|
|
|
|
pr = cls(git, repo_name, storage)
|
|
|
|
|
return pr
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
@ -234,22 +235,19 @@ class ProfileRepository(object):
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def url(self):
|
|
|
|
|
git = Git()
|
|
|
|
|
return git.get_url(self.directory, "origin")
|
|
|
|
|
return self.git.get_url(self.directory, "origin")
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def branch(self):
|
|
|
|
|
git = Git()
|
|
|
|
|
return git.getBranch(self.directory)
|
|
|
|
|
return self.git.getBranch(self.directory)
|
|
|
|
|
|
|
|
|
|
def sync(self):
|
|
|
|
|
"""
|
|
|
|
|
Синхронизировать репозиторий
|
|
|
|
|
"""
|
|
|
|
|
git = Git()
|
|
|
|
|
if not git.pullRepository(self.directory, quiet_error=True):
|
|
|
|
|
git.resetRepository(self.directory, to_origin=True)
|
|
|
|
|
git.pullRepository(self.directory, quiet_error=True)
|
|
|
|
|
if not self.git.pullRepository(self.directory, quiet_error=True):
|
|
|
|
|
self.git.resetRepository(self.directory, to_origin=True)
|
|
|
|
|
self.git.pullRepository(self.directory, quiet_error=True)
|
|
|
|
|
|
|
|
|
|
def get_profiles(self):
|
|
|
|
|
"""
|
|
|
|
|