资源简介
一个sublime的插件,允许你在SublimeText中运行一个HTTP服务器,并为所有打开的项目文件夹提供服务
代码片段和文件信息
# ------------------------------------------------------------------------------
# SublimeServer 0.3.3
# ------------------------------------------------------------------------------
__VERSION__ = “0.3.3“
import os
import sys
import sublime
import sublime_plugin
import threading
import webbrowser
import posixpath
import socket
import cgi
import shutil
import mimetypes
import time
import io
# detect python‘s version
python_version = sys.version_info[0]
# Sublime 3 (Python 3.x)
if python_version == 3:
from http.server import baseHTTPRequestHandler HTTPServer
from socketserver import ThreadingMixIn TCPServer
# from io import StringIO
from urllib import parse as urllib
# Sublime 2 (Python 2.x)
else:
from baseHTTPServer import baseHTTPRequestHandler HTTPServer
from SocketServer import ThreadingMixIn TCPServer
# from StringIO import StringIO
import urllib
# SublimeServer Settings
settings = None
# HTTP server thread
thread = None
# Open directories
dic = None
# Fail attempts
attempts = 0
# Sublime complete loaded?
loaded = False
def load_settings():
‘‘‘Load SublimeServer Settings‘‘‘
# default settings
defaultPort = 8080
# default attempts
defaultAttempts = 5
# default interval
defaultInterval = 500
# default mimeType
defaultMimeTypes = {
‘‘: ‘application/octet-stream‘ # Default
‘.py‘: ‘text/plain‘
‘.c‘: ‘text/plain‘
‘.h‘: ‘text/plain‘
}
# default autorun
defaultAutorun = False
# default extension
defaultExtension = ‘.html‘
# load SublimeServer settings
s = sublime.load_settings(‘SublimeServer.sublime-settings‘)
# if setting file not exists set to default
if not s.has(‘port‘):
s.set(‘port‘ defaultPort)
if not s.has(‘attempts‘):
s.set(‘attempts‘ defaultAttempts)
if not s.has(‘interval‘):
s.set(‘interval‘ defaultInterval)
if not s.has(‘mimetypes‘):
s.set(‘mimetypes‘ defaultMimeTypes)
if not s.has(‘autorun‘):
s.set(‘autorun‘ defaultAutorun)
if not s.has(‘defaultExtension‘):
s.set(‘defaultExtension‘ defaultExtension)
# Normalize base path.
if s.has(‘base‘):
base = s.get(‘base‘)
base = base.replace(‘\\‘ ‘/‘)
if not base.endswith(‘/‘):
base += ‘/‘
s.set(‘base‘ base)
sublime.save_settings(‘SublimeServer.sublime-settings‘)
# Merge project and user settings.
window = sublime.active_window()
if window:
view = window.active_view()
if view:
settings = view.settings()
if settings:
serverSettings = settings.get(‘SublimeServer‘)
if serverSettings:
for setting in serverSettings:
s.set(setting serverSettings.get(setting))
return s
def get_directories():
‘‘‘Get Open Directories in Sublime‘‘‘
dic = {}
# retrieve all Sublime windows
windo
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 15 2017-03-06 14:43 SublimeServer\.gitignore
文件 82 2017-03-06 14:43 SublimeServer\Context.sublime-menu
文件 549 2017-03-06 14:43 SublimeServer\Default.sublime-commands
文件 1342 2017-03-06 14:43 SublimeServer\favicon.ico
文件 1057 2017-03-06 14:43 SublimeServer\LICENSE
文件 878 2017-03-06 14:43 SublimeServer\Main.sublime-menu
文件 47989 2017-03-06 14:43 SublimeServer\markdown.js
文件 2193 2017-03-06 14:43 SublimeServer\README.md
文件 74 2017-03-06 14:43 SublimeServer\st
文件 18928 2017-03-06 14:43 SublimeServer\SublimeServer.py
目录 0 2017-03-06 14:43 SublimeServer
----------- --------- ---------- ----- ----
73107 11
评论
共有 条评论