Exemplo n.º 1
0
    def fetch( self, repopath=None ):
        """try to clone or update the repository"""
        EmergeDebug.trace("HgSource.fetch called", 2)

        # get the path where the repositories should be stored to
        if repopath == None:
            repopath = self.repositoryUrl()

        # in case you need to move from a read only Url to a writeable one, here it gets replaced
#        repoString = utils.replaceVCSUrl( repopath )
        repopath = repopath.replace("[hg]", "")
        repoUrl, repoBranch, _ = utils.splitVCSUrl( repopath )
        ret = True

        # only run if wanted (e.g. no --offline is given on the commandline) or no hg support is given by the python installation
        if ( not self.noFetch and self.enableHg ):
            # question whether mercurial stuff uses these proxies
            self.setProxy()
            checkoutDir = self.checkoutDir()

            # check corrupted checkout dir
            if os.path.exists( checkoutDir ) and not os.path.exists( checkoutDir + "\.hg" ):
                os.rmdir( checkoutDir )
            
            if not os.path.exists( checkoutDir ):
                os.makedirs( checkoutDir )
                os.chdir( checkoutDir )
                ret = self.system( "%s clone %s ." % ( self.hgExecutable, repoUrl ) ) # TODO: check return code for success
            
            if os.path.exists( checkoutDir ):
                os.chdir( checkoutDir )
                ret = self.system( "%s update %s" % ( self.hgExecutable, repoBranch ) ) # TODO: check return code for success
        else:
            EmergeDebug.debug("skipping hg fetch (--offline)")
        return ret
Exemplo n.º 2
0
def getPackagesCategories(packageName, defaultCategory = None):
    EmergeDebug.trace("getPackagesCategories for package name %s" % packageName)
    if defaultCategory is None:
        defaultCategory = emergeSettings.get("General","EMERGE_DEFAULTCATEGORY","kde")

    packageList, categoryList = [], []
    if len( packageName.split( "/" ) ) == 1:
        if PortageInstance.isCategory( packageName ):
            EmergeDebug.debug("isCategory=True", 2)
            packageList = PortageInstance.getAllPackages( packageName )
            categoryList = [ packageName ] * len(packageList)
        else:
            EmergeDebug.debug("isCategory=False", 2)
            if PortageInstance.isCategory( defaultCategory ) and PortageInstance.isPackage( defaultCategory, packageName ):
                # prefer the default category
                packageList = [ packageName ]
                categoryList = [ defaultCategory ]
            else:
                if PortageInstance.getCategory( packageName ):
                    packageList = [ packageName ]
                    categoryList = [ PortageInstance.getCategory( packageName ) ]
    elif len( packageName.split( "/" ) ) == 2:
        [ cat, pac ] = packageName.split( "/" )
        if PortageInstance.isCategory( cat ):
            categoryList = [ cat ]
        else:
            return packageList, categoryList
        if len( categoryList ) > 0 and PortageInstance.isPackage( categoryList[0], pac ):
            packageList = [ pac ]
        if len( categoryList ) and len( packageList ):
            EmergeDebug.debug("added package %s/%s" % (categoryList[0], pac), 2)
    else:
        EmergeDebug.error("unknown packageName")

    return packageList, categoryList
Exemplo n.º 3
0
    def __fetchSingleBranch(self, repopath=None):
        EmergeDebug.trace("GitSource __fetchSingleBranch", 2)
        # get the path where the repositories should be stored to
        if repopath == None:
            repopath = self.repositoryUrl()
        EmergeDebug.debug("fetching %s" % repopath)

        # in case you need to move from a read only Url to a writeable one, here it gets replaced
        repopath = repopath.replace("[git]", "")
        repoString = utils.replaceVCSUrl(repopath)
        [repoUrl, repoBranch, repoTag] = utils.splitVCSUrl(repoString)
        if not repoBranch and not repoTag:
            repoBranch = "master"

        ret = True
        # only run if wanted (e.g. no --offline is given on the commandline)
        if not self.noFetch:
            self.setProxy()
            safePath = os.environ["PATH"]
            # add the git path to the PATH variable so that git can be called without path
            os.environ["PATH"] = os.path.join(self.rootdir, "git", "bin") + ";" + safePath
            checkoutDir = self.checkoutDir()
            # if we only have the checkoutdir but no .git within,
            # clean this up first
            if os.path.exists(checkoutDir) and not os.path.exists(checkoutDir + "\.git"):
                os.rmdir(checkoutDir)
            if os.path.exists(checkoutDir):
                if not repoTag:
                    self.__git("fetch")
                    ret = self.__git("checkout", repoBranch or "master") and self.__git("merge")
                    if self.subinfo.options.fetch.checkoutSubmodules:
                        self.__git("submodule update --init --recursive")
            else:
                # it doesn't exist so clone the repo
                os.makedirs(checkoutDir)
                # first try to replace with a repo url from etc/portage/emergehosts.conf
                recursive = "--recursive" if self.subinfo.options.fetch.checkoutSubmodules else ""
                ret = self.__git("clone", recursive, repoUrl, ".")

            # if a branch is given, we should check first if the branch is already downloaded
            # locally, otherwise we can track the remote branch
            if ret and repoBranch and not repoTag:
                track = ""
                if not self.__isLocalBranch(repoBranch):
                    track = "--track origin/"
                ret = self.__git("checkout", "%s%s" % (track, repoBranch))

            # we can have tags or revisions in repoTag
            if ret and repoTag:
                if self.__isTag(repoTag):
                    if not self.__isLocalBranch("_" + repoTag):
                        ret = self.__git("checkout", "-b", "_%s" % repoTag, repoTag)
                    else:
                        ret = self.__git("checkout", "_%s" % repoTag)
                else:
                    ret = self.__git("checkout", repoTag)

        else:
            EmergeDebug.debug("skipping git fetch (--offline)")
        return ret
Exemplo n.º 4
0
def SourceFactory(settings):
    """ return sourceBase derived instance for recent settings"""
    EmergeDebug.trace("SourceFactory called", 1)
    source = None

    if settings.hasTarget():
        if settings.hasMultipleTargets():
            url = settings.targetAt(0)
        else:
            url = settings.target()
        source = ArchiveSource(settings)

    ## \todo move settings access into info class
    if settings.hasSvnTarget():
        url = settings.svnTarget()
        sourceType = utils.getVCSType( url )
        if sourceType == "svn":
            source = SvnSource(settings)
        elif sourceType == "hg":
            source = HgSource(settings)
        elif sourceType == "git":
            source = GitSource(settings)

    if source == None:
        EmergeDebug.die("none or unsupported source system set")
    if not source.subinfo:
        source.subinfo = settings
    source.url = url
    return source
Exemplo n.º 5
0
 def unpack(self):
     EmergeDebug.trace("MultiSource unpack", 2)
     # pylint: disable=E1101
     # multiple inheritance: MultiSource is never the only
     # superclass, others define self.buildSystemType.
     self.source.buildSystemType = self.buildSystemType
     return self.source.unpack()
Exemplo n.º 6
0
 def unpack(self):
     EmergeDebug.trace("MultiSource unpack", 2)
     # pylint: disable=E1101
     # multiple inheritance: MultiSource is never the only
     # superclass, others define self.buildSystemType.
     self.source.buildSystemType = self.buildSystemType
     return self.source.unpack()
Exemplo n.º 7
0
    def sourceVersion(self):
        """ return the revision of the repository """
        EmergeDebug.trace("HgSource.sourceVersion called", 2)

        if self.enableHg:

            # open a temporary file - do not use generic tmpfile because this doesn't give a good file object with python
            with open(
                    os.path.join(self.checkoutDir().replace('/', '\\'),
                                 ".emergehgtip.tmp"), "wb+") as tempfile:

                # run the command
                utils.system("%s tip" % self.hgExecutable, stdout=tempfile)
                # TODO: check return value for success
                tempfile.seek(os.SEEK_SET)

                # read the temporary file and grab the first line
                revision = tempfile.readline().replace("changeset:",
                                                       "").strip()

            os.remove(
                os.path.join(self.checkoutDir().replace('/', '\\'),
                             ".emergehgtip.tmp"))
        # always return True to not break something serious
        return revision
    def __repositoryBaseUrl( self ):
        """ this function return the base url to the KDE repository """
        EmergeDebug.trace("VersionSystemSourceBase __repositoryBaseUrl", 2)
        # @todo move to SvnSource
        server = emergeSettings.get("General", "KDESVNSERVER", "svn://anonsvn.kde.org")


        return server + '/home/kde/'
Exemplo n.º 9
0
 def applyPatch(self, fileName, patchdepth, unusedSrcDir=None):
     """apply a patch to a mercurial repository checkout"""
     EmergeDebug.trace("HgSource.applyPatches called", 2)
     if fileName and self.enableHg:
         patchfile = os.path.join ( self.packageDir(), fileName )
         os.chdir( self.sourceDir() )
         return self.system( '"%s" import -p %s "%s"' % (self.hgExecutable, patchdepth, patchfile) )
     return True
Exemplo n.º 10
0
 def __init__(self, subinfo=None):
     EmergeDebug.trace("SvnSource.__init__", 2)
     if subinfo:
         self.subinfo = subinfo
     VersionSystemSourceBase.__init__( self )
     self.options = None
     ## \todo add internal dependency for subversion package
     self.svnInstallDir = os.path.join(self.rootdir, 'dev-utils', 'svn', 'bin')
Exemplo n.º 11
0
    def __repositoryBaseUrl(self):
        """ this function return the base url to the KDE repository """
        EmergeDebug.trace("VersionSystemSourceBase __repositoryBaseUrl", 2)
        # @todo move to SvnSource
        server = emergeSettings.get("General", "KDESVNSERVER",
                                    "svn://anonsvn.kde.org")

        return server + '/home/kde/'
Exemplo n.º 12
0
 def localFileNames(self):
     EmergeDebug.trace("MultiSource localFileNames", 2)
     if self.subinfo.archiveName() == "":
         return self.source.localFileNamesBase()
     if isinstance(self.subinfo.archiveName(), (list, tuple)):
         return self.subinfo.archiveName()
     else:
         return (self.subinfo.archiveName(), )
Exemplo n.º 13
0
 def applyPatch(self, fileName, patchdepth, unusedSrcDir=None):
     """apply a patch to a svn repository checkout"""
     EmergeDebug.trace("SvnSource.applyPatch", 2)
     if fileName:
         return utils.applyPatch(self.sourceDir(),
                                 os.path.join(self.packageDir(), fileName),
                                 patchdepth)
     return True
Exemplo n.º 14
0
 def createPatch( self ):
     """create patch file from git source into the related package dir.
     The patch file is named autocreated.patch"""
     EmergeDebug.trace('GitSource createPatch', 2)
     patchFileName = os.path.join( self.packageDir(), "%s-%s.patch" % \
             ( self.package, str( datetime.date.today() ).replace('-', '') ) )
     EmergeDebug.debug("git diff %s" % patchFileName, 1)
     with open(patchFileName,'wt+') as patchFile:
         return self.__git('diff', stdout=patchFile)
Exemplo n.º 15
0
    def enterBuildDir(self):
        EmergeDebug.trace("EmergeBase.enterBuildDir called")

        if ( not os.path.exists( self.buildDir() ) ):
            os.makedirs( self.buildDir() )
            EmergeDebug.debug("creating: %s" % self.buildDir())

        os.chdir( self.buildDir() )
        EmergeDebug.debug("entering: %s" % self.buildDir())
Exemplo n.º 16
0
 def createPatch( self ):
     """create patch file from git source into the related package dir. The patch file is named autocreated.patch"""
     EmergeDebug.trace("HgSource.createPatch called", 2)
     ret = False
     if self.enableHg:
         os.chdir( self.sourceDir() )
         patchFile = os.path.join( self.packageDir(), "%s-%s.patch" % ( self.package, str( datetime.date.today() ).replace('-', '') ) )
         ret = self.system( self.sourceDir(), "%s diff > %s" % ( self.hgExecutable,  patchFile ) )
     return ret
Exemplo n.º 17
0
 def applyPatch(self, fileName, patchdepth, unusedSrcDir=None):
     """apply a patch to a mercurial repository checkout"""
     EmergeDebug.trace("HgSource.applyPatches called", 2)
     if fileName and self.enableHg:
         patchfile = os.path.join(self.packageDir(), fileName)
         os.chdir(self.sourceDir())
         return self.system('"%s" import -p %s "%s"' %
                            (self.hgExecutable, patchdepth, patchfile))
     return True
    def sourceDir(self, index=0 ):
        EmergeDebug.trace("VersionSystemSourceBase sourceDir", 2)
        sourcedir = self.checkoutDir( index )

        if self.subinfo.hasTargetSourcePath():
            sourcedir = os.path.join(sourcedir, self.subinfo.targetSourcePath())

        EmergeDebug.debug("using sourcedir: %s" % sourcedir, 2)
        return os.path.abspath(sourcedir)
Exemplo n.º 19
0
    def enterBuildDir(self):
        EmergeDebug.trace("EmergeBase.enterBuildDir called")

        if (not os.path.exists(self.buildDir())):
            os.makedirs(self.buildDir())
            EmergeDebug.debug("creating: %s" % self.buildDir())

        os.chdir(self.buildDir())
        EmergeDebug.debug("entering: %s" % self.buildDir())
Exemplo n.º 20
0
 def __init__(self):
     object.__init__(self)
     EmergeDebug.trace("MultiSource __init__", 2)
     # pylint: disable=E1101
     # multiple inheritance: MultiSource is never the only
     # superclass, others define self.source, self.subinfo etc.
     # TODO: This code should mostly be in the class defining self.source etc.
     self.source = SourceFactory(self.subinfo)
     self.source.localFileNames = self.localFileNames.__get__(self, MultiSource)
Exemplo n.º 21
0
 def repositoryUrlCount(self):
     """return the number of provided repository url's. Multiple repository urls' are delimited by ';'"""
     EmergeDebug.trace("VersionSystemSourceBase repositoryUrlCount", 2)
     if not self.subinfo.hasSvnTarget():
         return 0
     u = self.subinfo.svnTarget()
     if u.find(';') == -1:
         return 1
     urls = u.split(';')
     return len(urls)
Exemplo n.º 22
0
 def repositoryUrlOptions(self, index=0):
     """this function return options for the repository url at position 'index'.
     Options for a repository url are defined by adding '#' followed by the specific option.
     """
     EmergeDebug.trace("VersionSystemSourceBase repositoryUrlOptions", 2)
     if self.subinfo.hasSvnTarget():
         u = self.getUrl(index)
         (dummy, option) = self.splitUrl(u)
         return option
     return None
Exemplo n.º 23
0
    def sourceDir(self, index=0):
        EmergeDebug.trace("VersionSystemSourceBase sourceDir", 2)
        sourcedir = self.checkoutDir(index)

        if self.subinfo.hasTargetSourcePath():
            sourcedir = os.path.join(sourcedir,
                                     self.subinfo.targetSourcePath())

        EmergeDebug.debug("using sourcedir: %s" % sourcedir, 2)
        return os.path.abspath(sourcedir)
 def repositoryUrlCount( self ):
     """return the number of provided repository url's. Multiple repository urls' are delimited by ';'"""
     EmergeDebug.trace("VersionSystemSourceBase repositoryUrlCount", 2)
     if not self.subinfo.hasSvnTarget():
         return 0
     u = self.subinfo.svnTarget()
     if u.find(';') == -1:
         return 1
     urls = u.split(';')
     return len(urls)
 def repositoryUrlOptions( self, index=0 ):
     """this function return options for the repository url at position 'index'.
     Options for a repository url are defined by adding '#' followed by the specific option.
     """
     EmergeDebug.trace("VersionSystemSourceBase repositoryUrlOptions", 2)
     if self.subinfo.hasSvnTarget():
         u = self.getUrl(index)
         (dummy, option) = self.splitUrl(u)
         return option
     return None
Exemplo n.º 26
0
 def createPatch(self):
     """create patch file from git source into the related package dir.
     The patch file is named autocreated.patch"""
     EmergeDebug.trace("GitSource createPatch", 2)
     patchFileName = os.path.join(
         self.packageDir(), "%s-%s.patch" % (self.package, str(datetime.date.today()).replace("-", ""))
     )
     EmergeDebug.debug("git diff %s" % patchFileName, 1)
     with open(patchFileName, "wt+") as patchFile:
         return self.__git("diff", stdout=patchFile)
    def checkoutDir( self, dummyIndex=0 ):
        EmergeDebug.trace("VersionSystemSourceBase checkoutDir", 2)
        if self.subinfo.hasSvnTarget():
            sourcedir = os.path.join(  EmergeStandardDirs.gitDir(), self.package )
        else:
            EmergeDebug.die("svnTarget property not set for this target")

        if self.subinfo.targetSourceSuffix() != None:
            sourcedir = "%s-%s" % (sourcedir, self.subinfo.targetSourceSuffix())

        return os.path.abspath(sourcedir)
Exemplo n.º 28
0
 def applyPatch(self, fileName, patchdepth, srcdir=None ):
     """base implementation for applying a single patch to the source"""
     EmergeDebug.trace("SourceBase.applyPatch called", 2)
     if not fileName:
         return True
     if not srcdir:
         srcdir = self.sourceDir()
     patchfile = os.path.join ( self.packageDir(), fileName )
     # TODO: integrate utils.applyPatch() here and remove it from utils().
     # and change packages in portage accordingly
     return utils.applyPatch( srcdir, patchfile, patchdepth )
Exemplo n.º 29
0
 def applyPatches(self):
     """apply patches if available"""
     EmergeDebug.trace("SourceBase.applyPatches called", 0)
     if self.subinfo.hasTarget() or self.subinfo.hasSvnTarget():
         patches = self.subinfo.patchesToApply()
         if not isinstance(patches, list):
             patches = list([patches])
         # pylint: disable=W0142
         # do not warn about * magic
         return set(self.applyPatch(*x) for x in patches) == set([True])
     return True
Exemplo n.º 30
0
    def __init__(self, subinfo=None):
        EmergeDebug.trace("GitSource __init__", 2)
        if subinfo:
            self.subinfo = subinfo
        VersionSystemSourceBase.__init__(self)

        # detect git installation
        gitInstallDir = os.path.join(self.rootdir, "dev-utils", "git")
        if os.path.exists(gitInstallDir):
            self.gitPath = os.path.join(gitInstallDir, "bin", "git")
        else:
            self.gitPath = "git"
    def unpack(self):
        EmergeDebug.trace("VersionSystemSourceBase unpack", 2)
        self.enterBuildDir()

        if not self.noClean:
            if EmergeDebug.verbose() > 0:
                print("cleaning %s" % self.buildDir())
            utils.cleanDirectory( self.buildDir() )
        ret = self.applyPatches()
        if emergeSettings.getboolean("General","EMERGE_HOLD_ON_PATCH_FAIL", False):
            return ret
        return True
Exemplo n.º 32
0
 def applyPatch(self, fileName, patchdepth, unusedSrcDir=None):
     """apply a patch to a svn repository checkout"""
     EmergeDebug.trace("SvnSource.applyPatch", 2)
     if fileName:
         patchfile = os.path.join (self.packageDir(), fileName)
         # @todo check if this could be merged into SourceBase.applyPatch
         if self.noCopy:
             srcdir = self.sourceDir()
         else:
             srcdir = self.buildDir()
         return utils.applyPatch(srcdir, patchfile, patchdepth)
     return True
Exemplo n.º 33
0
 def createPatch(self):
     """create patch file from git source into the related package dir. The patch file is named autocreated.patch"""
     EmergeDebug.trace("HgSource.createPatch called", 2)
     ret = False
     if self.enableHg:
         os.chdir(self.sourceDir())
         patchFile = os.path.join(
             self.packageDir(), "%s-%s.patch" %
             (self.package, str(datetime.date.today()).replace('-', '')))
         ret = self.system(self.sourceDir(),
                           "%s diff > %s" % (self.hgExecutable, patchFile))
     return ret
Exemplo n.º 34
0
    def checkoutDir(self, dummyIndex=0):
        EmergeDebug.trace("VersionSystemSourceBase checkoutDir", 2)
        if self.subinfo.hasSvnTarget():
            sourcedir = os.path.join(EmergeStandardDirs.gitDir(), self.package)
        else:
            EmergeDebug.die("svnTarget property not set for this target")

        if self.subinfo.targetSourceSuffix() != None:
            sourcedir = "%s-%s" % (sourcedir,
                                   self.subinfo.targetSourceSuffix())

        return os.path.abspath(sourcedir)
Exemplo n.º 35
0
    def unpack(self):
        EmergeDebug.trace("VersionSystemSourceBase unpack", 2)
        self.enterBuildDir()

        if not self.noClean:
            if EmergeDebug.verbose() > 0:
                print("cleaning %s" % self.buildDir())
            utils.cleanDirectory(self.buildDir())
        ret = self.applyPatches()
        if emergeSettings.getboolean("General", "EMERGE_HOLD_ON_PATCH_FAIL",
                                     False):
            return ret
        return True
Exemplo n.º 36
0
    def __fetchMultipleBranch(self, repopath=None):
        EmergeDebug.trace("GitSource __fetchMultipleBranch", 2)
        # get the path where the repositories should be stored to
        if repopath == None:
            repopath = self.repositoryUrl()
        EmergeDebug.debug("fetching %s" % repopath)

        # in case you need to move from a read only Url to a writeable one, here it gets replaced
        repopath = repopath.replace("[git]", "")
        repoString = utils.replaceVCSUrl(repopath)
        [repoUrl, repoBranch, repoTag] = utils.splitVCSUrl(repoString)

        ret = True
        # only run if wanted (e.g. no --offline is given on the commandline)
        if not self.noFetch:
            self.setProxy()
            safePath = os.environ["PATH"]
            # add the git path to the PATH variable so that git can be called without path
            os.environ["PATH"] = os.path.join(self.rootdir, "git", "bin") + ";" + safePath
            rootCheckoutDir = os.path.join(self.checkoutDir(), ".git")
            if not os.path.exists(rootCheckoutDir):
                # it doesn't exist so clone the repo
                os.makedirs(rootCheckoutDir)
                ret = self.__git("clone", "--mirror", repoUrl, ".", cwd=rootCheckoutDir)
            else:
                ret = self.__git("fetch", cwd=rootCheckoutDir)
                if not ret:
                    EmergeDebug.die("could not fetch remote data")

            if repoBranch == "":
                repoBranch = "master"
            if ret:
                branchDir = os.path.join(self.checkoutDir(), repoBranch)
                if not os.path.exists(branchDir):
                    os.makedirs(branchDir)
                    ret = self.__git(
                        "clone", "--local --shared -b", repoBranch, rootCheckoutDir, branchDir, cwd=branchDir
                    )
                else:
                    ret = self.__git("pull")
                    if not ret:
                        EmergeDebug.die("could not pull into branch %s" % repoBranch)

            if ret:
                # ret = self.__git('checkout', '-f')
                ret = self.__git("checkout", "-f", repoTag or repoBranch, cwd=branchDir)
        else:
            EmergeDebug.debug("skipping git fetch (--offline)")
        return ret
    def getUrl( self, index ):
        """get the url at position 'index' from a ';' separated list of urls"""
        EmergeDebug.trace("VersionSystemSourceBase getUrl", 2)
        u = self.subinfo.svnTarget()
        if u.find(';') == -1:
            if index == 0:
                return u
            else:
                return None
        # urls are a list
        urls = u.split(';')
        if index >= len(urls):
            return None

        u = urls[index]
        return u
Exemplo n.º 38
0
 def repositoryUrl(self, index=0):
     """this function returns the full url into a version system based repository at position 'index'.
     See @ref repositoryUrlCount how to define multiple repository urls."""
     EmergeDebug.trace("VersionSystemSourceBase repositoryUrl", 2)
     if self.subinfo.hasSvnTarget():
         u1 = self.getUrl(index)
         (u, dummy) = self.splitUrl(u1)
         # check relative kde url
         # @todo this is svn specific - move to SvnSource
         if u.find("://") == -1 and utils.getVCSType(u) == "svn":
             url = self.__repositoryBaseUrl() + u
         else:
             url = u
         return url
     else:
         return False
Exemplo n.º 39
0
    def __init__( self, subinfo=None ):
        EmergeDebug.trace('HgSource __init__', 2)
        if subinfo:
            self.subinfo = subinfo
        VersionSystemSourceBase.__init__( self )

        self.hgExecutable = os.path.join( os.environ.get( 'ProgramFiles' ), 'mercurial', 'hg.exe' )
        self.enableHg = os.path.exists( self.hgExecutable )
        # add other locations
        if not self.enableHg:
            print("could not find hg.exe, you should run emerge mercurial")
        # guard spaces in path
        self.hgExecutable = "\"%s\"" % self.hgExecutable

        # initialize the repository
        self.repo = None
Exemplo n.º 40
0
    def getUrl(self, index):
        """get the url at position 'index' from a ';' separated list of urls"""
        EmergeDebug.trace("VersionSystemSourceBase getUrl", 2)
        u = self.subinfo.svnTarget()
        if u.find(';') == -1:
            if index == 0:
                return u
            else:
                return None
        # urls are a list
        urls = u.split(';')
        if index >= len(urls):
            return None

        u = urls[index]
        return u
 def repositoryUrl( self, index=0 ):
     """this function returns the full url into a version system based repository at position 'index'.
     See @ref repositoryUrlCount how to define multiple repository urls."""
     EmergeDebug.trace("VersionSystemSourceBase repositoryUrl", 2)
     if self.subinfo.hasSvnTarget():
         u1 = self.getUrl(index)
         (u, dummy) = self.splitUrl(u1)
         # check relative kde url
         # @todo this is svn specific - move to SvnSource
         if u.find("://") == -1 and utils.getVCSType( u ) == "svn":
             url = self.__repositoryBaseUrl() + u
         else:
             url = u
         return url
     else:
         return False
Exemplo n.º 42
0
    def fetch(self, repopath=None):
        """ checkout or update an existing repository path """
        EmergeDebug.trace("SvnSource.fetch", 2)
        if self.noFetch:
            EmergeDebug.debug("skipping svn fetch (--offline)")
            return True

        for i in range(self.repositoryUrlCount()):
            if repopath:
                url = repopath
            else:
                url = self.repositoryUrl(i)
            self.__tryCheckoutFromRoot(
                url, self.checkoutDir(i),
                self.repositoryUrlOptions(i) != 'norecursive')
        return True
Exemplo n.º 43
0
    def __fetchMultipleBranch(self, repopath=None):
        EmergeDebug.trace('GitSource __fetchMultipleBranch', 2)
        # get the path where the repositories should be stored to
        if repopath == None:
            repopath = self.repositoryUrl()
        EmergeDebug.debug("fetching %s" % repopath)

        # in case you need to move from a read only Url to a writeable one, here it gets replaced
        repopath = repopath.replace("[git]", "")
        repoString = utils.replaceVCSUrl( repopath )
        [repoUrl, repoBranch, repoTag ] = utils.splitVCSUrl( repoString )

        ret = True
        # only run if wanted (e.g. no --offline is given on the commandline)
        if ( not self.noFetch ):
            self.setProxy()
            safePath = os.environ["PATH"]
            # add the git path to the PATH variable so that git can be called without path
            os.environ["PATH"] = os.path.join( self.rootdir, "git", "bin" ) + ";" + safePath
            rootCheckoutDir = os.path.join(self.checkoutDir(), '.git')
            if not os.path.exists( rootCheckoutDir ):
                # it doesn't exist so clone the repo
                os.makedirs( rootCheckoutDir )
                ret = self.__git('clone', '--mirror', repoUrl, '.', cwd=rootCheckoutDir)
            else:
                ret = self.__git('fetch', cwd=rootCheckoutDir)
                if not ret:
                    EmergeDebug.die("could not fetch remote data")

            if repoBranch == "":
                repoBranch = "master"
            if ret:
                branchDir = os.path.join(self.checkoutDir(), repoBranch)
                if not os.path.exists(branchDir):
                    os.makedirs(branchDir)
                    ret = self.__git('clone', '--local --shared -b', repoBranch, rootCheckoutDir, branchDir, cwd=branchDir)
                else:
                    ret = self.__git('pull')
                    if not ret:
                        EmergeDebug.die("could not pull into branch %s" % repoBranch)

            if ret:
                #ret = self.__git('checkout', '-f')
                ret = self.__git("checkout", "-f", repoTag or repoBranch, cwd=branchDir)
        else:
            EmergeDebug.debug("skipping git fetch (--offline)")
        return ret
Exemplo n.º 44
0
    def fetch( self, repopath = None ):
        """ checkout or update an existing repository path """
        EmergeDebug.trace("SvnSource.fetch", 2)
        if self.noFetch:
            EmergeDebug.debug("skipping svn fetch (--offline)")
            return True

        if not os.path.exists(self.svnInstallDir):
            EmergeDebug.die("required subversion package not installed in %s" % self.svnInstallDir)

        for i in range(self.repositoryUrlCount()):
            if repopath:
                url = repopath
            else:
                url = self.repositoryUrl(i)
            self.__tryCheckoutFromRoot(url, self.checkoutDir(i), self.repositoryUrlOptions(i) != 'norecursive')
        return True
Exemplo n.º 45
0
    def __init__(self, subinfo=None):
        EmergeDebug.trace('HgSource __init__', 2)
        if subinfo:
            self.subinfo = subinfo
        VersionSystemSourceBase.__init__(self)

        self.hgExecutable = os.path.join(os.environ.get('ProgramFiles'),
                                         'mercurial', 'hg.exe')
        self.enableHg = os.path.exists(self.hgExecutable)
        # add other locations
        if not self.enableHg:
            print("could not find hg.exe, you should run emerge mercurial")
        # guard spaces in path
        self.hgExecutable = "\"%s\"" % self.hgExecutable

        # initialize the repository
        self.repo = None
Exemplo n.º 46
0
    def sourceDir(self, index=0 ):
        EmergeDebug.trace("VersionSystemSourceBase sourceDir", 2)
        if not self.noCopy:
            # need to check index ?
            sourcedir = self.workDir()

            if self.subinfo.targetSourceSuffix() != None:
                sourcedir = "%s-%s" % (sourcedir, self.subinfo.targetSourceSuffix())

            return sourcedir
        else:
            sourcedir = self.checkoutDir( index )

        if self.subinfo.hasTargetSourcePath():
            sourcedir = os.path.join(sourcedir, self.subinfo.targetSourcePath())

        EmergeDebug.debug("using sourcedir: %s" % sourcedir, 2)
        return os.path.abspath(sourcedir)
Exemplo n.º 47
0
    def sourceDir(self, index=0):
        EmergeDebug.trace("GitSource sourceDir", 2)
        repopath = self.repositoryUrl()
        # in case you need to move from a read only Url to a writeable one, here it gets replaced
        repopath = repopath.replace("[git]", "")
        repoString = utils.replaceVCSUrl(repopath)
        _, repoBranch, _ = utils.splitVCSUrl(repoString)
        if repoBranch == "":
            repoBranch = "master"
        if emergeSettings.getboolean("General", "EMERGE_GIT_MULTIBRANCH", False):
            sourcedir = os.path.join(self.checkoutDir(index), repoBranch)
        else:
            sourcedir = self.checkoutDir(index)

        if self.subinfo.hasTargetSourcePath():
            sourcedir = os.path.join(sourcedir, self.subinfo.targetSourcePath())

        EmergeDebug.debug("using sourcedir: %s" % sourcedir, 2)
        return sourcedir
Exemplo n.º 48
0
    def sourceDir(self, index=0 ):
        EmergeDebug.trace('GitSource sourceDir', 2)
        repopath = self.repositoryUrl()
        # in case you need to move from a read only Url to a writeable one, here it gets replaced
        repopath = repopath.replace("[git]", "")
        repoString = utils.replaceVCSUrl( repopath )
        _, repoBranch, _ = utils.splitVCSUrl( repoString )
        if repoBranch == "":
            repoBranch = "master"
        if emergeSettings.getboolean("General","EMERGE_GIT_MULTIBRANCH", False):
            sourcedir = os.path.join(self.checkoutDir(index), repoBranch)
        else:
            sourcedir = self.checkoutDir(index)

        if self.subinfo.hasTargetSourcePath():
            sourcedir = os.path.join(sourcedir, self.subinfo.targetSourcePath())

        EmergeDebug.debug("using sourcedir: %s" % sourcedir, 2)
        return sourcedir
Exemplo n.º 49
0
 def applyPatch(self, fileName, patchdepth, unusedSrcDir=None):
     """apply single patch o git repository"""
     EmergeDebug.trace("GitSource ", 2)
     if fileName:
         patchfile = os.path.join(self.packageDir(), fileName)
         if emergeSettings.getboolean("General", "EMERGE_GIT_MULTIBRANCH", False):
             repopath = self.repositoryUrl()
             # in case you need to move from a read only Url to a writeable one, here it gets replaced
             repopath = repopath.replace("[git]", "")
             repoString = utils.replaceVCSUrl(repopath)
             repoBranch = utils.splitVCSUrl(repoString)[1] or "master"
             sourceDir = os.path.join(self.checkoutDir(), repoBranch)
         else:
             sourceDir = self.sourceDir()
             # FIXME this reverts previously applied patches !
             # self.__git('checkout', '-f',cwd=sourceDir)
             sourceDir = self.checkoutDir()
         return self.__git("apply", "--whitespace=fix", "-p %d" % patchdepth, patchfile, cwd=sourceDir)
     return True
Exemplo n.º 50
0
    def fetch(self, repopath=None):
        """try to clone or update the repository"""
        EmergeDebug.trace("HgSource.fetch called", 2)

        # get the path where the repositories should be stored to
        if repopath == None:
            repopath = self.repositoryUrl()

        # in case you need to move from a read only Url to a writeable one, here it gets replaced
#        repoString = utils.replaceVCSUrl( repopath )
        repopath = repopath.replace("[hg]", "")
        repoUrl, repoBranch, _ = utils.splitVCSUrl(repopath)
        ret = True

        # only run if wanted (e.g. no --offline is given on the commandline) or no hg support is given by the python installation
        if (not self.noFetch and self.enableHg):
            # question whether mercurial stuff uses these proxies
            self.setProxy()
            checkoutDir = self.checkoutDir()

            # check corrupted checkout dir
            if os.path.exists(checkoutDir) and not os.path.exists(checkoutDir +
                                                                  "\.hg"):
                os.rmdir(checkoutDir)

            if not os.path.exists(checkoutDir):
                os.makedirs(checkoutDir)
                os.chdir(checkoutDir)
                ret = self.system(
                    "%s clone %s ." %
                    (self.hgExecutable,
                     repoUrl))  # TODO: check return code for success

            if os.path.exists(checkoutDir):
                os.chdir(checkoutDir)
                ret = self.system(
                    "%s update %s" %
                    (self.hgExecutable,
                     repoBranch))  # TODO: check return code for success
        else:
            EmergeDebug.debug("skipping hg fetch (--offline)")
        return ret
Exemplo n.º 51
0
    def sourceVersion( self ):
        """ return the revision of the repository """
        EmergeDebug.trace("HgSource.sourceVersion called", 2)

        if self.enableHg:

            # open a temporary file - do not use generic tmpfile because this doesn't give a good file object with python
            with open( os.path.join( self.checkoutDir().replace('/', '\\'), ".emergehgtip.tmp" ), "wb+" ) as tempfile:

                # run the command
                utils.system( "%s tip" % self.hgExecutable, stdout=tempfile )
                # TODO: check return value for success
                tempfile.seek( os.SEEK_SET )

                # read the temporary file and grab the first line
                revision = tempfile.readline().replace("changeset:", "").strip()

            os.remove( os.path.join( self.checkoutDir().replace('/', '\\'), ".emergehgtip.tmp" ) )
        # always return True to not break something serious
        return revision
Exemplo n.º 52
0
 def applyPatch(self, fileName, patchdepth, unusedSrcDir=None):
     """apply single patch o git repository"""
     EmergeDebug.trace('GitSource ', 2)
     if fileName:
         patchfile = os.path.join ( self.packageDir(), fileName )
         if emergeSettings.getboolean("General","EMERGE_GIT_MULTIBRANCH", False):
             repopath = self.repositoryUrl()
             # in case you need to move from a read only Url to a writeable one, here it gets replaced
             repopath = repopath.replace("[git]", "")
             repoString = utils.replaceVCSUrl( repopath )
             repoBranch = utils.splitVCSUrl( repoString )[1] or "master"
             sourceDir = os.path.join(self.checkoutDir(), repoBranch)
         else:
             sourceDir = self.sourceDir()
             #FIXME this reverts previously applied patches !
             #self.__git('checkout', '-f',cwd=sourceDir)
             sourceDir = self.checkoutDir()
         return self.__git('apply', '--whitespace=fix',
                 '-p %d' % patchdepth, patchfile, cwd=sourceDir)
     return True
Exemplo n.º 53
0
    def checkoutDir(self, index=0):
        EmergeDebug.trace("SvnSource.checkoutDir", 2)
        if self.subinfo.hasSvnTarget():
            u = self.getUrl(index)
            (url, dummy) = self.splitUrl(u)

            if url.find("://") == -1:
                sourcedir = os.path.join(EmergeStandardDirs.svnDir(), url)
            else:
                sourcedir = os.path.join(EmergeStandardDirs.downloadDir(),
                                         "svn-src")
                sourcedir = os.path.join(sourcedir, self.package)
                _, path = self.__splitPath(url)
                if path and emergeSettings.getboolean(
                        "General", "EMERGE_SVN_STDLAYOUT", False):
                    sourcedir = os.path.join(sourcedir, path)
        else:
            EmergeDebug.die("svnTarget property not set for this target")

        if self.subinfo.targetSourceSuffix() != None:
            sourcedir = "%s-%s" % (sourcedir,
                                   self.subinfo.targetSourceSuffix())

        return sourcedir
Exemplo n.º 54
0
 def __init__(self, subinfo=None):
     EmergeDebug.trace("SvnSource.__init__", 2)
     if subinfo:
         self.subinfo = subinfo
     VersionSystemSourceBase.__init__(self)
     self.options = None
Exemplo n.º 55
0
 def checkoutDir(self, index=0 ):
     EmergeDebug.trace('GitSource checkoutDir', 2)
     return VersionSystemSourceBase.checkoutDir( self, index )
Exemplo n.º 56
0
    def __fetchSingleBranch( self, repopath = None ):
        EmergeDebug.trace('GitSource __fetchSingleBranch', 2)
        # get the path where the repositories should be stored to
        if repopath == None:
            repopath = self.repositoryUrl()
        EmergeDebug.debug("fetching %s" % repopath)

        # in case you need to move from a read only Url to a writeable one, here it gets replaced
        repopath = repopath.replace( "[git]", "" )
        repoString = utils.replaceVCSUrl( repopath )
        [ repoUrl, repoBranch, repoTag ] = utils.splitVCSUrl( repoString )
        if not repoBranch and not repoTag:
            repoBranch = "master"

        ret = True
        # only run if wanted (e.g. no --offline is given on the commandline)
        if ( not self.noFetch ):
            self.setProxy()
            safePath = os.environ[ "PATH" ]
            # add the git path to the PATH variable so that git can be called without path
            os.environ[ "PATH" ] = os.path.join( self.rootdir, "git", "bin" ) + ";" + safePath
            checkoutDir = self.checkoutDir()
            # if we only have the checkoutdir but no .git within,
            # clean this up first
            if os.path.exists(checkoutDir) \
                    and not os.path.exists(os.path.join(checkoutDir, ".git")):
                os.rmdir(checkoutDir)
            if os.path.exists(checkoutDir):
                if not repoTag:
                    self.__git("fetch")
                    ret = self.__git("checkout", repoBranch or "master") and \
                          self.__git("merge")
                    if self.subinfo.options.fetch.checkoutSubmodules:
                        self.__git("submodule update --init --recursive")
            else:
                # it doesn't exist so clone the repo
                os.makedirs( checkoutDir )
                # first try to replace with a repo url from etc/portage/emergehosts.conf
                recursive = '--recursive' if self.subinfo.options.fetch.checkoutSubmodules else ''
                ret = self.__git('clone', recursive, repoUrl, '.')

            # if a branch is given, we should check first if the branch is already downloaded
            # locally, otherwise we can track the remote branch
            if ret and repoBranch and not repoTag:
                track = ""
                if not self.__isLocalBranch( repoBranch ):
                    track = "--track origin/"
                ret = self.__git('checkout', "%s%s" % (track, repoBranch ))

            # we can have tags or revisions in repoTag
            if ret and repoTag:
                if self.__isTag( repoTag ):
                    if not self.__isLocalBranch( "_" + repoTag ):
                        ret = self.__git('checkout', '-b', '_%s' % repoTag, repoTag)
                    else:
                        ret = self.__git('checkout', '_%s' % repoTag)
                else:
                    ret = self.__git('checkout', repoTag)

        else:
            EmergeDebug.debug("skipping git fetch (--offline)")
        return ret