def outdated(self): "checks whether the working copy is outdated" if not os.path.isdir(self.name): return True else: os.chdir(self.name) # git remote -v update (fetch everything) cmd = ['git', 'remote', '-v', 'update'] if not pu.isUnix(): cmd = [r'C:\Program Files\Git\bin\sh.exe', '--login', '-c', ' '.join(cmd) ] with open(os.devnull, 'w') as FNULL: status = subprocess.call(cmd, stdout=FNULL, stderr=subprocess.STDOUT) if status: raise Exception('"%s" FAILED with error %d' % (cmd, status)) # git status -uno (check "Your branch is up to date") cmd = ['git', 'status', '-uno'] if not pu.isUnix(): cmd = [r'C:\Program Files\Git\bin\sh.exe', '--login', '-c', ' '.join(cmd) ] out = subprocess.check_output(cmd) out = out.decode() # python 3 returns bytes m = re.search(r'Your branch is up to date', out) os.chdir('..') return (m==None)
def update(self): if not os.path.isdir(self.name): #print "skipping %s" % self.name # should checkout instead #return if pu.isUnix(): cmd = 'git clone %s' % self.repo else: cmd = r'"C:\Program Files\Git\bin\sh.exe" --login -c "git clone %s"' % self.repo status = subprocess.call(cmd, shell=True) if status: raise Exception('"%s" FAILED with error %d' % (cmd, status)) print 'status=', status else: pu.chDir(self.name) if pu.isUnix(): cmd = 'git pull origin master' else: cmd = r'"C:\Program Files\Git\bin\sh.exe" --login -c "git pull origin master"' print cmd # os.system necessite des "" en plus autour de la cmd) #os.system('"%s"' % cmd) status = subprocess.call(cmd, shell=True) if status: raise Exception('"%s" FAILED with error %d' % (cmd, status)) print 'status=', status pu.chDir('..')
def __init__(self, name, repo): self.name = name self.repo = repo # set SVN_SSH, sinon: "can't create tunnel" if not pu.isUnix(): os.environ[ 'SVN_SSH'] = r'C:\\Program Files\\TortoiseSVN\\bin\\TortoisePlink.exe' # '\\\\' ou 'r et \\' !!
def update(self): if not os.path.isdir(self.name): #print "skipping %s" % self.name # should checkout instead #return cmd = 'git clone %s' % self.repo if not pu.isUnix(): cmd = r'"C:\Program Files\Git\bin\sh.exe" --login -c "%s"' % cmd status = subprocess.call(cmd, shell=True) if status: raise Exception('"%s" FAILED with error %d' % (cmd, status)) print('status =', status) else: pu.chDir(self.name) if pu.isUnix(): cmd = 'git pull origin master' else: cmd = r'"C:\Program Files\Git\bin\sh.exe" --login -c "git pull origin master"' print(cmd) # os.system necessite des "" en plus autour de la cmd) #os.system('"%s"' % cmd) status = subprocess.call(cmd, shell=True) if status: raise Exception('"%s" FAILED with error %d' % (cmd, status)) print('status=', status) pu.chDir('..') # set core.filemode=false in .git/config on windows! # (otherwise executable files are considered as diffs) if not pu.isUnix(): pu.chDir(self.name) cmd = 'git config core.filemode false' cmd = r'"C:\Program Files\Git\bin\sh.exe" --login -c "%s"' % cmd print(cmd) status = subprocess.call(cmd, shell=True) if status: raise Exception('"%s" FAILED with error %d' % (cmd, status)) pu.chDir('..')
def update(self): # set SVN_SSH, sinon: "can't create tunnel" if not pu.isUnix(): os.environ[ 'SVN_SSH'] = r'C:\\Program Files\\TortoiseSVN\\bin\\TortoisePlink.exe' # '\\\\' ou 'r et \\' !! if not os.path.isdir(self.name): cmd = 'svn co %s %s' % (self.repo, self.name) else: cmd = 'svn update %s' % self.name print cmd status = subprocess.call(cmd, shell=True) if status: raise Exception('"%s" FAILED with error %d' % (cmd, status))
def main(repos): # checkout/update everything if 1: for rep in repos: rep.update() cfg = chooseCfg() # clean build dir if 1: print 'removing build dir' if os.path.isdir('oo_metaB'): os.rename('oo_metaB', 'oo_metaB_trash' ) # avoid the failure of os.mkdir() is same name is used shutil.rmtree('oo_metaB_trash') os.mkdir('oo_metaB') # could fail (access denied) on Windows: # http://stackoverflow.com/questions/16373747/permission-denied-doing-os-mkdird-after-running-shutil-rmtreed-in-python pu.chDir('oo_metaB') # make if 1: if pu.isUnix(): cmd = 'cmake -C ../oo_meta/CMake/%s ../oo_meta' % cfg else: cmd = r'cmake -C ..\oo_meta\CMake\%s ..\oo_meta' % cfg os.system(cmd) if 1: if pu.isInstalled("BuildConsole") and os.path.isfile('Metafor.sln'): print "[using incredibuild]" os.system('BuildConsole Metafor.sln /rebuild /cfg="Release|x64"') else: ncores = multiprocessing.cpu_count() print "[using cmake --build] with %d core(s)" % ncores os.system('cmake --build . --config Release -- -j%d' % ncores)
def main(repos, opts): # checkout/update everything build_required = False for rep in repos: outdated = rep.outdated() print(rep.name, ": outdated =", outdated) if outdated: build_required = True if not os.path.isdir('oo_metaB'): print('oo_metaB folder is missing!') build_required = True if not build_required: print('=> build is NOT required') print('do you want to force the build (y/[n])?') c = pu.getch() if c=='y' or c=='Y': build_required=True else: print('=> build is required') if build_required: # update for rep in repos: rep.update() cfg = chooseCfg() # requires oo_meta to be checked out! # clean build dir if os.path.isdir('oo_metaB'): print('removing build dir') # http://stackoverflow.com/questions/16373747/permission-denied-doing-os-mkdird-after-running-shutil-rmtreed-in-python os.rename('oo_metaB','oo_metaB_trash') # avoid the failure of os.mkdir() is same name is used shutil.rmtree('oo_metaB_trash') # create folder os.mkdir('oo_metaB') # could fail (access denied) on Windows: pu.chDir('oo_metaB') # cmake cmd = ['cmake', '-C', os.path.join('..','oo_meta','CMake',cfg), os.path.join('..','oo_meta') ] subprocess.call(cmd) """ if pu.isUnix(): cmd='cmake -C ../oo_meta/CMake/%s ../oo_meta' %cfg else: cmd=r'cmake -C ..\oo_meta\CMake\%s ..\oo_meta' %cfg os.system(cmd) """ # build if pu.isInstalled("BuildConsole") and os.path.isfile('Metafor.sln'): print("[using incredibuild]") cmd = ['BuildConsole', 'Metafor.sln', '/rebuild', '/cfg=Release|x64'] subprocess.call(cmd) #os.system('BuildConsole Metafor.sln /rebuild /cfg="Release|x64"') else: ncores = multiprocessing.cpu_count() print("[using cmake --build] with %d core(s)" % ncores) cmd = ['cmake', '--build', '.', '--config', 'Release'] if pu.isUnix(): cmd.extend([ '--', '-j%d' % ncores]) subprocess.call(cmd)