Добавлена поддержка закрытых репозиториев

master-3.5 3.5.7_beta2
parent 000b720e7d
commit 78161512fb

@ -758,14 +758,14 @@ class Md5Checkvalue(MtimeCheckvalue):
class GitCheckvalue(object): class GitCheckvalue(object):
def __init__(self, rpath): def __init__(self, git, rpath):
self.rpath = rpath self.rpath = rpath
self.git = Git() self.git = git
def checkvalues(self): def checkvalues(self):
with ignore(GitError): with ignore(GitError):
if self.git.is_git(self.rpath): if self.git.is_git(self.rpath):
yield self.rpath, Git().getCurrentCommit(self.rpath) yield self.rpath, self.git.getCurrentCommit(self.rpath)
class EmergeCache(object): class EmergeCache(object):

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

@ -143,7 +143,7 @@ class Update(MethodsInterface):
EmergeCache.logger.logger.setLevel(logging.WARNING) EmergeCache.logger.logger.setLevel(logging.WARNING)
self.emerge_cache.check_list = ( self.emerge_cache.check_list = (
self.emerge_cache.check_list + self.emerge_cache.check_list +
map(emerge_parser.GitCheckvalue, map(lambda x:emerge_parser.GitCheckvalue(x, self.getGit()),
self.clVars.Get('update.cl_update_rep_path'))) self.clVars.Get('update.cl_update_rep_path')))
self.update_map = {} self.update_map = {}
self.refresh_binhost = False self.refresh_binhost = False
@ -153,13 +153,16 @@ class Update(MethodsInterface):
def get_prog_path(self, program_name): def get_prog_path(self, program_name):
return getProgPath(program_name) return getProgPath(program_name)
def getGit(self):
return self.clVars.Get('cl_update_git')
def _syncRepository(self, name, url, rpath, revision, def _syncRepository(self, name, url, rpath, revision,
cb_progress=None, clean=False, notask=False): cb_progress=None, clean=False, notask=False):
""" """
Синхронизировать репозитори Синхронизировать репозитори
""" """
dv = self.clVars dv = self.clVars
git = Git() git = self.getGit()
info_outdated = False info_outdated = False
old_dir = "%s.old" % git._gitDir(rpath) old_dir = "%s.old" % git._gitDir(rpath)
if path.exists(old_dir): if path.exists(old_dir):
@ -299,7 +302,7 @@ class Update(MethodsInterface):
dv = self.clVars dv = self.clVars
rpath = \ rpath = \
dv.select('cl_update_rep_path', cl_update_rep_name=repname, limit=1) dv.select('cl_update_rep_path', cl_update_rep_name=repname, limit=1)
git = Git() git = self.getGit()
self.addProgress() self.addProgress()
git.trimRepository(rpath, cb_progress=self.setProgress) git.trimRepository(rpath, cb_progress=self.setProgress)
return True return True
@ -319,7 +322,7 @@ class Update(MethodsInterface):
if not url or not rpath: if not url or not rpath:
raise UpdateError(_("Configuration variables for repositories " raise UpdateError(_("Configuration variables for repositories "
"are not setup")) "are not setup"))
git = Git() git = self.getGit()
if not git.checkUrl(url): if not git.checkUrl(url):
raise UpdateError(_("Git %s is unavailable") % url) raise UpdateError(_("Git %s is unavailable") % url)
chroot_path = path.normpath(self.clVars.Get('cl_chroot_path')) chroot_path = path.normpath(self.clVars.Get('cl_chroot_path'))

@ -722,9 +722,21 @@ class VariableClUpdateProfileStorage(ReadonlyVariable):
type = "object" type = "object"
def get(self): def get(self):
git = self.Get('cl_update_git')
return RepositoryStorageSet( return RepositoryStorageSet(
LocalStorage('/var/lib/layman'), LocalStorage(git, '/var/lib/layman'),
CacheStorage('/var/calculate/tmp/update')) CacheStorage(git, '/var/calculate/tmp/update'))
class VariableClUpdateGit(ReadonlyVariable):
type = "object"
def get(self):
sshkey = self.Get('update.cl_update_sshkey_path')
if path.exists(sshkey):
return Git(sshkey)
else:
return Git()
class VariableClUpdateRepHost(Variable): class VariableClUpdateRepHost(Variable):
@ -955,19 +967,16 @@ class VariableClUpdateProfileUrl(Variable):
self.help = _("set the profile repository") self.help = _("set the profile repository")
re_url = re.compile( re_url = re.compile(
r"^(?:(%s)://)?(\w[\w\./:-]+?\w)(\.git)?$" % "|".join( r"^(?:(%s)://)?((?:git@)?\w[\w\./:-]+?\w)(\.git)?$" % "|".join(
["http", "https", "git"])) ["http", "https", "git", "ssh"]))
re_shortname = re.compile('^(?:([\w\.-]+):)?([\w\.-]+)$') re_shortname = re.compile('^(?:([\w\.-]+):)?([\w\.-]+)$')
@classmethod @classmethod
def normalize_url(cls, url): def normalize_url(cls, url):
match = cls.re_url.match(url) url = Git.normalize_url(url)
if not match: if not url:
raise VariableError(_("Wrong repository URL")) raise VariableError(_("Wrong repository URL"))
url = match.group(2)
url = "%s://%s" % (match.group(1) or "git", url)
url = "%s.git" % url
return url return url
def url_by_shortname(self, value): def url_by_shortname(self, value):
@ -1024,8 +1033,7 @@ class VariableClUpdateProfileUrl(Variable):
raise CriticalError( raise CriticalError(
_("You need to update the repositories before " _("You need to update the repositories before "
"you change the profile")) "you change the profile"))
git = Git() return Git.get_url(profile, "origin") or self.default_url
return git.get_url(profile, "origin") or self.default_url
except CriticalError as e: except CriticalError as e:
raise VariableError(str(e)) raise VariableError(str(e))
except Exception as e: except Exception as e:
@ -1088,13 +1096,14 @@ class VariableClProfileRepository(ReadonlyVariable):
def get(self): def get(self):
try: try:
git = self.Get('cl_update_git')
profile_dn = self.Get('cl_profile_system') profile_dn = self.Get('cl_profile_system')
while profile_dn != '/' and ".git" not in listDirectory(profile_dn): while profile_dn != '/' and ".git" not in listDirectory(profile_dn):
profile_dn = path.dirname(profile_dn) profile_dn = path.dirname(profile_dn)
if profile_dn == '/': if profile_dn == '/':
return "" return ""
ls = LocalStorage(path.dirname(profile_dn)) ls = LocalStorage(git, path.dirname(profile_dn))
return ProfileRepository(path.basename(profile_dn), ls) return ProfileRepository(git, path.basename(profile_dn), ls)
except Exception: except Exception:
return "" return ""
@ -1785,3 +1794,9 @@ class VariableClUpdateUsetagSet(Variable):
""" """
type = Variable.Types.Boolean type = Variable.Types.Boolean
value = Variable.On value = Variable.On
class VariableClUpdateSshkeyPath(Variable):
"""
Путь до ssh ключа
"""
value = "/var/lib/calculate/id_rsa"

Loading…
Cancel
Save