本文整理汇总了Python中sublime.error_message函数的典型用法代码示例。如果您正苦于以下问题:Python error_message函数的具体用法?Python error_message怎么用?Python error_message使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了error_message函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_done
def add_done(self, message, result):
if result.strip():
sublime.error_message("Error adding file:\n" + result)
return
self.run_command(['git', 'commit', '-m', message],
callback=self.update_status)
示例2: run
def run(self, edit):
fname = self.view.file_name()
if not fname:
sublime.error_message("Save the file!")
return
cmd = "source(\"" + escape_dq(fname) + "\")"
sendtext(cmd)
示例3: copy_linter
def copy_linter(self, name):
"""Copy the template linter to a new linter with the given name."""
self.name = name
self.fullname = 'SublimeLinter-contrib-{}'.format(name)
self.dest = os.path.join(sublime.packages_path(), self.fullname)
if os.path.exists(self.dest):
sublime.error_message('The plugin “{}” already exists.'.format(self.fullname))
return
src = os.path.join(sublime.packages_path(), persist.PLUGIN_DIRECTORY, 'linter-plugin-template')
self.temp_dir = None
try:
self.temp_dir = tempfile.mkdtemp()
self.temp_dest = os.path.join(self.temp_dir, self.fullname)
shutil.copytree(src, self.temp_dest)
self.get_linter_language(name, self.configure_linter)
except Exception as ex:
if self.temp_dir and os.path.exists(self.temp_dir):
shutil.rmtree(self.temp_dir)
sublime.error_message('An error occurred while copying the template plugin: {}'.format(str(ex)))
示例4: run
def run(self, edit):
template_filename = self.view.file_name()
self.dissect_filename(template_filename)
if not template_filename:
return sublime.error_message("You have to provide a template path.")
if not self.action.startswith("eton"):
return sublime.error_message("Invalid eton template %s" % template_filename)
if not os.path.exists(template_filename):
return sublime.error_message("File does not exist")
self.url = get_url(self.settings) + self.COMMAND_URL+self.partner+'/'+self.action.replace('eton_','')
# get file names
file_names = json.dumps(self.generate_file_list())
use_cache = self.settings.get('use_cache', DEFAULT_USE_CACHE_SETTING)
print("Attempting to render %s for %s" % (self.action, self.partner))
print("url is %s" % self.url)
params = dict(partner=self.partner,
action=self.action,
templates= json.dumps(self.generate_file_map()))
try:
response = urlopen(self.url, urllib.parse.urlencode(params).encode("utf-8"))
except urllib.error.URLError as e:
print(e)
return str(e)
temp = tempfile.NamedTemporaryFile(delete=False, suffix=".html")
temp.write(response.read())
temp.close()
webbrowser.open("file://"+temp.name)
示例5: protocol
def protocol(self, req):
self.buf += req
while True:
before, sep, after = self.buf.partition(NEWLINE)
if not sep:
break
try:
# Node.js sends invalid utf8 even though we're calling write(string, "utf8")
# Python 2 can figure it out, but python 3 hates it and will die here with some byte sequences
# Instead of crashing the plugin, we drop the data. Yes, this is horrible.
before = before.decode('utf-8', 'ignore')
data = json.loads(before)
except Exception as e:
msg.error('Unable to parse json: %s' % str(e))
msg.error('Data: %s' % before)
# XXXX: THIS LOSES DATA
self.buf = after
continue
name = data.get('name')
try:
if name == 'error':
message = 'Floobits: Error! Message: %s' % str(data.get('msg'))
msg.error(message)
if data.get('flash'):
sublime.error_message('Floobits: %s' % str(data.get('msg')))
elif name == 'disconnect':
message = 'Floobits: Disconnected! Reason: %s' % str(data.get('reason'))
msg.error(message)
sublime.error_message(message)
self.stop()
else:
self.handler(name, data)
except Exception as e:
msg.error('Error handling %s event with data %s: %s' % (name, data, e))
self.buf = after
示例6: __createArchiveFilename
def __createArchiveFilename(self):
# Create our archive filename, from the mask in our settings.
# Split filename int dir, base, and extension, then apply our mask
path_base, extension = os.path.splitext(self.view.file_name())
dir = os.path.dirname(path_base)
base = os.path.basename(path_base)
sep = os.sep
# Now build our new filename
try:
# This could fail, if someone messed up the mask in the
# settings. So, if it did fail, use our default.
archive_filename = self.archive_org_filemask.format(
dir=dir, base=base, ext=extension, sep=sep)
except:
# Use our default mask
archive_filename = self.archive_org_default_filemask.format(
dir=dir, base=base, ext=extension, sep=sep)
# Display error, letting the user know
sublime.error_message(u"Error:\n\nInvalid filemask:{0}\nUsing default: {1}".format(
self.archive_org_filemask, self.archive_org_default_filemask))
return archive_filename
示例7: run
def run(self, edit, **args):
DEFAULT_FORMAT = '%Y-%m-%d'
view = self.view
date_format = get_setting(view, 'jekyll_date_format', '%Y-%m-%d')
datetime_format = get_setting(view, 'jekyll_datetime_format', '%Y-%m-%d %H:%M:%S')
try:
d = datetime.today()
if args['format'] and args['format'] == 'date':
text = d.strftime(date_format)
elif args['format'] and args['format'] == 'datetime':
text = d.strftime(datetime_format)
else:
text = d.strftime(DEFAULT_FORMAT)
except Exception as e:
sublime.error_message('Jekyll: {0}: {1}'.format(type(e).__name__, e))
return
# Don't bother replacing selections if no text exists
if text == '' or text.isspace():
return
# Do replacements
for r in self.view.sel():
# Insert when sel is empty to not select the contents
if r.empty():
self.view.insert(edit, r.a, text)
else:
self.view.replace(edit, r, text)
示例8: update_build_settings
def update_build_settings(self, settings):
val = settings.get("ANSI_process_trigger", "on_finish")
if val in ["on_finish", "on_data"]:
self.process_trigger = val
else:
self.process_trigger = None
sublime.error_message("ANSIescape settings warning:\n\nThe setting ANSI_process_trigger has been set to an invalid value; must be one of 'on_finish' or 'on_data'.")
示例9: run
def run(self, edit):
selections = self.get_selections()
CompilerCall = self.get_minifier()
if CompilerCall is None:
sublime.error_message('Please focus on the file you wish to minify.')
else:
threads = []
for sel in selections:
selbody = self.view.substr(sel)
thread = CompilerCall(
sel,
selbody,
timeout=self.settings.get('timeout', 5),
level=self.settings.get('optimization_level', 'WHITESPACE_ONLY'),
rm_new_lines=self.settings.get('remove_new_lines', False))
threads.append(thread)
thread.start()
# Wait for threads
for thread in threads:
thread.join()
selections.clear()
self.handle_threads(edit, threads, selections, offset=0, i=0, dir=1)
示例10: curl_convert
def curl_convert(self, data):
try:
import subprocess
# It looks like the text does NOT need to be escaped and
# surrounded with double quotes.
# Tested in ubuntu 13.10, python 2.7.5+
shell_safe_json = data.decode("utf-8")
curl_args = [
"curl",
"-H",
"Content-Type: application/json",
"-d",
shell_safe_json,
"https://api.github.com/markdown",
]
github_oauth_token = self.settings.get("github_oauth_token")
if github_oauth_token:
curl_args[1:1] = ["-u", github_oauth_token]
markdown_html = subprocess.Popen(curl_args, stdout=subprocess.PIPE).communicate()[0].decode("utf-8")
return markdown_html
except subprocess.CalledProcessError:
sublime.error_message(
"cannot use github API to convert markdown. SSL is not included in your Python installation. And using curl didn't work either"
)
return None
示例11: parser_specific_convert
def parser_specific_convert(self, markdown_text):
import subprocess
binary = self.settings.get("multimarkdown_binary", "")
if os.path.exists(binary):
cmd = [binary]
critic_mode = self.settings.get("strip_critic_marks", "accept")
if critic_mode in ("accept", "reject"):
cmd.append("-a" if critic_mode == "accept" else "-r")
sublime.status_message("converting markdown with multimarkdown...")
if sublime.platform() == "windows":
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
p = subprocess.Popen(
cmd, startupinfo=startupinfo, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
else:
p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for line in markdown_text.split("\n"):
p.stdin.write((line + "\n").encode("utf-8"))
markdown_html = p.communicate()[0].decode("utf-8")
if p.returncode:
# Log info to console
sublime.error_message("Could not convert file! See console for more info.")
print(markdown_html)
markdown_html = _CANNOT_CONVERT
else:
sublime.error_message("Cannot find multimarkdown binary!")
markdown_html = _CANNOT_CONVERT
return markdown_html
示例12: open_in_browser
def open_in_browser(cls, path, browser="default"):
if browser == "default":
if sys.platform == "darwin":
# To open HTML files, Mac OS the open command uses the file
# associated with .html. For many developers this is Sublime,
# not the default browser. Getting the right value is
# embarrassingly difficult.
import shlex
import subprocess
env = {"VERSIONER_PERL_PREFER_32_BIT": "true"}
raw = """perl -MMac::InternetConfig -le 'print +(GetICHelper "http")[1]'"""
process = subprocess.Popen(shlex.split(raw), env=env, stdout=subprocess.PIPE)
out, err = process.communicate()
default_browser = out.strip().decode("utf-8")
cmd = "open -a '%s' %s" % (default_browser, path)
os.system(cmd)
else:
desktop.open(path)
sublime.status_message("Markdown preview launched in default browser")
else:
cmd = '"%s" %s' % (browser, path)
if sys.platform == "darwin":
cmd = "open -a %s" % cmd
elif sys.platform == "linux2":
cmd += " &"
elif sys.platform == "win32":
cmd = 'start "" %s' % cmd
result = os.system(cmd)
if result != 0:
sublime.error_message('cannot execute "%s" Please check your Markdown Preview settings' % browser)
else:
sublime.status_message("Markdown preview launched in %s" % browser)
示例13: SearchFor
def SearchFor(view, text, searchurl):
if not searchurl:
# see if we have an extension match first, then use default
settings = sublime.load_settings(__name__ + '.sublime-settings')
filename, ext = os.path.splitext(view.file_name())
typesettings = settings.get('searchanywhere_type_searchengine', [])
foundsetting = False
for typesetting in typesettings:
if typesetting['extension'] == ext:
foundsetting = True
searchurl = typesetting['searchurl']
if not foundsetting:
if settings.has('searchanywhere_searchurl'):
searchurl = settings.get('searchanywhere_searchurl')
else:
sublime.error_message(__name__ + ': No Search Engine selected')
return
else:
# search url is provided by the caller
pass
url = searchurl.replace('{0}', text.replace(' ','%20'))
webbrowser.open_new_tab(url)
示例14: handle_cwd
def handle_cwd(self, new_dir):
try:
if new_dir[0] == "~":
new_dir = os.getenv(self.home) + new_dir[1:]
os.chdir(new_dir)
except:
sublime.error_message(new_dir + " does not exist")
示例15: process_status
def process_status(self, vcs, path):
global file_status_cache
settings = sublime.load_settings('Tortoise.sublime-settings')
if path in file_status_cache and file_status_cache[path]['time'] > \
time.time() - settings.get('cache_length'):
if settings.get('debug'):
print 'Fetching cached status for %s' % path
return file_status_cache[path]['status']
if settings.get('debug'):
start_time = time.time()
try:
status = vcs.check_status(path)
except (Exception) as (exception):
sublime.error_message(str(exception))
file_status_cache[path] = {
'time': time.time() + settings.get('cache_length'),
'status': status
}
if settings.get('debug'):
print 'Fetching status for %s in %s seconds' % (path,
str(time.time() - start_time))
return status