def _preexec_val(self):
return os.setsid if sublime.platform() != "windows" else None
python类platform()的实例源码
def kill(self):
pid = self.process.pid
if sublime.platform() == "windows":
kill_process = subprocess.Popen(['taskkill', '/F', '/T', '/PID', str(pid)], stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
kill_process.communicate()
else:
os.killpg(pid, signal.SIGTERM)
ProcessCache.remove(self)
CrossPlatformCodecs.py 文件源码
项目:sublime-commandbox
作者: Ortus-Solutions
项目源码
文件源码
阅读 18
收藏 0
点赞 0
评论 0
def force_decode(self, text):
try:
text = text.decode('utf-8')
except UnicodeDecodeError:
if sublime.platform() == "windows":
text = self.decode_windows_line(text)
return text
CrossPlatformCodecs.py 文件源码
项目:sublime-commandbox
作者: Ortus-Solutions
项目源码
文件源码
阅读 17
收藏 0
点赞 0
评论 0
def encode_process_command(self, command):
is_sublime_2_and_in_windows = sublime.platform() == "windows" and int(sublime.version()) < 3000
return command.encode(sys.getfilesystemencoding()) if is_sublime_2_and_in_windows else command
def get_subl_executable_path():
"""Return the path to the subl command line binary."""
executable_path = sublime.executable_path()
if sublime.platform() == 'osx':
suffix = '.app/'
app_path = executable_path[:executable_path.rfind(suffix) + len(suffix)]
executable_path = app_path + 'Contents/SharedSupport/bin/subl'
return executable_path
# popen utils
def create_tempdir():
"""Create a directory within the system temp directory used to create temp files."""
try:
if os.path.isdir(tempdir):
shutil.rmtree(tempdir)
os.mkdir(tempdir)
# Make sure the directory can be removed by anyone in case the user
# runs ST later as another user.
os.chmod(tempdir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
except PermissionError:
if sublime.platform() != 'windows':
current_user = pwd.getpwuid(os.geteuid())[0]
temp_uid = os.stat(tempdir).st_uid
temp_user = pwd.getpwuid(temp_uid)[0]
message = (
'The SublimeLinter temp directory:\n\n{0}\n\ncould not be cleared '
'because it is owned by \'{1}\' and you are logged in as \'{2}\'. '
'Please use sudo to remove the temp directory from a terminal.'
).format(tempdir, temp_user, current_user)
else:
message = (
'The SublimeLinter temp directory ({}) could not be reset '
'because it belongs to a different user.'
).format(tempdir)
sublime.error_message(message)
from . import persist
persist.debug('temp directory:', tempdir)
def get_user_fullname():
"""Return the user's full name (or at least first name)."""
if sublime.platform() in ('osx', 'linux'):
import pwd
return pwd.getpwuid(os.getuid()).pw_gecos
else:
return os.environ.get('USERNAME', 'Me')
st_color_scheme_matcher.py 文件源码
项目:sublime-text-3-packages
作者: nickjj
项目源码
文件源码
阅读 24
收藏 0
点赞 0
评论 0
def sublime_format_path(pth):
"""Format path for sublime internal use."""
m = re.match(r"^([A-Za-z]{1}):(?:/|\\)(.*)", pth)
if sublime.platform() == "windows" and m is not None:
pth = m.group(1) + "/" + m.group(2)
return pth.replace("\\", "/")
def visible(self):
return platform.system() == "Windows" and self.settings.get("portable_mode")
def pipe_through_prog(cmd, path=None, stdin=''):
"""Run the Vale binary with the given command.
"""
startupinfo = None
if sublime.platform() == 'windows':
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
p = subprocess.Popen(cmd, cwd=path, stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
stdin=subprocess.PIPE,
startupinfo=startupinfo)
out, err = p.communicate(input=stdin.encode('utf-8'))
return out.decode('utf-8'), err
def __init__(self):
self.default_binary = 'vale'
if sublime.platform() == 'windows':
self.default_binary += '.exe'
self.on_hover = []
self.error_template = None
self.warning_template = None
self.info_template = None
self.css = None
self.settings.add_on_change('reload', lambda: self.load())
self.load()
def open_url(url):
if sublime.platform() == 'osx':
command = 'open'
elif sublime.platform() == 'windows':
command = 'start'
elif sublime.platform() == 'linux':
command = 'lynx'
command += ' ' + str(url)
os.system(command)
# ----------------------------------------------------------
# Manager
# ----------------------------------------------------------
def is_windows():
return sublime.platform() == 'windows'
def get_branch(self, platform, arch):
return [{
'linux-x64': 'master',
'linux-x32': 'x32',
}, {
'linux-x64': 'linux-x64',
'linux-x32': 'linux-x32',
'osx-x64': 'osx',
}][ST3].get(platform + '-' + arch)
def sublime_format_path(pth):
"""Format path for sublime internal use."""
m = re.match(r"^([A-Za-z]{1}):(?:/|\\)(.*)", pth)
if sublime.platform() == "windows" and m is not None:
pth = m.group(1) + "/" + m.group(2)
return pth.replace("\\", "/")
def response_tab_bindings():
"""Returns string with special key bindings for response tab commands.
"""
replay = '[cmd+r]' if platform == 'osx' else '[ctrl+r]'
nav = '[ctrl+alt+ ?/?]'
pin = '[cmd+t]' if platform == 'osx' else '[ctrl+t]'
save = '[cmd+s]' if platform == 'osx' else '[ctrl+s]'
explore = '[cmd+e]' if platform == 'osx' else '[ctrl+e]'
return '{} replay request, {} prev/next request, {} pin/unpin tab, {} save request, {} explore URL'.format(
replay, nav, pin, save, explore)
def handle_thread(thread, msg=None, counter=0, direction=1, width=8):
if thread.is_alive():
next = counter + direction
if next > width:
direction = -1
elif next < 0:
direction = 1
bar = [' '] * (width + 1)
bar[counter] = '='
counter += direction
status('%s [%s]' % (msg, ''.join(bar)))
sublime.set_timeout(lambda: handle_thread(thread, msg, counter,
direction, width), 100)
else:
status(' ok ')
# # Code lifted from https://github.com/randy3k/ProjectManager/blob/master/pm.py
# def subl(args=[]):
# # learnt from SideBarEnhancements
# executable_path = sublime.executable_path()
# print('executable_path: '+ executable_path)
# if sublime.platform() == 'linux':
# subprocess.Popen([executable_path] + [args])
# if sublime.platform() == 'osx':
# app_path = executable_path[:executable_path.rfind(".app/") + 5]
# executable_path = app_path + "Contents/SharedSupport/bin/subl"
# subprocess.Popen([executable_path] + args)
# if sublime.platform() == "windows":
# def fix_focus():
# window = sublime.active_window()
# view = window.active_view()
# window.run_command('focus_neighboring_group')
# window.focus_view(view)
# sublime.set_timeout(fix_focus, 300)
##########################################################################################
#Python Util
##########################################################################################
def get_slash():
sysstr = platform.system()
if(sysstr =="Windows"):
slash = "\\"
else:
slash = "/"
return slash
def get_friendly_platform_key():
friendly_platform_map = {
'darwin': 'osx',
'win32': 'windows',
'linux2': 'linux',
'linux': 'linux'
}
return friendly_platform_map[sys.platform]
##parse_json_from_file is from mavensmate util
def cygwin_path_handle(path):
"""Cygwin Path Support"""
if sublime.platform() == "windows":
return os.path.normcase(re.sub(cygwin_drive_regex, lambda m: "%s:/" % m.groups()[0], path))
else:
return path # do nothing if it is not under windows.