Example #1
0
def get_git(scheme,url,target,overwrite,tag):
    import git

    if os.path.exists(target + '/.git'):
        if not overwrite: return
    else:
        if len(scheme) == 1: giturl = url
        else: giturl = url[4:]
        git.clone(giturl,target)

    fs.goto(target)
    git.fetch()
    out = git.branch()
    for line in out.split('\n'):
        if not line: continue
        if line[0] != '*': continue
        out = line.split()[1]
        break
    #print out,tag
    if out != tag:
        lbranches,rbranches = git.branches()
        if tag in lbranches:
            git.checkout(tag)
        else:
            # git 1.5 does not put remotes/ like 1.6 does
            from exception import CommandFailure
            try:
                git.checkout('origin/'+tag,tag)
            except CommandFailure:
                git.checkout('remotes/origin/'+tag,tag)
    git.pull()
    fs.goback()
    return
Example #2
0
 def _fix_projects(self):
     import fs,os,cmt
     from command import source
     fs.goto(os.path.join(self.dstdir,'projects'))
     environ = source('./setup.sh')
     for pobj in self.project_objects:
         pdir = os.path.join(self.dstdir,'projects',pobj.name,pobj.rel_pkg(),'cmt')
         cmt.cmt("config",environ=environ,dir=pdir)
         pkgenv = source('./setup.sh',env=environ,dir=pdir)
         cmt.cmt("br cmt config",environ=pkgenv,dir=pdir)
     fs.goback()
Example #3
0
    def _git_checkout(self,tag,pkg=""):
        import fs,git
        fs.goto(os.path.join(fs.projects(),'gaudi',pkg))

        lbranches,rbranches = git.branches()
        if tag in lbranches:
            git.checkout(tag)
        else:
            git.checkout('origin/'+tag,tag)

        fs.goback()
        return
Example #4
0
def cmd(cmdstr,env=None,dir=None,output=False,loglevel=log.INFO):
    '''
    Run an arbitrary command given by first non-optional argument.  If
    it is a full command line string it will be broken down via a
    split() on spaces.  If spaces are meaningful, pass in a list of
    strings.

    If env is defined it will be set the environment in which the
    command is run.

    If dir is set the command will be run after going to that
    directory.

    If output is True, the stdout/stderr will be returned as a string.

    Passing loglevel to set at what level the output should be logged.

    Avoid calling this function in favor of specific command function
    '''
    out = []

    # Convert to list if given a string
    if type(cmdstr) == type(""):
        cmdstr = cmdstr.strip()
        cmds = cmdstr.split()
        if len(cmds) > 1: cmdstr = cmds

    if not env: env = os.environ

    from subprocess import Popen, PIPE, STDOUT

    if dir: fs.goto(dir)

    log.info('running: "%s" in %s'%(cmdstr,os.getcwd()))

    # Must update this explicitly since env is not tied to this
    # application's env.
    env['PWD'] = os.getcwd()

    #log.info('\n'.join(map(lambda x: '"%s" --> "%s"'%x, env.iteritems())))

    # Start the command
    #print 'cmdstr="%s", env=%s'%(cmdstr,env)

    try:
        proc = Popen(cmdstr,stdout=PIPE,stderr=STDOUT,universal_newlines=True,env=env)
    except OSError,err:
        if dir: fs.goback()
        log.error_notrace(err)
        log.error_notrace('In directory %s'%os.getcwd())
        raise
Example #5
0
    def _git_clone(self,url,submodules=False):
        import fs,git
        target = fs.projects()+'/gaudi'
        if os.path.exists(target):
            log.info('Directory already exists, skipping clone to: %s'%target)
            return

        fs.goto(fs.projects(),True)
        git.clone(url,'gaudi')
        fs.goback()

        if submodules:
            fs.goto(os.path.join(fs.projects(),'gaudi'),True)
            git.submodule('init')
            git.submodule('update')
            fs.goback()

        return
Example #6
0
    def build_package(self,pkg,cmds = None):
        '''
    for cmd in get config make install
    do
        echo "$pkg: running \"cmt pkg_$cmd\""
        cmt pkg_$cmd
        check_cmd
    done
        '''
        import fs
        fs.assure(os.path.join(fs.external(),'tarFiles'))
        fs.assure(os.path.join(fs.external(),'build/LCG'))
        
        bdir = self.builder_directory(pkg)
        from exception import InconsistentState
        if bdir is None: 
            raise InconsistentState('No builder directory for "%s"'%pkg)
        
        if not cmds:
            print 'Building %s in %s'%(pkg,bdir)

        pkg = os.path.basename(bdir)
        cmtdir = os.path.join(bdir,'cmt')

        envdir = os.path.join('LCG_Builders',pkg)
        environ = self.env(envdir)

        import fs
        fs.goto(cmtdir)
        
        import cmt
        if not cmds: cmds = ['get','config','make','install']
        for what in cmds:
            print '\t%s'%what
            cmt.cmt('pkg_%s'%what, environ=environ, dir=cmtdir)

        
        fs.goback()
        return
Example #7
0
        if res is None: continue
        # fixme: clean up this cut-and-paste of above!
        for line in proc.stdout.readlines():
            if line:
                line = line.strip()
                log.log(loglevel,line)
                if output:
                    out.append(line)
        break

    log_maker.set_format(old_format)

    # Check return code
    if res is not 0:
        if dir: fs.goback()
        else: dir = os.getcwd()
        if isinstance(cmdstr,list): cmdstr = " ".join(cmdstr)
        err = 'Command: "%s" failed with code %d run from directory "%s"'%(cmdstr,res,dir)
        log.error(err)
        log.error('START ENV DUMP:')
        envdump = []
        for k,v in env.items():
            envdump.append('%s=%s'%(k,v))
        log.error('\n%s\nEND ENV DUMP:'%'\n'.join(envdump))
        from exception import CommandFailure
        raise CommandFailure,err

    if dir: fs.goback()
    return '\n'.join(out)