goGuru.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:GoGuru 作者: alvarolm 项目源码 文件源码
def plugin_loaded():
    # load shellenv
    def load_shellenv():
        global shellenv
        from .dep import shellenv

    # try golangconfig
    if get_setting("goguru_use_golangconfig", False):
        try:
            global golangconfig
            import golangconfig
        except:
            error("couldn't import golangconfig:", sys.exc_info()[0])
            log("using shellenv instead of golangconfig")
            # use_golangconfig = False
            load_shellenv()

    else:
        load_shellenv()

    log("debug:", get_setting("goguru_debug", False))
    log("use_golangconfig", get_setting("goguru_use_golangconfig", False))

    # keep track of the version if possible (pretty nasty workaround, any other ideas ?)
    try:
        PluginPath = os.path.dirname(os.path.realpath(__file__))
        p = subprocess.Popen(["git", "describe", "master", "--tags"], stdout=subprocess.PIPE, cwd=PluginPath)
        GITVERSION = p.communicate()[0].decode("utf-8").rstrip()
        if p.returncode != 0:
            debug("git return code", p.returncode)
            raise Exception("git return code", p.returncode)

        defsettings = os.path.join(PluginPath, 'Default.sublime-settings')
        f = open(defsettings, 'r')
        filedata = f.read()
        f.close()
        newdata = filedata.replace(get_setting('goguru_version'), GITVERSION + '_')
        f = open(defsettings, 'w')
        f.write(newdata)
        f.close()
    except:
        debug("couldn't get git tag:", sys.exc_info()[0])

    # read version
    log("version:", get_setting('goguru_version'))

    # check if user setting exists and creates it
    us = sublime.load_settings("GoGuru.sublime-settings")
    if (not us.has('goguru_debug')):
        us.set('goguru_debug', get_setting("goguru_debug", False))
        sublime.save_settings("GoGuru.sublime-settings")
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号