当前位置: 首页>>代码示例>>Python>>正文


Python Repo.pull方法代码示例

本文整理汇总了Python中git.Repo.pull方法的典型用法代码示例。如果您正苦于以下问题:Python Repo.pull方法的具体用法?Python Repo.pull怎么用?Python Repo.pull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在git.Repo的用法示例。


在下文中一共展示了Repo.pull方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: process

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import pull [as 别名]
 def process(branch, commit):
     # Select git dir
     git = Repo(owner+"/"+repo).git
     # Switch to branch
     print "Switching to branch "+branch
     git.checkout(branch)
     # Pull latest edits
     print "Pulling edits.."
     git.pull()
     # Run ccpcheck
     print "Running ccpcheck.."
     includes = "{owner}/{repo}/include".format(owner=owner, repo=repo)
     sources = "{owner}/{repo}/src".format(owner=owner, repo=repo)
     enabled_settings = "--enable=warning,style,performance,portability,information,missingInclude"
     cppres = Popen(["cppcheck", enabled_settings, "-I", includes, sources], stdout=PIPE, stderr=PIPE).stderr.readlines()
     cdata = {"id":commit["id"], "timestamp":commit["timestamp"], "owner":owner, "repo":repo, "branch": branch, "message":commit["message"], "author":commit["author"]}
     filepath = owner+"."+repo+"."+branch.replace("/",".")
     # Load old file (if it exists)
     if os.path.isfile(filepath+".cppcheck.log"):
         with open(owner+"/"+filepath+".cppcheck.diff","r") as difffile:
             oldcpp = difffile.readlines()
             cppdiff = difflib.unified_diff(oldcpp, cppres)
             outcpp = ''.join(cppdiff)
     else:
         outcpp = ''.join(cppres)
     # Run clang static analyzer (scan-build)
     print "Running clang static analyzer.."
     clangres = Popen(["scan-build","--use-analyzer","/usr/bin/clang","-o","/var/www/scans/"+owner+"/"+repo,"gmake","clean","liboleg","oleg_test"], cwd=owner+"/"+repo, stdout=PIPE, stderr=PIPE).stdout.readlines()
     last = clangres[len(clangres)-1]
     if last.find("No bugs") < 0:
         cdata["dir"] = last[last.find("20"):last.find("examine")-5]
     # Write to files
     with open(owner+"/"+filepath+".cppcheck.diff","w") as difffile:
         difffile.write(''.join(cppres))
     with open(owner+"/"+filepath+".cppcheck.log","w") as cppfile:
         cppfile.write(outcpp)
     with open(owner+"/"+filepath+".json", "w") as logfile:
         logfile.write(json.dumps(cdata))
     print "Logfile written!"
     return "All okay!"
开发者ID:qpfiffer,项目名称:richelieu,代码行数:42,代码来源:scripts.py

示例2: release_kuber

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import pull [as 别名]
def release_kuber(context, app, version):
    # check whether the app belongs to the context
    if app not in config.app_dict.get(context, []):
        log.error('Provided app does not belong to the context')
        return

    to_kuber = os.path.join(os.getcwd(), 'hellonode')
    git = Repo(os.path.abspath('{}/..'.format(to_kuber))).git
    git = Repo('{}'.format(os.getcwd())).git
    git.checkout('master')
    git.pull()

    try:
        try:
        # check whether a container with app name and provided version number exists
            print version
            version = version if version.startswith('v') else 'v'+version
            print version
            container_tags = subprocess.check_output(['gsutil', 'ls', '{}/{}/tag_{}'.format(
                                config.gs_path_to_app, app, version)])
            log.info('App and version check successful')
        except:
            log.error('The container with provided app and version number does not exist')
            return

        # modify app.yml file with new version
        yaml_file = '{}.yml'.format(app)

        print os.getcwd()
        with open(yaml_file) as f:
            yaml_dict = yaml.load(f)

        _update_yaml_file(yaml_dict, version)

        with open(yaml_file, 'w') as f:
            yaml.dump(yaml_dict, f, default_flow_style=False)

        # get replication controller name, sample output of this command:
        # CONTROLLER              CONTAINER (S)     IMAGES            SELECTOR     REPLICAS
        # backend-controller      applier           applier_2.3.11    applier      3
        rc_name = subprocess.check_output(['kubectl','get', 'deployment',
                                           '{}'.format(app)]).split('\n')[1].split()[0]

        log.info('Applying New Configuration')
        # run rolling update
        exit_code = subprocess.call(['kubectl', 'apply', '-f', yaml_file])

        # if rolling update succeeds, commit changes in Git repo and push back to master
        if exit_code == 0:
            log.info('Updated {} to {} successfully'.format(app, version))
            git.add(yaml_file)
            commit_message = ' bump {} to {}'.format(app, version)
            git.commit(m=commit_message)
            log.info(commit_message)
            git.push()
        else:
            log.error('Errors in updating deployment, exit code:{}'.format(exit_code))
            git.checkout('.')

    except Exception as e:
        git.checkout('.')
        log.exception('Exception:{}'.format(e))
开发者ID:ishaqsharief318,项目名称:kubernetes-test,代码行数:64,代码来源:release_kuber.py

示例3: release_kuber

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import pull [as 别名]
def release_kuber(context, app, version):
    # check whether the app belongs to the context
    if app not in config.app_dict.get(context, []):
        log.error('Provided app does not belong to the context')
        return

    git = Repo('{}/..'.format(os.getcwd())).git
    git.checkout('master')
    git.pull()

    try:
        # # check whether a container with app name and provided version number exists
        # container_tags = subprocess.check_output(['gsutil', 'ls', '{}/{}'.format(config.gs_path_to_app, app)])
        # container_exist = False
        #
        # for tag in container_tags.split('\n'):
        #     # tag sample:
        #     # gs://artifacts.sojern-platform.appspot.com/containers/repositories/library/applier/tag_2.3.11
        #     version_list = re.findall('\d+\.\d+\.\d+', tag.split('/')[-1])
        #     if version_list and version_list[0] == version:
        #         container_exist = True
        #         break
        #
        # if not container_exist:
        #     log.error('The container with provided app and version number does not exist')
        #     return

        # modify app.yml file with new version
        yaml_file = '{}.yml'.format(app)

        with open(yaml_file) as f:
            yaml_dict = yaml.load(f)

        _update_yaml_file(yaml_dict, version)

        with open(yaml_file, 'w') as f:
            yaml.dump(yaml_dict, f, default_flow_style=False)

        # get replication controller name, sample output of this command:
        # CONTROLLER              CONTAINER (S)     IMAGES            SELECTOR     REPLICAS
        # backend-controller      applier           applier_2.3.11    applier      3
        rc_name = subprocess.check_output(['kubectl', '--context={}'.format(context), 'get', 'rc',
                                           '--selector=run={}'.format(app)]).split('\n')[1].split()[0]

        print 'controller name:', rc_name
        # run rolling update
        exit_code = subprocess.call(['kubectl', '--context=vagrant', 'rolling-update',
                                     '{}'.format(rc_name), '-f', yaml_file])

        # if rolling update succeeds, commit changes in Git repo and push back to master
        if exit_code == 0:
            log.info('Rolling update {} to {} successfully'.format(app, version))
            git.add(yaml_file)
            git.commit(m='bump {} to {}'.format(app, version))
            git.push()
        else:
            log.error('Errors in rolling update command, exit code:{}'.format(exit_code))
            git.checkout('.')

    except Exception as e:
        git.checkout('.')
        log.exception('Exception:{}'.format(e))
开发者ID:yangxiangliang,项目名称:kubertest,代码行数:64,代码来源:release_kuber.py

示例4: on_message

# 需要导入模块: from git import Repo [as 别名]
# 或者: from git.Repo import pull [as 别名]
def on_message(message):

        #log.info('received a message: %s' % message)
        try:
            dict_msg = json.loads(message)

            action = dict_msg.get('action')

            payload = dict_msg.get('payload')
        except ValueError: #this section deals with the case when the message is not a json message and as a result cannot be processed. Considering that the messages are generated by the NFVO this is not supposed to happen
            print "Not a json object"
            action = None
            out = None
            err = "Not a json message"
            status = "1"
        if action == 'SAVE_SCRIPTS':
            path = dict_msg.get('script-path')
            try:
                script = base64.b64decode(payload)

                if path == None:
                    print "No path provided, saving into default directory"
                    path = SCRIPTS_PATH
                if not os.path.exists(path):
                    os.makedirs(path)
                name = dict_msg.get('name')

                if path[-1] == "/":
                    path_name = path + name
                else:
                    path_name = path + "/" + name

                os.environ['SCRIPTS_PATH'] = path
                f = open(path_name, "w")
                f.write(script)
                log.info("Written %s into %s" % (script, path_name))
                out = str(os.listdir(path))
                err = ""
                status = 0
                st = os.stat(path)
                os.chmod(path, st.st_mode | 0111)
                st = os.stat(path_name)
                os.chmod(path_name, st.st_mode | 0111)
            except TypeError: #catches typeerror in case of the message not being properly encoded
                print "Incorrect script encoding"
                action = None
                out = None
                err = "Incorrect script encoding"
                status = "1"

        if action == 'CLONE_SCRIPTS':
            path = dict_msg.get('script-path')
            if path == None:
                path = SCRIPTS_PATH
            url = payload
            os.environ['SCRIPTS_PATH'] = path
            log.debug("Cloning into: %s" % url)
            try:
                Repo.clone_from(url, path)
                print 'Cloned'
                log.debug('Cloned')
            except GitCommandError as e:
                print 'Encountered error'
                err = traceback.format_exc()
                status = e.status
                out = None
            else:
                out = str(os.listdir(path))
                err = ""
                status = 0
        elif action == "EXECUTE":
            if payload[-1] == "/":
                payload = SCRIPTS_PATH + payload
            else:
                payload = SCRIPTS_PATH + "/" + payload
            env = dict_msg.get('env')
            log.debug("Executing: %s with env %s" % (payload, env))
            if env is None or len(env) == 0:
                env = None
            else:
                env.update(os.environ)
            ems_out_log = open('/var/log/openbaton/ems-out.log', "w+")
            ems_err_log = open('/var/log/openbaton/ems-err.log', "w+")

            proc = subprocess.Popen(["/bin/bash"] + payload.split(), stdout=ems_out_log, stderr=ems_err_log, env=env)
            status = proc.wait()
            ems_out_log.seek(0)
            ems_err_log.seek(0)
            out = ems_out_log.read()
            err = ems_err_log.read()

            ems_out_log.close()
            ems_err_log.close()
            log.debug("Executed: ERR: %s OUT: %s", err, out)


        elif action == "SCRIPTS_UPDATE":
            url = payload
            try:
                Repo.pull(url, "/opt/openbaton/scripts/")
#.........这里部分代码省略.........
开发者ID:gbernini,项目名称:lcm-agent,代码行数:103,代码来源:receiver.py


注:本文中的git.Repo.pull方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。