本文整理汇总了Python中sublime.load_binary_resource函数的典型用法代码示例。如果您正苦于以下问题:Python load_binary_resource函数的具体用法?Python load_binary_resource怎么用?Python load_binary_resource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_binary_resource函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: update_binary
def update_binary():
pkgpath = os.path.join(sublime.installed_packages_path(), 'InputHelper.sublime-package')
srcdir = os.path.join(sublime.packages_path(), 'InputHelper', 'lib')
srcpath = os.path.join(srcdir, binname)
srcdb = os.path.join(srcdir, dbname)
bindir = os.path.join(sublime.packages_path(), usrbin)
binpath = os.path.join(bindir, binname)
bindb = os.path.join(bindir, dbname)
resdir = 'Packages/InputHelper/lib/'
resbin = resdir + binname
resdb = resdir + dbname
bininfo = None
bindata = None
dbdata = None
if os.path.exists(binpath):
bininfo = os.stat(binpath)
elif not os.path.exists(bindir):
os.makedirs(bindir, 0o755)
if not os.path.exists(bindb):
if os.path.exists(srcdb):
with open(srcdb, 'rb') as srcfile:
dbdata = srcfile.read()
srcfile.close
elif st_version == 3 and os.path.exists(pkgpath):
dbdata = sublime.load_binary_resource(resdb)
if dbdata != None:
print("* Creating " + bindb)
with open(bindb, 'wb') as dbfile:
dbfile.write(dbdata)
dbfile.close()
if os.path.exists(srcpath):
srcinfo = os.stat(srcpath)
if bininfo == None or bininfo[ST_MTIME] < srcinfo[ST_MTIME]:
with open(srcpath, 'rb') as srcfile:
bindata = srcfile.read()
srcfile.close()
elif st_version == 3 and os.path.exists(pkgpath):
pkginfo = os.stat(pkgpath)
if bininfo == None or bininfo[ST_MTIME] < pkginfo[ST_MTIME]:
bindata = sublime.load_binary_resource(resbin)
if bindata != None:
print("* Updating " + binpath)
with open(binpath, 'wb') as binfile:
binfile.write(bindata)
binfile.close()
if not os.access(binpath, os.X_OK):
os.chmod(binpath, 0o755)
示例2: __init__
def __init__(self, scheme_file, color_filter=None):
"""Initialize."""
if color_filter is None:
color_filter = self.filter
self.legacy = not scheme_file.lower().endswith('.sublime-color-scheme')
self.color_scheme = path.normpath(scheme_file)
self.scheme_file = path.basename(self.color_scheme)
if self.legacy:
self.scheme_obj = color_filter(
readPlistFromBytes(
re.sub(
br"^[\r\n\s]*<!--[\s\S]*?-->[\s\r\n]*|<!--[\s\S]*?-->", b'',
sublime.load_binary_resource(sublime_format_path(self.color_scheme))
)
)
)
else:
sublime.decode_value(
sublime.load_resource(sublime_format_path(self.color_scheme)),
preserve_lines=True
)
self.scheme_file = scheme_file
self.matched = {}
self.variables = {}
self.parse_scheme()
示例3: update_resource
def update_resource(binname):
# from https://github.com/weslly/ColorPicker/blob/master/sublimecp.py=
targetdir = os.path.join(sublime.packages_path(), 'User', 'R-Box', 'bin')
targetpath = os.path.join(targetdir, binname)
respath = 'Packages/R-Box/bin/' + binname
pkgpath = os.path.join(sublime.installed_packages_path(), 'R-Box.sublime-package')
unpkgpath = os.path.join(sublime.packages_path(), 'R-Box', 'bin', binname)
if os.path.exists(targetpath):
targetinfo = os.stat(targetpath)
else:
if not os.path.exists(targetdir):
os.makedirs(targetdir, 0o755)
targetinfo = None
if os.path.exists(unpkgpath):
pkginfo = os.stat(unpkgpath)
elif os.path.exists(pkgpath):
pkginfo = os.stat(pkgpath)
else:
return
if targetinfo == None or targetinfo.st_mtime < pkginfo.st_mtime:
data = sublime.load_binary_resource(respath)
print("* Updating " + targetpath)
with open(targetpath, 'wb') as binfile:
binfile.write(data)
binfile.close()
if not os.access(targetpath, os.X_OK):
os.chmod(targetpath, 0o755)
示例4: update_binary
def update_binary():
bindir = os.path.join(sublime.packages_path(), usrbin)
binpath = os.path.join(bindir, binname)
pkgpath = os.path.join(sublime.installed_packages_path(), 'ColorPicker.sublime-package')
respath = 'Packages/ColorPicker/lib/' + binname
libdir = os.path.join(sublime.packages_path(), 'ColorPicker', 'lib')
libpath = os.path.join(libdir, binname)
bininfo = None
bindata = None
if os.path.exists(binpath):
bininfo = os.stat(binpath)
elif not os.path.exists(bindir):
os.makedirs(bindir, 0o755)
if os.path.exists(libpath):
libinfo = os.stat(libpath)
if bininfo == None or bininfo[ST_MTIME] < libinfo[ST_MTIME]:
with open(libpath, 'rb') as libfile:
bindata = libfile.read()
libfile.close()
elif sublime_version == 3 and os.path.exists(pkgpath):
pkginfo = os.stat(pkgpath)
if bininfo == None or bininfo[ST_MTIME] < pkginfo[ST_MTIME]:
bindata = sublime.load_binary_resource(respath)
if bindata != None:
print("* Updating " + binpath)
with open(binpath, 'wb') as binfile:
binfile.write(bindata)
binfile.close()
if not os.access(binpath, os.X_OK):
os.chmod(binpath, 0o755)
示例5: set_language
def set_language(lang):
if not lang:
return
PACKAGES_PATH = sublime.packages_path()
DEFAULT_PATH = os.path.join(PACKAGES_PATH, "Default")
SYN_PATH = os.path.join(DEFAULT_PATH, "Syntax.sublime-menu")
if os.path.isfile(SYN_PATH):
with open(SYN_PATH, "rb") as f:
syntax = f.read()
m = md5()
m.update(syntax)
if m.hexdigest() == LANGS[lang]['syntax_md5sum']:
sublime.status_message("%s has loaded." % lang)
return
# mkdir if Default not exist
if not os.path.isdir(DEFAULT_PATH):
os.mkdir(DEFAULT_PATH)
# Load binary resource
PACKAGE_NAME = os.path.basename(os.path.dirname(__file__)).split('.')[0]
LOCALZIP_RES = "Packages/{}/{}".format(PACKAGE_NAME,
LANGS[lang]['zipfile'])
lang_bytes = sublime.load_binary_resource(LOCALZIP_RES)
# write to tempfile and unzip it.
import zipfile
from tempfile import NamedTemporaryFile
tmp_file = NamedTemporaryFile(delete=False)
tmp_file.write(lang_bytes)
tmp_file.close()
with zipfile.ZipFile(tmp_file.name, "r") as f:
f.extractall(DEFAULT_PATH)
tmp_file.close()
os.unlink(tmp_file.name)
示例6: startup
def startup(self):
"""
Check and extract helper files
@param on_done: callback after loaded
"""
helpers = sublime.find_resources("JavatarAutocompleteHelper.jar")
installed = False
for helper in helpers:
if helper[:9] == "Packages/":
helper = os.path.join(sublime.packages_path(), helper[9:])
if os.path.exists(helper) and self.verify_helper(helper):
installed = True
break
if not installed:
Logger().info("Updating helper files...")
file_path = os.path.join(
sublime.packages_path(),
"User",
"Javatar",
"Helper",
"JavatarAutocompleteHelper.jar"
)
if os.path.exists(file_path):
os.remove(file_path)
if not os.path.isdir(os.path.dirname(file_path)):
try:
os.makedirs(os.path.dirname(file_path))
except:
pass
helper_file = open(file_path, "wb")
helper_file.write(sublime.load_binary_resource(
"Packages/Javatar/binary/JavatarAutocompleteHelper.jar"
))
helper_file.close()
示例7: __init__
def __init__(self, scheme_file, color_filter=None):
"""Initialize."""
if color_filter is None:
color_filter = self.filter
self.color_scheme = scheme_file.replace('\\', '/')
self.scheme_file = path.basename(self.color_scheme)
if NEW_SCHEMES and scheme_file.endswith(('.sublime-color-scheme', '.hidden-color-scheme')):
self.legacy = False
self.scheme_obj = {
'variables': {},
GLOBAL_OPTIONS: {},
'rules': []
}
else:
try:
content = sublime.load_binary_resource(sublime_format_path(self.color_scheme))
except IOError:
# Fallback if file was created manually and not yet found in resources
with open(packages_path(self.color_scheme), 'rb') as f:
content = f.read()
self.legacy = True
self.convert_format(readPlistFromBytes(XML_COMMENT_RE.sub(b'', content)))
self.overrides = []
if NEW_SCHEMES:
self.merge_overrides()
self.scheme_file = scheme_file
self.matched = {}
self.variables = {}
self.parse_scheme()
self.scheme_obj = color_filter(self.scheme_obj)
self.setup_matcher()
示例8: update_resources
def update_resources(*target):
targetpath = os.path.join(sublime.packages_path(), 'User', PKGNAME, *target)
targetdir = os.path.dirname(targetpath)
respath = 'Packages/%s/' % PKGNAME + "/".join(target)
pkgpath = os.path.join(sublime.installed_packages_path(), '%s.sublime-package' % PKGNAME)
unpkgpath = os.path.join(sublime.packages_path(), PKGNAME, *target)
if os.path.exists(targetpath):
targetinfo = os.stat(targetpath)
else:
if not os.path.exists(targetdir):
os.makedirs(targetdir, 0o755)
targetinfo = None
if os.path.exists(unpkgpath):
pkginfo = os.stat(unpkgpath)
elif os.path.exists(pkgpath):
pkginfo = os.stat(pkgpath)
else:
return
if targetinfo is None or targetinfo.st_mtime < pkginfo.st_mtime:
print("* Updating " + targetpath)
if sublime.version() < '3000':
shutil.copy2(unpkgpath, targetpath)
else:
data = sublime.load_binary_resource(respath)
with open(targetpath, 'wb') as f:
f.write(data)
f.close()
if not os.access(targetpath, os.X_OK):
os.chmod(targetpath, 0o755)
示例9: plugin_loaded
def plugin_loaded():
global full_data_path, full_icons_path, full_themes_path
full_data_path = os.path.join(sublime.packages_path()[:-len("Packages")], os.path.normpath(data_path))
full_icons_path = os.path.join(full_data_path, "icons")
full_themes_path = os.path.join(full_data_path, "themes")
# Create folders
if not os.path.exists(full_data_path):
os.mkdir(full_data_path)
if not os.path.exists(full_icons_path):
os.mkdir(full_icons_path)
if not os.path.exists(full_themes_path):
os.mkdir(full_themes_path)
# Copy binary
binary = "ColorPicker_" + get_ext()
chflags = stat.S_IXUSR|stat.S_IXGRP|stat.S_IRUSR|stat.S_IRUSR|stat.S_IWUSR|stat.S_IWGRP
fpath = os.path.join(full_data_path, binary)
if get_version() >= 3000:
if not os.path.exists(fpath):
data = sublime.load_binary_resource('/'.join(["Packages", "Color Highlighter", "ColorPicker", binary]))
if len(data) != 0:
write_bin_file(fpath, data)
os.chmod(fpath, chflags)
else:
if not os.path.exists(fpath):
shutil.copy(os.path.join(sublime.packages_path(), "Color Highlighter", "ColorPicker", binary), fpath)
os.chmod(fpath, chflags)
# restore themes
restore_broken_schemes()
示例10: edit_plist_color_scheme
def edit_plist_color_scheme(original_color_scheme):
scheme_data = plistlib.readPlistFromBytes(sublime.load_binary_resource(original_color_scheme))
if os.path.exists(sublime.packages_path() + "/MCC/ModifiedColorSchemes/" + scheme_data["name"] + ".tmTheme"):
sublime.load_settings("Preferences.sublime-settings").set("color_scheme", "Packages/MCC/ModifiedColorSchemes/" + scheme_data["name"] + ".tmTheme")
sublime.save_settings("Preferences.sublime-settings")
return
elif scheme_data["name"].find("(MCC)") > -1:
return
try:
new_background_rgb = "#000000"
if "background" in scheme_data["settings"][0]["settings"]:
new_background_rgb = ColorSchemeEditor.change_color_by_one(scheme_data["settings"][0]["settings"]["background"])
scheme_data = ColorSchemeEditor.add_mcc_scopes(scheme_data, False, new_background_rgb)
if not os.path.exists(sublime.packages_path() + "/MCC/ModifiedColorSchemes/"):
os.makedirs(sublime.packages_path() + "/MCC/ModifiedColorSchemes/")
new_file_name = "/MCC/ModifiedColorSchemes/" + scheme_data["name"] + ".tmTheme"
scheme_data["name"] = scheme_data["name"] + " (MCC)"
plistlib.writePlist(scheme_data, sublime.packages_path() + new_file_name)
sublime.load_settings("Preferences.sublime-settings").set("color_scheme", "Packages" + new_file_name)
sublime.save_settings("Preferences.sublime-settings")
except Exception as e:
# sublime.error_message("MCC couldn't convert your current color scheme")
print("Error on tmTheme conversion")
print(e)
sublime.active_window().run_command("show_panel", {"panel": "console", "toggle": True})
示例11: run
def run(self):
# Wait for _corona_utils initialization to complete
# print("Waiting for InitializedEvent...")
_corona_utils.InitializedEvent.wait()
self._snippets_dir = os.path.join(_corona_utils.PACKAGE_USER_DIR, "Snippets")
if not os.path.exists(self._snippets_dir):
os.makedirs(self._snippets_dir)
print(_corona_utils.PACKAGE_NAME + ": Extracting snippets ...")
try:
# In ST3 our ZIP file is not on the filesystem, it's in our package so we have to extract
# it and unzip from there (to work on Windows the temp file must be closed before it can
# be reopened to be unzipped)
zip_bytes = sublime.load_binary_resource(_corona_utils.ST_PACKAGE_PATH + "snippets.zip")
with tempfile.NamedTemporaryFile(suffix = ".zip", delete=False) as tempzip:
tempzip.write(zip_bytes)
tempzip.close()
UnZIPToDir(tempzip.name, self._snippets_dir)
os.remove(tempzip.name)
except:
# We're on ST2 and the ZIP file is just a file in our package directory
UnZIPToDir(os.path.join(_corona_utils.PACKAGE_DIR, "snippets.zip"), self._snippets_dir)
snippetMenuArray = []
snippetJSON = ""
if os.path.isdir(self._snippets_dir):
snippetMenuArray = self.addDirectory(self._snippets_dir)
snippetJSON = json.dumps(snippetMenuArray, indent=4, separators=(',', ': '))
if snippetJSON == "":
print(_corona_utils.PACKAGE_NAME + ": Failed to build Snippets menu")
return
# Put our menu into the Main.sublime-menu.template file
menus = ""
if _corona_utils.SUBLIME_VERSION < 3000:
with open(os.path.join(_corona_utils.PACKAGE_DIR, "Main.sublime-menu.template"), "r") as fd:
menus = fd.read()
else:
menus = sublime.load_resource(_corona_utils.ST_PACKAGE_PATH + "Main.sublime-menu.template")
if menus == "":
print(_corona_utils.PACKAGE_NAME + ": Failed to create Snippets menu")
return
menus = menus.replace("$corona_snippets", snippetJSON)
if not os.path.exists(_corona_utils.PACKAGE_DIR):
os.makedirs(_corona_utils.PACKAGE_DIR)
if _corona_utils.SUBLIME_VERSION < 3000:
with open(os.path.join(_corona_utils.PACKAGE_DIR, "Main.sublime-menu"), "w") as fd:
fd.write("// Generated file - do not edit - modify 'Main.sublime-menu.template' instead\n")
fd.write(menus)
else: # ST3/P3
with open(os.path.join(_corona_utils.PACKAGE_DIR, "Main.sublime-menu"), "w", encoding='utf-8') as fd:
fd.write("// Generated file - do not edit - modify 'Main.sublime-menu.template' instead\n")
fd.write(menus)
示例12: parse_scheme
def parse_scheme(self):
HaxeColorScheme.styles = None
HaxeColorScheme.color_map = None
color_scheme = self.settings.get('color_scheme')
try:
if int(sublime.version()) >= 3000:
b = sublime.load_binary_resource(color_scheme)
pl = readPlistFromBytes(b)
else:
pl = readPlist(os.path.join(os.path.abspath(
sublime.packages_path() + '/..'), color_scheme))
except:
return
def safe_update(fr, to):
for k in fr.keys():
if k not in to:
to[k] = fr[k]
dct = {}
for d in pl.settings:
if 'settings' not in d:
continue
s = d['settings']
if 'scope' not in d:
safe_update(s, dct)
else:
scope = d['scope']
scopes = [sc.strip() for sc in scope.split(',')]
if 'text' in scopes or 'source' in scopes:
dct.update(d.settings)
HaxeColorScheme.color_map = dct
示例13: _get_resource
def _get_resource(package_name, resource, return_binary=False, encoding="utf-8"):
packages_path = sublime.packages_path()
content = None
if VERSION > 3013:
try:
if return_binary:
content = sublime.load_binary_resource("Packages/" + package_name + "/" + resource)
else:
content = sublime.load_resource("Packages/" + package_name + "/" + resource)
except IOError:
pass
else:
path = None
if os.path.exists(os.path.join(packages_path, package_name, resource)):
path = os.path.join(packages_path, package_name, resource)
content = _get_directory_item_content(path, return_binary, encoding)
if VERSION >= 3006:
sublime_package = package_name + ".sublime-package"
packages_path = sublime.installed_packages_path()
if content is None:
if os.path.exists(os.path.join(packages_path, sublime_package)):
content = _get_zip_item_content(os.path.join(packages_path, sublime_package), resource, return_binary, encoding)
packages_path = os.path.dirname(sublime.executable_path()) + os.sep + "Packages"
if content is None:
if os.path.exists(os.path.join(packages_path, sublime_package)):
content = _get_zip_item_content(os.path.join(packages_path, sublime_package), resource, return_binary, encoding)
return content.replace("\r\n", "\n").replace("\r", "\n")
示例14: set_view
def set_view(self, src, lang):
"""Setup view for conversion."""
# Get the output panel
self.view = sublime.active_window().get_output_panel('mdpopups')
# Let all plugins no to leave this view alone
self.view.settings().set('is_widget', True)
# Don't translate anything.
self.view.settings().set("translate_tabs_to_spaces", False)
# Don't mess with my indenting Sublime!
self.view.settings().set("auto_indent", False)
# Insert into the view
self.view.run_command('insert', {'characters': src})
# Setup the proper syntax
lang = lang.lower()
user_map = sublime.load_settings('Preferences.sublime-settings').get('mdpopups.sublime_user_lang_map', {})
keys = set(list(user_map.keys()) + list(lang_map.keys()))
loaded = False
for key in keys:
v = lang_map.get(key, (tuple(), tuple()))
user_v = user_map.get(key, (tuple(), tuple()))
if lang in (tuple(user_v[0]) + v[0]):
for l in (tuple(user_v[1]) + v[1]):
for ext in ST_LANGUAGES:
sytnax_file = 'Packages/%s%s' % (l, ext)
try:
sublime.load_binary_resource(sytnax_file)
except Exception:
continue
self.view.set_syntax_file(sytnax_file)
loaded = True
break
if loaded:
break
if loaded:
break
if not loaded:
# Default to plain text
for ext in ST_LANGUAGES:
# Just in case text one day switches to 'sublime-syntax'
sytnax_file = 'Packages/Plain text%s' % ext
try:
sublime.load_binary_resource(sytnax_file)
except Exception:
continue
self.view.set_syntax_file(sytnax_file)
示例15: load_plist
def load_plist(relative_path):
try:
plist_data = plistlib.readPlistFromBytes(sublime.load_binary_resource(relative_path))
print("CFML: loaded plist file - " + relative_path)
return plist_data
except:
print("CFML: unable to load plist file - " + relative_path)
return None