本文整理汇总了Python中os.path.isdir方法的典型用法代码示例。如果您正苦于以下问题:Python path.isdir方法的具体用法?Python path.isdir怎么用?Python path.isdir使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os.path
的用法示例。
在下文中一共展示了path.isdir方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: list
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def list(self):
dirs = []
# TODO: error management
for d in listdir(self.datapath):
dp = path.join(self.datapath, d)
if path.isdir(dp):
dirs.append({
"name": d,
"path": dp,
"mtime": datetime.datetime.fromtimestamp(path.getmtime(dp)).strftime('%d.%m.%Y %H:%M:%S')
# "size": path.getsize(dp),
# "hsize": self.human_size(self.get_size(dp))
})
dirs.sort(key=lambda dir: dir['name'], reverse=True)
return {'status': 'success', 'data': dirs}
示例2: find_package_dirs
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def find_package_dirs(root_path):
""" Find python package directories in directory `root_path`
Parameters
----------
root_path : str
Directory to search for package subdirectories
Returns
-------
package_sdirs : set
Set of strings where each is a subdirectory of `root_path`, containing
an ``__init__.py`` file. Paths prefixed by `root_path`
"""
package_sdirs = set()
for entry in os.listdir(root_path):
fname = entry if root_path == '.' else pjoin(root_path, entry)
if isdir(fname) and exists(pjoin(fname, '__init__.py')):
package_sdirs.add(fname)
return package_sdirs
示例3: compile_bundle_entry
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def compile_bundle_entry(self, spec, entry):
"""
Handler for each entry for the bundle method of the compile
process. This copies the source file or directory into the
build directory.
"""
modname, source, target, modpath = entry
bundled_modpath = {modname: modpath}
bundled_target = {modname: target}
export_module_name = []
if isfile(source):
export_module_name.append(modname)
copy_target = join(spec[BUILD_DIR], target)
if not exists(dirname(copy_target)):
makedirs(dirname(copy_target))
shutil.copy(source, copy_target)
elif isdir(source):
copy_target = join(spec[BUILD_DIR], modname)
shutil.copytree(source, copy_target)
return bundled_modpath, bundled_target, export_module_name
示例4: find_node_modules_basedir
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def find_node_modules_basedir(self):
"""
Find all node_modules directories configured to be accessible
through this driver instance.
This is typically used for adding the direct instance, and does
not traverse the parent directories like what Node.js does.
Returns a list of directories that contain a 'node_modules'
directory.
"""
paths = []
# First do the working dir.
local_node_path = self.join_cwd(NODE_MODULES)
if isdir(local_node_path):
paths.append(local_node_path)
# do the NODE_PATH environment variable last, as Node.js seem to
# have these resolving just before the global.
if self.node_path:
paths.extend(self.node_path.split(pathsep))
return paths
示例5: find_system_jdks
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def find_system_jdks():
"""
Returns a set of valid JDK directories by searching standard locations.
"""
bases = [
'/Library/Java/JavaVirtualMachines',
'/usr/lib/jvm',
'/usr/java',
'/usr/jdk/instances',
r'C:\Program Files\Java'
]
jdks = set()
for base in bases:
if isdir(base):
for n in os.listdir(base):
jdk = join(base, n)
mac_jdk = join(jdk, 'Contents', 'Home')
if isdir(mac_jdk):
jdk = mac_jdk
if is_valid_jdk(jdk):
jdks.add(realpath(jdk))
return jdks
示例6: all_actions
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def all_actions():
"""
Returns a list of all available actions from the *.py files in the actions directory
:return: ist of all available action
"""
result = []
directory = os.getcwd()
while True:
if any([entry for entry in listdir(directory) if entry == ACTIONS_DIR and isdir(os.path.join(directory, entry))]):
break
directory = os.path.abspath(os.path.join(directory, '..'))
actions_dir = os.path.join(directory, ACTIONS_DIR)
for f in listdir(actions_dir):
if isfile(join(actions_dir, f)) and f.endswith("_{}.py".format(ACTION.lower())):
module_name = ACTION_MODULE_NAME.format(f[0:-len(".py")])
mod = get_action_module(module_name)
cls = _get_action_class_from_module(mod)
if cls is not None:
action_name = cls[0][0:-len(ACTION)]
result.append(action_name)
return result
示例7: all_handlers
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def all_handlers():
global __actions
if __actions is None:
__actions = []
current = abspath(os.getcwd())
while True:
if isdir(os.path.join(current, "handlers")):
break
parent = dirname(current)
if parent == current:
# at top level
raise Exception("Could not find handlers directory")
else:
current = parent
for f in listdir(os.path.join(current, "handlers")):
if isfile(join(current, "handlers", f)) and f.endswith("_{}.py".format(HANDLER.lower())):
module_name = HANDLERS_MODULE_NAME.format(f[0:-len(".py")])
m = _get_module(module_name)
cls = _get_handler_class(m)
if cls is not None:
handler_name = cls[0]
__actions.append(handler_name)
return __actions
示例8: cache_asset
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def cache_asset(cache_dir, cache_f, path, asset_id):
r"""
Caches the info for a given asset id so it can be efficiently
served in the future.
Parameters
----------
asset_id : `str`
The id of the asset that needs to be cached
"""
asset_cache_dir = p.join(cache_dir, asset_id)
if not p.isdir(asset_cache_dir):
os.mkdir(asset_cache_dir)
cache_f(cache_dir, path, asset_id)
# IMAGE CACHING
示例9: init_pipeline_plugins
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def init_pipeline_plugins(plugin_dir):
"""
Initialize the pipeline plugins which triggers the auto registering of user
defined pipeline functions.
1. Add the plugin_dir into sys.path.
2. Import the file under plugin_dir that starts with "cce_plugin_" and ends
with ".py"
"""
if not op.isdir(plugin_dir):
logger.warning("%s is not a directory! Pipeline plugin files won't be loaded.",
plugin_dir)
return
sys.path.append(plugin_dir)
for file_name in next(walk(plugin_dir))[2]:
if file_name == "__init__.py" or not file_name.startswith("cce_plugin_"):
continue
if file_name.endswith(".py"):
import_plugin_file(file_name)
示例10: _expand_dirs_to_files
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def _expand_dirs_to_files(files_or_dirs, recursive=False):
files = []
files_or_dirs = _ensure_list(files_or_dirs)
for file_or_dir in files_or_dirs:
file_or_dir = op.realpath(file_or_dir)
if op.isdir(file_or_dir):
# Skip dirnames starting with '.'
if _to_skip(file_or_dir):
continue
# Recursively visit the directories and add the files.
if recursive:
files.extend(_expand_dirs_to_files([op.join(file_or_dir, file)
for file in os.listdir(file_or_dir)],
recursive=recursive))
else:
files.extend([op.join(file_or_dir, file)
for file in os.listdir(file_or_dir)])
elif '*' in file_or_dir:
files.extend(glob.glob(file_or_dir))
else:
files.append(file_or_dir)
return files
示例11: run
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def run(self, edit, new_view=False):
path = self.path
filenames = self.get_selected()
# If reuse view is turned on and the only item is a directory, refresh the existing view.
if not new_view and reuse_view():
if len(filenames) == 1 and isdir(join(path, filenames[0])):
fqn = join(path, filenames[0])
show(self.view.window(), fqn, view_id=self.view.id())
return
for filename in filenames:
fqn = join(path, filename)
if isdir(fqn):
show(self.view.window(), fqn, ignore_existing=new_view)
else:
self.view.window().open_file(fqn)
示例12: _move
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def _move(self, path):
if path == self.path:
return
files = self.get_marked() or self.get_selected()
if not isabs(path):
path = join(self.path, path)
if not isdir(path):
sublime.error_message('Not a valid directory: {}'.format(path))
return
# Move all items into the target directory. If the target directory was also selected,
# ignore it.
files = self.get_marked() or self.get_selected()
path = normpath(path)
for filename in files:
fqn = normpath(join(self.path, filename))
if fqn != path:
shutil.move(fqn, path)
self.view.run_command('dired_refresh')
示例13: _parse_split
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def _parse_split(self, path):
"""
Split the path into the directory to search and the prefix to match in that directory.
If the path is completely invalid, (None, None) is returned.
"""
prefix = ''
if not path.endswith(os.sep):
prefix = basename(path)
path = dirname(path)
if not isdir(path):
return (None, None)
return (path, prefix)
示例14: register_plugins
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def register_plugins(linter, directory):
"""load all module and package in the given directory, looking for a
'register' function in each one, used to register pylint checkers
"""
imported = {}
for filename in os.listdir(directory):
base, extension = splitext(filename)
if base in imported or base == '__pycache__':
continue
if extension in PY_EXTS and base != '__init__' or (
not extension and isdir(join(directory, base))):
try:
module = modutils.load_module_from_file(join(directory, filename))
except ValueError:
# empty module name (usually emacs auto-save files)
continue
except ImportError as exc:
print("Problem importing module %s: %s" % (filename, exc),
file=sys.stderr)
else:
if hasattr(module, 'register'):
module.register(linter)
imported[base] = 1
示例15: scan_diveces_airodump
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import isdir [as 别名]
def scan_diveces_airodump(self):
dirpath = "Settings/Dump"
if not path.isdir(dirpath):
makedirs(dirpath)
self.data = {'Bssid':[], 'Essid':[], 'Channel':[]}
exit_air = airdump_start(self.interface)
self.fix = False
if exit_air == None:
self.cap = get_network_scan()
if self.cap != None:
for i in self.cap:
i = i.split("||")
if Refactor.check_is_mac(i[2]):
Headers = []
self.data['Channel'].append(i[0])
self.data['Essid'].append(i[1])
self.data['Bssid'].append(i[2])
for n, key in enumerate(self.data.keys()):
Headers.append(key)
for m, item in enumerate(self.data[key]):
item = QTableWidgetItem(item)
item.setTextAlignment(Qt.AlignVCenter | Qt.AlignCenter)
self.tables.setItem(m, n, item)
self.cap =[]