[英]Assistance with expanding a Sublime Text Plugin
我有一個崇高的文本插件,可以監視以lp_開頭的文件的創建
創建帶有lp_前綴的文件時,插件會創建一個同名文件夾,其中包含images文件夾。
我想觀看站點的不同區域,並在離創建的文件最近的lp文件夾中創建相關文件夾。
例如我有以下文件夾結構
根>桌面>根>桌面> lp
根>移動>根>移動> lp
根>平板電腦>根>平板電腦> lp
在“ device”文件夾中創建帶有lp_前綴的文件時,我希望在最近的lp文件夾中創建該文件夾。
下面的插件是正確的,但是我不確定如何設置針對特定文件夾的規則。
導入sublime,sublime_plugin,os
# We extend event listener
class ExampleCommand(sublime_plugin.EventListener):
# This method is called every time a file is saved (not only the first time is saved)
def on_post_save_async(self, view):
variables = view.window().extract_variables()
fileBaseName = variables['file_base_name'] # File name without extension
path = '/Users/jameshusband/Dropbox/development/remote/superfreeslotgames.com/css/' + fileBaseName
imagepath = path + '/images/'
if fileBaseName.startswith('lp_') and not os.path.exists(path):
os.mkdir(path)
os.mkdir(imagepath)
有人可以為此指出正確的方向嗎? 我對Python不太了解,因此不確定實現目標的最佳方法。
非常感謝SergioFC對此提供的幫助!
import sublime, sublime_plugin, os
# We extend event listener
class ExampleCommand(sublime_plugin.EventListener):
# This method is called every time a file is saved (not only the first time is saved)
def on_post_save_async(self, view):
variables = view.window().extract_variables()
fileBaseName = variables['file_base_name'] # File name without extension
file_path = variables['file_path']
if fileBaseName.startswith('lp_'):
if file_path.endswith('/desktop'):
path = file_path + '/lp/' + fileBaseName
imagepath = path + '/images/'
os.mkdir(path)
os.mkdir(imagepath)
open(path + '/' + "style.css", 'w')
if file_path.endswith('/tablet'):
path = file_path + '/lp/' + fileBaseName
imagepath = path + '/images/'
os.mkdir(path)
os.mkdir(imagepath)
open(path + '/' + "style.css", 'w')
if file_path.endswith('/mobile'):
path = file_path + '/lp/' + fileBaseName
imagepath = path + '/images/'
os.mkdir(path)
os.mkdir(imagepath)
open(path + '/' + "style.css", 'w')
從此處擴展將是在保存lp_文件時上傳lp文件夾內容,然后將用戶選項設置為多用途
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.