协助扩展 Sublime Text 插件

Assistance with expanding a Sublime Text Plugin

我有一个 sublime text 插件,它监视以 lp_ 开头的文件的创建

创建带有 lp_ 前缀的文件时,插件会创建一个同名文件夹,其中包含一个图像文件夹。

我想观看我网站的不同区域并在离创建的文件最近的 lp 文件夹中创建相关文件夹。

例如我有以下文件夹结构

根目录 > 桌面 > 根 > 桌面 > lp

根 > 手机 > 根 > 手机 > lp

Root > 平板电脑 > Root > 平板电脑 > 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 文件夹内容,然后为多用途设置用户选项