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


Python GitHub.search方法代码示例

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


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

示例1: Bat

# 需要导入模块: from github import GitHub [as 别名]
# 或者: from github.GitHub import search [as 别名]
class Bat(object):

    CURR_SCRIPT = ''
    VIM_PATH = path.join(path.expanduser('~'), '.vim')
    AUTOLOAD_PATH = path.join(VIM_PATH, 'autoload')
    VIMPYRE_PATH = path.join(VIM_PATH, 'vimpyre')
    
    @property
    def pathogen_url(self):
        try:
            return environ['VIM_PATHOGEN_URL']
        except:
            return 'https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim'

    def __init__(self, script = ''):
        self.CURR_SCRIPT = script
        self.github = GitHub()

    def _check_name(self):
        if self.CURR_SCRIPT.startswith('http') or self.CURR_SCRIPT.startswith('git'):
            return self.CURR_SCRIPT

        try:
            search_ret = self.search()
            rets = [item for item in search_ret if self.CURR_SCRIPT == item['name']]
            if rets:
                rets[0]['homepage'] = 'https://github.com/' + self.CURR_SCRIPT
                return rets[0]
            return []
        except:
            pass

    def _filter_script_name(self):
        return self.CURR_SCRIPT.split('/')[-1]

    def _render_fetch_url(self, ret):
        if type(ret) == dict:
            fetch_url = ret['url'] + '.git'
        else:
            fetch_url = ret

        return fetch_url

    @property
    def bundles(self):
        """ List of bundles in the vimpyre path """
        try:
            with util.cd(self.VIMPYRE_PATH):
                return [item for item in listdir('.') if path.isdir(item)]
        except OSError:
            console('Cannot access your vimpyre path!')

    def install_base(self):
        """
        Install pathogen.vim and create vimpyre directory.

            >>> bat = Bat()
            >>> bat.install_base()
            => => Send a bat to catch pathogen.vim ...
            Catch done! Please add the following message to your .vimrc:
            execute pathogen#infect('bundle/{}', 'vimpyre/{}')
        """
        try:
            console('=> => Send a bat to catch pathogen.vim ...')
            raw_urlopen = urllib.urlopen(self.pathogen_url)
            if raw_urlopen.getcode() == 200:
                util.mkdir_p(self.AUTOLOAD_PATH)
                util.mkdir_p(self.VIMPYRE_PATH)
                raw_pathogen = raw_urlopen.read()
                pathogen = path.join(self.AUTOLOAD_PATH, 'pathogen.vim')
                with open(pathogen, 'w') as f:
                    f.write(raw_pathogen)
                console('Catch done! Please add the following to your .vimrc:')
                console("execute pathogen#infect('bundle/{}', 'vimpyre/{}')")
            else:
                console('Pathogen vimscript not found in %s' % self.pathogen_url)
                console('You can change this url with enviroment variable VIM_PATHOGEN_URL')
                console('Catch fail! Please try again!')
        except:
            console('[Unexpected Error] Catch fail! Please try again!')

    def install(self):
        console('=> => Send a bat to catch %s' % self.CURR_SCRIPT)

        try:
            ret = self._check_name()
            if ret:
                fetch_url = self._render_fetch_url(ret)
                cmd_fetch = 'git clone --depth 1 %s' % fetch_url
                util.mkdir_p(self.VIMPYRE_PATH)
                with util.cd(self.VIMPYRE_PATH):
                    system(cmd_fetch)
            else:
                msg = ('%s not found! Please use `vimpyre search <vim-script>`'
                       ' to check the script name and install again!' %
                       self.CURR_SCRIPT)
                console(msg)
        except:
            self.install_base()

#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:


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