本文整理匯總了Python中libs.Tools.getFileNameFromPath方法的典型用法代碼示例。如果您正苦於以下問題:Python Tools.getFileNameFromPath方法的具體用法?Python Tools.getFileNameFromPath怎麽用?Python Tools.getFileNameFromPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類libs.Tools
的用法示例。
在下文中一共展示了Tools.getFileNameFromPath方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: on_close
# 需要導入模塊: from libs import Tools [as 別名]
# 或者: from libs.Tools import getFileNameFromPath [as 別名]
def on_close(self, view):
"""
When a sketch is closed, temp files are deleted
Arguments: view {ST object} -- Sublime Text Object
"""
# Serial Monitor
monitor_module = Serial
if Messages.isMonitorView(view):
name = view.name()
serial_port = name.split('-')[1].strip()
if serial_port in monitor_module.serials_in_use:
cur_serial_monitor = monitor_module.serial_monitor_dict.get(
serial_port, None)
if cur_serial_monitor:
cur_serial_monitor.stop()
monitor_module.serials_in_use.remove(serial_port)
# Remove cache
keep_cache = Preferences().get('keep_cache', True)
if(keep_cache):
return
file_path = Tools.getPathFromView(view)
if(not file_path):
return
file_name = Tools.getFileNameFromPath(file_path, ext=False)
tmp_path = Paths.getTempPath()
tmp_all = os.path.join(tmp_path, '*')
tmp_all = glob.glob(tmp_all)
for content in tmp_all:
if file_name in content:
tmp_path = os.path.join(tmp_path, content)
rmtree(tmp_path, ignore_errors=False)
Preferences().set('builded_sketch', False)
# Empty enviroment menu
Menu().createEnvironmentMenu(empty=True)
示例2: __init__
# 需要導入模塊: from libs import Tools [as 別名]
# 或者: from libs.Tools import getFileNameFromPath [as 別名]
def __init__(self, view=False, console=False, install=False, command=True):
'''
Initialize the command and preferences classes, to check
if the current work file is an IoT type it received the view
parameter (ST parameter). This parameter is necessary only in
the options like build or upload.
Keyword Arguments:
view {st object} -- stores many info related with ST (default: False)
'''
self.Preferences = Preferences()
self.Menu = Menu()
# user console
if(console):
current_time = time.strftime('%H:%M:%S')
self.message_queue = MessageQueue(console)
self.message_queue.startPrint()
# For installing purposes
if(install):
self.Commands = CommandsPy(console=console)
return
self.view = view
self.execute = True
self.is_native = False
self.is_iot = False
if(view):
# avoid to do anything with a monitor view
view_name = view.name()
sketch_size = view.size()
file_path = Tools.getPathFromView(view)
if(not file_path and 'monitor' in view_name.lower()):
try:
current_time = time.strftime('%H:%M:%S')
self.message_queue.put('invalid_file_{0}', current_time)
except:
pass
self.execute = False
return
# unsaved file
if(command and not file_path and sketch_size > 0):
saved_file = self.saveCodeInFile(view)
view = saved_file[1]
file_path = Tools.getPathFromView(view)
if(command and not sketch_size):
self.message_queue.put('not_empty_sketch_{0}', current_time)
# current file / view
current_path = Paths.getCurrentFilePath(view)
if(not current_path):
return
self.is_iot = Tools.isIOTFile(view)
current_dir = Paths.getCWD(current_path)
parent_dir = Paths.getParentCWD(current_path)
file_name = Tools.getFileNameFromPath(file_path)
temp_name = Tools.getFileNameFromPath(current_path, ext=False)
if(not self.is_iot):
self.execute = False
# check IoT type file
if(console and not self.is_iot and not self.execute):
current_time = time.strftime('%H:%M:%S')
msg = 'not_iot_{0}{1}'
if(not file_name):
msg = 'not_empty_sketch_{0}'
self.message_queue.put(msg, current_time, file_name)
self.execute = False
return
if(not command and not self.is_iot):
return
# Check native project
for file in os.listdir(parent_dir):
if(file.endswith('platformio.ini')):
self.dir = parent_dir
self.src = False
self.is_native = True
break
# set native paths
if(not self.is_native):
build_dir = self.Preferences.get('build_dir', False)
if(not build_dir):
build_dir = Paths.getTempPath(temp_name)
self.src = current_dir
self.dir = build_dir
# unsaved changes
if (command and view.is_dirty()):
view.run_command('save')
if(console):
#.........這裏部分代碼省略.........