@ -37,6 +37,7 @@ from calculate.lib.cl_log import log
import re
import shutil
from collections import MutableSet
from contextlib import contextmanager
from calculate . lib . utils . git import Git , GitError , MTimeKeeper , NotGitError
from calculate . lib . utils . portage import ( Layman , EmergeLog ,
@ -51,7 +52,8 @@ Colors = TextState.Colors
from calculate . lib . utils . files import ( getProgPath , STDOUT , removeDir ,
PercentProgress , process , getRunCommands ,
readFile , listDirectory , pathJoin ,
writeFile )
find , FindFileType ,
writeFile , makeDirectory )
import emerge_parser
import logging
from emerge_parser import ( EmergeParser , EmergeCommand , EmergeError ,
@ -156,6 +158,30 @@ class Update(MethodsInterface):
def getGit ( self ) :
return self . clVars . Get ( ' cl_update_git ' )
@contextmanager
def private_repo ( self , rpath , url ) :
if Git . is_private_url ( url ) :
try :
if not path . exists ( rpath ) :
makeDirectory ( rpath )
os . chmod ( rpath , 0700 )
yield
finally :
try :
for dn in ( Git . _gitDir ( rpath ) , path . join ( rpath , " profiles/templates " ) ) :
if path . exists ( dn ) :
os . chmod ( dn , 0700 )
for fn in find ( path . join ( rpath , " profiles " ) , True , FindFileType . RegularFile ,
True , None , downfilter = lambda x : not x . endswith ( " /templates " ) ) :
if fn . endswith ( " calculate.env " ) or fn . endswith ( " ini.env " ) :
os . chmod ( fn , 0600 )
if path . exists ( rpath ) :
os . chmod ( rpath , 0755 )
except OSError :
pass
else :
yield
def _syncRepository ( self , name , url , rpath , revision ,
cb_progress = None , clean = False , notask = False ) :
"""
@ -174,8 +200,9 @@ class Update(MethodsInterface):
self . startTask ( _ ( " Syncing the {rep} repository " ) . format (
rep = name . capitalize ( ) ) )
self . addProgress ( )
git . cloneTagRepository ( url , rpath , revision ,
cb_progress = cb_progress )
with self . private_repo ( rpath , url ) :
git . cloneTagRepository ( url , rpath , revision ,
cb_progress = cb_progress )
info_outdated = True
else :
cr = " "
@ -197,9 +224,10 @@ class Update(MethodsInterface):
self . startTask ( _ ( " Syncing the {rep} repository " ) . format (
rep = name . capitalize ( ) ) )
self . addProgress ( )
git . updateTagRepository ( url , rpath , revision ,
cb_progress = cb_progress ,
clean = clean )
with self . private_repo ( rpath , url ) :
git . updateTagRepository ( url , rpath , revision ,
cb_progress = cb_progress ,
clean = clean )
new_cr = git . getCurrentCommit ( rpath )
if new_cr != cr :
info_outdated = True
@ -385,12 +413,6 @@ class Update(MethodsInterface):
if repname not in ( " portage " , " gentoo " ) :
layman . add ( repname , url , rpath_orig )
finally :
try :
if ( path . exists ( rpath ) and
Git . parse_url ( url ) [ 0 ] == Git . GitProtocol . SSH ) :
os . chmod ( rpath , 0700 )
except OSError :
pass
mtime . restore ( )
return True