本文整理汇总了Python中ensime_shared.util.Util.write_file方法的典型用法代码示例。如果您正苦于以下问题:Python Util.write_file方法的具体用法?Python Util.write_file怎么用?Python Util.write_file使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ensime_shared.util.Util
的用法示例。
在下文中一共展示了Util.write_file方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: start_process
# 需要导入模块: from ensime_shared.util import Util [as 别名]
# 或者: from ensime_shared.util.Util import write_file [as 别名]
def start_process(self, conf_path, classpath, cache_dir, java_home,
java_flags):
Util.mkdir_p(cache_dir)
log_path = os.path.join(cache_dir, "server.log")
log = open(log_path, "w")
null = open("/dev/null", "r")
args = (
[os.path.join(java_home, "bin", "java")] +
["-cp", classpath] +
[a for a in java_flags.split(" ") if a != ""] +
["-Densime.config={}".format(conf_path),
"org.ensime.server.Server"])
process = subprocess.Popen(
args,
stdin=null,
stdout=log,
stderr=subprocess.STDOUT)
pid_path = os.path.join(cache_dir, "server.pid")
Util.write_file(pid_path, str(process.pid))
def on_stop():
log.close()
with catch(Exception, lambda e: None):
os.remove(pid_path)
return EnsimeProcess(cache_dir, process, log_path, on_stop)
示例2: start_process
# 需要导入模块: from ensime_shared.util import Util [as 别名]
# 或者: from ensime_shared.util.Util import write_file [as 别名]
def start_process(self, classpath):
cache_dir = self.config['cache-dir']
java_flags = self.config['java-flags']
Util.mkdir_p(cache_dir)
log_path = os.path.join(cache_dir, "server.log")
log = open(log_path, "w")
null = open("/dev/null", "r")
java = os.path.join(self.config['java-home'], 'bin', 'java')
if not os.path.exists(java):
raise InvalidJavaPathError(errno.ENOENT, 'No such file or directory', java)
elif not os.access(java, os.X_OK):
raise InvalidJavaPathError(errno.EACCES, 'Permission denied', java)
args = (
[java, "-cp", classpath] +
[a for a in java_flags if a != ""] +
["-Densime.config={}".format(self._config_path),
"org.ensime.server.Server"])
process = subprocess.Popen(
args,
stdin=null,
stdout=log,
stderr=subprocess.STDOUT)
pid_path = os.path.join(cache_dir, "server.pid")
Util.write_file(pid_path, str(process.pid))
def on_stop():
log.close()
with catch(Exception, lambda e: None):
os.remove(pid_path)
return EnsimeProcess(cache_dir, process, log_path, on_stop)
示例3: generate_classpath
# 需要导入模块: from ensime_shared.util import Util [as 别名]
# 或者: from ensime_shared.util.Util import write_file [as 别名]
def generate_classpath(self, scala_version, classpath_file):
project_dir = self.classpath_project_dir(scala_version)
Util.mkdir_p(project_dir)
Util.mkdir_p(os.path.join(project_dir, "project"))
Util.write_file(os.path.join(project_dir, "build.sbt"), self.build_sbt(scala_version, classpath_file))
Util.write_file(os.path.join(project_dir, "project", "build.properties"),
"sbt.version={}".format(self.sbt_version))
log_file = os.path.join(project_dir, "build.log")
log = open(log_file, 'w')
null = open("/dev/null", "r")
# see https://github.com/ensime/ensime-vim/issues/29 on why we use this method
self.vim.command("!(cd {};sbt -Dsbt.log.noformat=true -batch saveClasspath)".format(project_dir))
示例4: _start_process
# 需要导入模块: from ensime_shared.util import Util [as 别名]
# 或者: from ensime_shared.util.Util import write_file [as 别名]
def _start_process(self, classpath):
"""Given a classpath prepared for running ENSIME, spawns a server process
in a way that is otherwise agnostic to how the strategy installs ENSIME.
Args:
classpath (list of str): list of paths to jars or directories
(Within this function the list is joined with a system dependent
path separator to create a single string argument suitable to
pass to ``java -cp`` as a classpath)
Returns:
EnsimeProcess: A process handle for the launched server.
"""
cache_dir = self.config['cache-dir']
java_flags = self.config['java-flags']
iswindows = os.name == 'nt'
Util.mkdir_p(cache_dir)
log_path = os.path.join(cache_dir, "server.log")
log = open(log_path, "w")
null = open(os.devnull, "r")
java = os.path.join(self.config['java-home'], 'bin', 'java.exe' if iswindows else 'java')
if not os.path.exists(java):
raise InvalidJavaPathError(errno.ENOENT, 'No such file or directory', java)
elif not os.access(java, os.X_OK):
raise InvalidJavaPathError(errno.EACCES, 'Permission denied', java)
args = (
[java, "-cp", (';' if iswindows else ':').join(classpath)] +
[a for a in java_flags if a] +
["-Densime.config={}".format(self.config.filepath),
"org.ensime.server.Server"])
process = subprocess.Popen(
args,
stdin=null,
stdout=log,
stderr=subprocess.STDOUT)
pid_path = os.path.join(cache_dir, "server.pid")
Util.write_file(pid_path, str(process.pid))
def on_stop():
log.close()
null.close()
with catch(Exception):
os.remove(pid_path)
return EnsimeProcess(cache_dir, process, log_path, on_stop)
示例5: generate_classpath
# 需要导入模块: from ensime_shared.util import Util [as 别名]
# 或者: from ensime_shared.util.Util import write_file [as 别名]
def generate_classpath(self, scala_version, classpath_file):
project_dir = self.classpath_project_dir(scala_version)
Util.mkdir_p(project_dir)
Util.mkdir_p(os.path.join(project_dir, "project"))
Util.write_file(
os.path.join(project_dir, "build.sbt"),
self.build_sbt(scala_version, classpath_file))
Util.write_file(
os.path.join(project_dir, "project", "build.properties"),
"sbt.version={}".format(self.sbt_version))
# Synchronous update of the classpath via sbt
# see https://github.com/ensime/ensime-vim/issues/29
cd_cmd = "cd {}".format(project_dir)
sbt_cmd = "sbt -Dsbt.log.noformat=true -batch saveClasspath"
inside_nvim = int(self.vim.eval("has('nvim')"))
if inside_nvim:
cmd = "terminal"
import tempfile
tmp_dir = tempfile.gettempdir()
flag_file = "{}/ensime-vim-classpath.flag".format(tmp_dir)
sbt_cmd += "; echo $? > {}".format(flag_file)
self.vim.command("echo 'Waiting for generation of classpath...'")
self.vim.command("terminal ({} && {})".format(cd_cmd, sbt_cmd))
# Block execution when sbt is run
waiting_for_flag = True
while waiting_for_flag:
waiting_for_flag = not os.path.isfile(flag_file)
if not waiting_for_flag:
with open(flag_file, "r") as f:
rtcode = f.readline()
os.remove(flag_file)
if rtcode and int(rtcode) != 0: # error
self.vim.command(
"echo 'Something wrong happened, check the "
"execution log...'")
return None
else:
time.sleep(0.2)
else:
self.vim.command("!({} && {})".format(cd_cmd, sbt_cmd))
success = self.reorder_classpath(classpath_file)
if not success:
self.vim.command("echo 'Classpath ordering failed.'")
return True
示例6: install
# 需要导入模块: from ensime_shared.util import Util [as 别名]
# 或者: from ensime_shared.util.Util import write_file [as 别名]
def install(self):
"""Installs ENSIME server with a bootstrap sbt project and generates its classpath."""
project_dir = os.path.dirname(self.classpath_file)
sbt_plugin = """addSbtPlugin("{0}" % "{1}" % "{2}")"""
Util.mkdir_p(project_dir)
Util.mkdir_p(os.path.join(project_dir, "project"))
Util.write_file(
os.path.join(project_dir, "build.sbt"),
self.build_sbt())
Util.write_file(
os.path.join(project_dir, "project", "build.properties"),
"sbt.version={}".format(self.SBT_VERSION))
Util.write_file(
os.path.join(project_dir, "project", "plugins.sbt"),
sbt_plugin.format(*self.SBT_COURSIER_COORDS))
# Synchronous update of the classpath via sbt
# see https://github.com/ensime/ensime-vim/issues/29
cd_cmd = "cd {}".format(project_dir)
sbt_cmd = "sbt -Dsbt.log.noformat=true -batch saveClasspath"
if int(self.vim.eval("has('nvim')")):
import tempfile
import re
tmp_dir = tempfile.gettempdir()
flag_file = "{}/ensime-vim-classpath.flag".format(tmp_dir)
self.vim.command("echo 'Waiting for generation of classpath...'")
if re.match(".+fish$", self.vim.eval("&shell")):
sbt_cmd += "; echo $status > {}".format(flag_file)
self.vim.command("terminal {}; and {}".format(cd_cmd, sbt_cmd))
else:
sbt_cmd += "; echo $? > {}".format(flag_file)
self.vim.command("terminal ({} && {})".format(cd_cmd, sbt_cmd))
# Block execution when sbt is run
waiting_for_flag = True
while waiting_for_flag:
waiting_for_flag = not os.path.isfile(flag_file)
if not waiting_for_flag:
with open(flag_file, "r") as f:
rtcode = f.readline()
os.remove(flag_file)
if rtcode and int(rtcode) != 0: # error
self.vim.command(
"echo 'Something wrong happened, check the "
"execution log...'")
return None
else:
time.sleep(0.2)
else:
self.vim.command("!({} && {})".format(cd_cmd, sbt_cmd))
success = self.reorder_classpath(self.classpath_file)
if not success:
self.vim.command("echo 'Classpath ordering failed.'")
return True