示例#1
0
 def freezeRepo(self,  repo):
     id = repo.getID()
     href = repo.getHref()
     rcs = repo.getRcs()
     path = repo.getPath()
     rev = repo.getRSpecRevision()
     repo_path = repo.getAbsLocalPath()
     #TODO: make it possible to base the freeze on an existing rspec (only freeze repos included in there)
     if (rcs == 'svn' or rcs == 'git'):
         if rev == 'HEAD' or rev == None or rev == 'master':
             curr_rev = self.rcsclient[rcs].getRevisionFromWorkingCopy(repo_path)
         else:
             curr_rev = self.rcsclient[rcs].getRevisionFromWorkingCopy(repo_path)
             if str(curr_rev) != rev:
                 warningMessage('%s: Overwriting strict revision nr %s with %s'%(id, str(rev),  str(curr_rev)))
         self.xmlgenerator.characters("\t")
         self.xmlgenerator.startElement('ctx-repo',  attrs = {'id':id,'rcs':rcs, 'href': href,  'rev': str(curr_rev),  'path':path })
         self.xmlgenerator.characters("\n")
     else:
         warningMessage("Currently only supporting freeze for svn-repos, skipping '%s'"%repo_path)
         return
     paths = repo.getAllRelativePaths()
     for path_type in paths:
         for  path_spec in paths[path_type]:
             self.xmlgenerator.characters("\t\t")
             self.xmlgenerator.startElement('ctx-path',  attrs = {'type':path_type,  'spec':path_spec})
             self.xmlgenerator.endElement('ctx-path')
             self.xmlgenerator.characters("\n")
     self.xmlgenerator.characters("\t")
     self.xmlgenerator.endElement('ctx-repo')
     self.xmlgenerator.characters("\n\n")
示例#2
0
    def locateItem(self, item, path_sections):

        candidate_locations = list()
        tried_locations = list()

        path_sections = assureList( path_sections )

        for path_section in path_sections:
            # Always prioritize locating items from the RSpec repositories
            if path_section in REPO_PATH_SECTIONS and self.getRSpec() != None:
                for repo in self.getRSpec().getRepositories():
                    repo_candidates, repo_tried = repo.locateItem( item, path_section )
                    candidate_locations.extend( repo_candidates )
                    tried_locations.extend( repo_tried )

            if len(candidate_locations) == 1:
                infoMessage("Located '%s' at '%s'"%(item, candidate_locations[0]), 2)
                return candidate_locations[0]
            elif len(candidate_locations) > 1:
                userErrorExit("Multiple occurances of '%s' was found. Unable to determine which one to use: \n   %s"\
                               %(item, "\n   ".join(candidate_locations)))

        # Item not present in any repository, be clear to the user..
        if self.getRSpec() != None:
            if self.getAccessPolicy() == AP_NO_REMOTE_ACCESS:
                infoMessage("Item '%s' was not found in RSpec repositories.\nNote that the system is set to search for repository items in the local view only (%s).\nTrying system global locations."%(item, AP_FLAGS[self.getAccessPolicy()]), 2)
            elif self.getAccessPolicy() == AP_PREFER_REMOTE_ACCESS:
                infoMessage("Item '%s' was not found in RSpec repositories.\nNote that the system is set to search for repository items at the repository source location only (%s).\nTrying system global locations."%(item, AP_FLAGS[self.getAccessPolicy()]), 2)
            else:
                infoMessage("Item '%s' was not found in RSpec repositories.\nTrying system global locations."%(item), 2)

        for path_section in path_sections:
            # File was not found in RSpec repositories, look in view
            if path_section in SYSGLOBAL_PATH_SECTIONS:
                for path in self.getGlobalPaths(path_section):
                    tried_locations.append( path )
                    if os.path.isdir(path):
                        if item in os.listdir(path):
                            candidate_locations.append( os.path.join(path, item) )
                    else:
                        tried_locations[-1] = tried_locations[-1] + " (path not found)"
                        warningMessage("System global path '%s' doesn't exist"%(path))

            if len(candidate_locations) == 1:
                infoMessage("Located '%s' at '%s'"%(item, candidate_locations[0]), 2)
                return candidate_locations[0]
            elif len(candidate_locations) > 1:
                userErrorExit("Multiple occurances of '%s' was found. Unable to determine which one to use: \n   %s"\
                               %(item, "\n   ".join(candidate_locations)))


        userErrorExit("Unable to locate file '%s'. Attempted the following locations: \n   %s"\
                       %(item, "\n   ".join(tried_locations)))
示例#3
0
    def locateItem(self, item, path_sections):

        candidate_locations = list()
        tried_locations = list()

        path_sections = assureList( path_sections )

        for path_section in path_sections:
            # Always prioritize locating items from the RSpec repositories
            if path_section in REPO_PATH_SECTIONS and self.getRSpec() != None:
                for repo in self.getRSpec().getRepositories():
                    repo_candidates, repo_tried = repo.locateItem( item, path_section )
                    candidate_locations.extend( repo_candidates )
                    tried_locations.extend( repo_tried )

            if len(candidate_locations) == 1:
                infoMessage("Located '%s' at '%s'"%(item, candidate_locations[0]), 2)
                return candidate_locations[0]
            elif len(candidate_locations) > 1:
                userErrorExit("Multiple occurances of '%s' was found. Unable to determine which one to use: \n   %s"\
                               %(item, "\n   ".join(candidate_locations)))
            infoMessage("Item '%s' was not found in RSpec repositories.\nTrying system global locations."%(item), 2) 

        for path_section in path_sections:
            # File was not found in RSpec repositories, look in view
            if path_section in SYSGLOBAL_PATH_SECTIONS:
                for path in self.getGlobalPaths(path_section):
                    tried_locations.append( path )
                    if os.path.isdir(path):
                        if item in os.listdir(path):
                            candidate_locations.append( os.path.join(path, item) )
                    else:
                        tried_locations[-1] = tried_locations[-1] + " (path not found)"
                        warningMessage("System global path '%s' doesn't exist"%(path))

            if len(candidate_locations) == 1:
                infoMessage("Located '%s' at '%s'"%(item, candidate_locations[0]), 2)
                return candidate_locations[0]
            elif len(candidate_locations) > 1:
                userErrorExit("Multiple occurances of '%s' was found. Unable to determine which one to use: \n   %s"\
                               %(item, "\n   ".join(candidate_locations)))


        userErrorExit("Unable to locate file '%s'. Attempted the following locations: \n   %s"\
                       %(item, "\n   ".join(tried_locations)))
示例#4
0
    def update(self):
        import ctx_view
        import subprocess

        origin_href = self.getRemote('origin')
 
        if origin_href != self.href:
            warningMessage("rspec href is set to %s, but the git repository origin is set to %s. Using git repository origin"%(self.href, origin_href))

        os.chdir(self.destpath)

        infoMessage("Fetching new tags in '%s': 'git fetch'"%(self.id_name))
        p = subprocess.Popen([self.git, 'fetch'], bufsize=4096)
        retcode = p.wait()
        if retcode != 0:
            warningMessage("could not fetch from %s"%(self.href))
            sys.exit(1)
        
        workingBranchName = self.getBranch()
        # getBranch changes dir, go back to git dir
        restoreWorkBranch = False

        infoMessage("Checking out %s in %s 'git checkout %s'"%(self.rev, self.id_name, self.rev),1)
        os.chdir(self.destpath)
        p = subprocess.Popen([self.git, 'checkout', self.rev], bufsize=4096)
        retcode = p.wait()
        if retcode != 0:
            sys.exit(1)
        updateBranchName = self.getBranch()
        # getBranch changes dir, go back to git dir
        os.chdir(self.destpath)
        if updateBranchName != '' and updateBranchName != '(no branch)':
            infoMessage("Updating branch '%s' in '%s': 'git pull %s %s''"%(self.rev, self.id_name, 'origin', self.rev))
            p = subprocess.Popen([self.git, 'pull', 'origin', self.rev], bufsize=4096)
            retcode = p.wait()
            print >>sys.stderr, ''
            if retcode != 0:
                #print >>sys.stderr, p.stderr.read()
                errorMessage("could not pull from %s"%(self.href))
                exit(retcode)

        os.chdir(self.path)
示例#5
0
    def startElement(self, name, attrs):

        # .....................................................................
        if name == 'ctx-rspec':
            if self.parent_element.peek() != None:
                userErrorExit("'<ctx-rspec>' can only be used as root element")

        # .....................................................................
        elif name == 'ctx-import':
            # Make sure this element is used in correct context
            if self.parent_element.peek() != 'ctx-rspec':
                userErrorExit("'%s' elements can only be used within '%s' elements"%(name, 'ctx-rspec'))

            #
            # Digest import and check for errors/inconsistencies
            #

            href = attrs.get('href', None)
            if href == None:
                userErrorExit("<ctx-import>: Missing mandatory attribute '%s' in RSpec '%s'"%('href', self.rspecFile.getFilename()))

            rcs = attrs.get('rcs', None)
            if rcs == None and attrs.has_key('rev'):
                userErrorExit("<ctx-import>: Revision ('rev') specified without specifying 'rcs' in RSpec '%s'"%(self.rspecFile.getFilename()))

            rev = attrs.get('rev', None )
            if rcs != None and rev == None:
                warningMessage("<ctx-import>: No revision specified for import in RSpec '%s'. Assuming 'HEAD'"%(self.rspecFile.getFilename()))
                rev = 'HEAD'

            # Prepare locator object and add import to current RSpec
            rspecFileLocator = RSpecFileLocator( rcs=rcs, href=href, revision=rev, updating = False, wipe_cache=False, view=self.view )
            self.rspecFile.addImport( rspecFileLocator ) # POINT OF RECURSION

        # .....................................................................
        elif name == 'ctx-repo':

            # Make sure this element is used in correct context
            if self.parent_element.peek() != 'ctx-rspec':
                userErrorExit("'%s' elements can only be used within '%s' elements"%(name, 'ctx-rspec'))

            # Make sure 'id' attribute is unique within RSpec
            if attrs.has_key('id'):
                if attrs.get('id') in self.id_list:
                    userErrorExit("Multiple occurances of id '%s' in '%s'"%(attrs.get('id'), self.rspecFile.getFilename()))
                else:
                    self.id_list.append(attrs.get('id'))

            self.current_repo = createRepoFromRCS( attrs.get('rcs', None),
                                                   attrs.get('id', ""),
                                                   attrs.get('path', ""),
                                                   attrs.get('href', ""),
                                                   attrs.get('rev', ""))
            self.rspecFile.addRepository ( self.current_repo )

        # .....................................................................
        elif name == 'ctx-path':

           # Make sure this element is used in correct context
            if self.parent_element.peek() not in ['ctx-repo',]:
                userErrorExit("'<%s>' elements cannot be used within '<%s>' elements"%(name, self.parent_element.peek()))

            #
            # Assure presence of mandatory attributes
            #

            attribute = 'type'
            if not attrs.has_key(attribute):
                userErrorExit("Missing mandatory attribute '%s' in element '<%s>'"%(attribute, name))

            attribute = 'spec'
            if not attrs.has_key(attribute):
                userErrorExit("Missing mandatory attribute '%s' in element '<%s>'"%(attribute, name))

            ctx_path_type = attrs.get( 'type' ).lower()
            self.current_repo.addPath( ctx_path_type, attrs.get('spec').replace('\\','/') )

        # .....................................................................
        else:
            warningMessage("Ignoring unknown element '<%s>' in RSpec '%s'.\nThis might be a normal compatibility issue."%(name, self.rspecFile.getFilename()))

        self.parent_element.push( name )
示例#6
0
 def characters (self, ch):
     warningMessage("Ignoring character data '%s' found in element '%s'"%(ch, self.parent_element.peek()))