sidebar.py 文件源码

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

项目:rekit-sublime 作者: supnate 项目源码 文件源码
def run(self):
    si = None
    if hasattr(subprocess, "STARTUPINFO"):
      si = subprocess.STARTUPINFO()
      si.dwFlags |= subprocess.STARTF_USESHOWWINDOW

    try:
      #si.wShowWindow = subprocess.SW_HIDE # default
      envPATH = os.environ['PATH'] + LOCAL_PATH
      s = sublime.load_settings("Rekit.sublime-settings")
      if s.get('node_dir') and envPATH.find(s.get('node_dir')) == -1:
        envPATH = envPATH + os.pathsep + s.get('node_dir')
      if s.get('npm_dir') and envPATH.find(s.get('npm_dir')) == -1:
        envPATH = envPATH + os.pathsep + s.get('npm_dir')

      # https://docs.python.org/2/library/subprocess.html
      # Note If specified, env must provide any variables required for the program to execute. 
      # On Windows, in order to run a side-by-side assembly the specified env **must** include a valid SystemRoot.
      envObj = {
        'PATH': envPATH,
        'SYSTEMROOT': os.environ['SYSTEMROOT']
      }

      p = subprocess.Popen(self.command, cwd=self.working_dir, env=envObj, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, bufsize=1, startupinfo=si)
      for line in iter(p.stdout.readline, b''):
        line2 = line.decode().strip('\r\n')
        # only show output for mocha     
        if re.search(r'run_test\.js|build\.js', self.command[1]) is not None:
          show_rekit_output(line2)
      if self.on_done:
        self.on_done()

    except subprocess.CalledProcessError as e:
      # show_rekit_output(str(e))
      show_rekit_output('running node failed:')
      show_rekit_output(str(e))
      sublime.error_message(str(e))

    except OSError as e:
      if e.errno == 2:
        main_thread(sublime.error_message, "Node binary could not be found in PATH\nConsider using the node_dir and npm_dir settings for the Rekit plugin\n\nPATH is: %s" % os.environ['PATH'])
      else:
        show_rekit_output('running node failed:')
        show_rekit_output(str(e))
        raise e

    except Exception as e:
      show_rekit_output('running node failed:')
      show_rekit_output(str(e))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号