Browse Source

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

tags/3.5.7_beta2
parent
commit
78161512fb
4 changed files with 54 additions and 38 deletions
  1. +3
    -3
      pym/update/emerge_parser.py
  2. +16
    -18
      pym/update/profile.py
  3. +7
    -4
      pym/update/update.py
  4. +28
    -13
      pym/update/variables/update.py

+ 3
- 3
pym/update/emerge_parser.py View File

@@ -758,14 +758,14 @@ class Md5Checkvalue(MtimeCheckvalue):


class GitCheckvalue(object):
def __init__(self, rpath):
def __init__(self, git, rpath):
self.rpath = rpath
self.git = Git()
self.git = git

def checkvalues(self):
with ignore(GitError):
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):


+ 16
- 18
pym/update/profile.py View File

@@ -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):
"""


+ 7
- 4
pym/update/update.py View File

@@ -143,7 +143,7 @@ class Update(MethodsInterface):
EmergeCache.logger.logger.setLevel(logging.WARNING)
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.update_map = {}
self.refresh_binhost = False
@@ -153,13 +153,16 @@ class Update(MethodsInterface):
def get_prog_path(self, program_name):
return getProgPath(program_name)

def getGit(self):
return self.clVars.Get('cl_update_git')

def _syncRepository(self, name, url, rpath, revision,
cb_progress=None, clean=False, notask=False):
"""
Синхронизировать репозитори
"""
dv = self.clVars
git = Git()
git = self.getGit()
info_outdated = False
old_dir = "%s.old" % git._gitDir(rpath)
if path.exists(old_dir):
@@ -299,7 +302,7 @@ class Update(MethodsInterface):
dv = self.clVars
rpath = \
dv.select('cl_update_rep_path', cl_update_rep_name=repname, limit=1)
git = Git()
git = self.getGit()
self.addProgress()
git.trimRepository(rpath, cb_progress=self.setProgress)
return True
@@ -319,7 +322,7 @@ class Update(MethodsInterface):
if not url or not rpath:
raise UpdateError(_("Configuration variables for repositories "
"are not setup"))
git = Git()
git = self.getGit()
if not git.checkUrl(url):
raise UpdateError(_("Git %s is unavailable") % url)
chroot_path = path.normpath(self.clVars.Get('cl_chroot_path'))


+ 28
- 13
pym/update/variables/update.py View File

@@ -722,9 +722,21 @@ class VariableClUpdateProfileStorage(ReadonlyVariable):
type = "object"

def get(self):
git = self.Get('cl_update_git')
return RepositoryStorageSet(
LocalStorage('/var/lib/layman'),
CacheStorage('/var/calculate/tmp/update'))
LocalStorage(git, '/var/lib/layman'),
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):
@@ -955,19 +967,16 @@ class VariableClUpdateProfileUrl(Variable):
self.help = _("set the profile repository")

re_url = re.compile(
r"^(?:(%s)://)?(\w[\w\./:-]+?\w)(\.git)?$" % "|".join(
["http", "https", "git"]))
r"^(?:(%s)://)?((?:git@)?\w[\w\./:-]+?\w)(\.git)?$" % "|".join(
["http", "https", "git", "ssh"]))

re_shortname = re.compile('^(?:([\w\.-]+):)?([\w\.-]+)$')

@classmethod
def normalize_url(cls, url):
match = cls.re_url.match(url)
if not match:
url = Git.normalize_url(url)
if not 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

def url_by_shortname(self, value):
@@ -1024,8 +1033,7 @@ class VariableClUpdateProfileUrl(Variable):
raise CriticalError(
_("You need to update the repositories before "
"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:
raise VariableError(str(e))
except Exception as e:
@@ -1088,13 +1096,14 @@ class VariableClProfileRepository(ReadonlyVariable):

def get(self):
try:
git = self.Get('cl_update_git')
profile_dn = self.Get('cl_profile_system')
while profile_dn != '/' and ".git" not in listDirectory(profile_dn):
profile_dn = path.dirname(profile_dn)
if profile_dn == '/':
return ""
ls = LocalStorage(path.dirname(profile_dn))
return ProfileRepository(path.basename(profile_dn), ls)
ls = LocalStorage(git, path.dirname(profile_dn))
return ProfileRepository(git, path.basename(profile_dn), ls)
except Exception:
return ""

@@ -1785,3 +1794,9 @@ class VariableClUpdateUsetagSet(Variable):
"""
type = Variable.Types.Boolean
value = Variable.On

class VariableClUpdateSshkeyPath(Variable):
"""
Путь до ssh ключа
"""
value = "/var/lib/calculate/id_rsa"

Loading…
Cancel
Save