本文整理汇总了Python中shutil.ignore_patterns方法的典型用法代码示例。如果您正苦于以下问题:Python shutil.ignore_patterns方法的具体用法?Python shutil.ignore_patterns怎么用?Python shutil.ignore_patterns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shutil
的用法示例。
在下文中一共展示了shutil.ignore_patterns方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: copytree
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def copytree(src, dst, symlinks=False, ignore=shutil.ignore_patterns('.*', '_*')):
"""
Copy Entire Folder
:param src: source path
:param dst: destination path
:param symlinks: optional
:param ignore: pass shutil.ignore_patterns('.*', '_*')
:return:
"""
for item in os.listdir(src):
s = os.path.join(src, item)
d = os.path.join(dst, item)
if os.path.isdir(s):
shutil.copytree(s, d, symlinks, ignore)
else:
shutil.copy2(s, d)
示例2: make_package
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def make_package(suffix=None):
this_dir = os.path.dirname(os.path.abspath(__file__))
dist_dir = os.path.join(this_dir, 'dist')
if not os.path.exists(dist_dir):
os.makedirs(dist_dir)
with tempfile.TemporaryDirectory() as tmpdir:
shutil.copytree(
os.path.join(this_dir, 'addons', 'io_scene_gltf_ksons'),
os.path.join(tmpdir, 'io_scene_gltf_ksons'),
ignore=shutil.ignore_patterns('__pycache__'))
zip_name = 'io_scene_gltf_ksons'
if suffix:
zip_name += '-' + suffix
shutil.make_archive(
os.path.join('dist', zip_name),
'zip',
tmpdir)
示例3: create_backup
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def create_backup(self):
if self._verbose: print("Backing up current addon folder")
local = os.path.join(self._updater_path,"backup")
tempdest = os.path.join(self._addon_root,
os.pardir,
self._addon+"_updater_backup_temp")
if os.path.isdir(local) == True:
shutil.rmtree(local)
if self._verbose: print("Backup destination path: ",local)
# make the copy
if self._backup_ignore_patterns != None:
shutil.copytree(
self._addon_root,tempdest,
ignore=shutil.ignore_patterns(*self._backup_ignore_patterns))
else:
shutil.copytree(self._addon_root,tempdest)
shutil.move(tempdest,local)
# save the date for future ref
now = datetime.now()
self._json["backup_date"] = "{m}-{d}-{yr}".format(
m=now.strftime("%B"),d=now.day,yr=now.year)
self.save_updater_json()
示例4: create_netns_dir
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def create_netns_dir(
self, network_dir=None, netns_network_dir=None, ignore=None):
if not netns_network_dir:
netns_network_dir = self.get_netns_network_dir()
if not network_dir:
network_dir = self.get_network_path()
if not ignore:
ignore = shutil.ignore_patterns('ifcfg-eth0*', 'ifcfg-lo*')
super(RH, self).create_netns_dir(
network_dir, netns_network_dir, ignore)
# Copy /etc/sysconfig/network file
src = '/etc/sysconfig/network'
dst = '/etc/netns/{netns}/sysconfig'.format(
netns=consts.AMPHORA_NAMESPACE)
shutil.copy2(src, dst)
示例5: exclusion_policy
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def exclusion_policy():
"""Returns a callable which, when passed a directory path and a list
of files in that directory, will return a subset of the files which should
be excluded from a copy or some other action.
See https://docs.python.org/3/library/shutil.html#shutil.ignore_patterns
"""
patterns = set(
[
".git",
"config.txt",
"*.db",
"*.dmg",
"node_modules",
"snapshots",
"data",
"server.log",
"__pycache__",
]
)
return shutil.ignore_patterns(*patterns)
示例6: run
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def run(self):
from renku.core.commands.init import fetch_template, \
read_template_manifest
with TemporaryDirectory() as tempdir:
# download and extract template data
temppath = Path(tempdir)
print('downloading Renku templates...')
fetch_template(URL, REFERENCE, temppath)
read_template_manifest(temppath, checkout=True)
# copy templates
current_path = Path.cwd()
template_path = current_path / 'renku' / 'templates'
if template_path.exists():
shutil.rmtree(str(template_path))
shutil.copytree(
str(temppath),
str(template_path),
ignore=shutil.ignore_patterns('.git')
)
示例7: copyVersionFolder
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def copyVersionFolder(cls, src_path: str, dest_path: str) -> None:
Logger.log("i", "Copying directory from '%s' to '%s'", src_path, dest_path)
# we first copy everything to a temporary folder, and then move it to the new folder
base_dir_name = os.path.basename(src_path)
temp_root_dir_path = tempfile.mkdtemp("cura-copy")
temp_dir_path = os.path.join(temp_root_dir_path, base_dir_name)
# src -> temp -> dest
try:
# Copy everything, except for the logs, lock or really old (we used to copy old configs to the "old" folder)
# config files.
shutil.copytree(src_path, temp_dir_path,
ignore = shutil.ignore_patterns("*.lock", "*.log", "*.log.?", "old"))
# if the dest_path exist, it needs to be removed first
if not os.path.exists(dest_path):
shutil.move(temp_dir_path, dest_path)
else:
Logger.log("e", "Unable to copy files to %s as the folder already exists", dest_path)
except:
Logger.log("e", "Something occurred when copying the version folder from '%s' to '%s'", src_path, dest_path)
示例8: add_qt_framework
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def add_qt_framework(self, f):
libname = f
f = f + '.framework'
src = join(PREFIX, 'qt', 'lib', f)
ignore = shutil.ignore_patterns('Headers', '*.h', 'Headers/*')
dest = join(self.frameworks_dir, f)
shutil.copytree(src, dest, symlinks=True,
ignore=ignore)
lib = os.path.realpath(join(dest, libname))
rpath = os.path.relpath(lib, self.frameworks_dir)
self.set_id(lib, self.FID + '/' + rpath)
self.fix_dependencies_in_lib(lib)
# The following is needed for codesign in OS X >= 10.9.5
# The presence of the .prl file in the root of the framework causes
# codesign to fail.
with current_dir(dest):
for x in os.listdir('.'):
if x != 'Versions' and not os.path.islink(x):
os.remove(x)
示例9: create_mirror
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def create_mirror(self, mirror_dir):
"""Create mirror of this package and it's dependencies.
Args:
mirror_dir: Directory where mirror will be stored.
Raises:
OSError: If this method fails to create mirror.
"""
ignore_git = shutil.ignore_patterns('.git')
logging.debug('Copying %s to %s', self.path, mirror_dir)
shutil.copytree(self.path, mirror_dir, ignore=ignore_git)
dependencies_dir = os.path.join(mirror_dir, 'dependencies')
logging.debug('Creating ' + dependencies_dir)
os.mkdir(dependencies_dir)
for dependency in self.dependencies:
mirrored_dependency = os.path.join(dependencies_dir, dependency.name)
logging.debug('Copying %s to %s ', dependency.path, mirrored_dependency)
shutil.copytree(dependency.path, mirrored_dependency, ignore=ignore_git)
示例10: copy_files
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def copy_files(src,dst,ignore_pattern,make=True,render=None,strips='.tpl'):
if not check_path(src):
raise PathDoesntExist
if not check_path(dst,make):
raise PathDoesntExist
src_files = os.listdir(src)
ignore_fun = shutil.ignore_patterns(*ignore_pattern)
filter_matches = ignore_fun(src,src_files)
for file in src_files:
if file in filter_matches:
continue
srcname = os.path.join(src,file)
dstname = os.path.join(dst,file.rstrip(strips))
if os.path.isdir(srcname):
copy_files(srcname,dstname,ignore_pattern)
else:
shutil.copy2(srcname,dstname)
if render:
if file in render:
_var = render[file]
render_template(srcname,dstname,_var)
示例11: build_c_extensions
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def build_c_extensions(ext_dir, args):
writeable_src_dir = os.path.join(ext_dir, 'src')
shutil.copytree(
KITTY_DIR, writeable_src_dir, symlinks=True,
ignore=shutil.ignore_patterns('b', 'build', 'dist', '*_commands.json', '*.o'))
cmd = [PYTHON, 'setup.py']
bundle = 'macos-freeze' if ismacos else 'linux-freeze'
cmd.append(bundle)
dest = kitty_constants['appname'] + ('.app' if ismacos else '')
dest = os.path.join(ext_dir, dest)
cmd += ['--prefix', dest]
if run(*cmd, cwd=writeable_src_dir) != 0:
print('Building of kitty package failed', file=sys.stderr)
os.chdir(KITTY_DIR)
run_shell()
raise SystemExit('Building of kitty package failed')
return ext_dir
示例12: examples
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def examples(path='hvplot-examples', verbose=False, force=False, root=__file__):
"""
Copies the notebooks to the supplied path.
"""
filepath = os.path.abspath(os.path.dirname(root))
example_dir = os.path.join(filepath, './examples')
if not os.path.exists(example_dir):
example_dir = os.path.join(filepath, '../examples')
if os.path.exists(path):
if not force:
print('%s directory already exists, either delete it or set the force flag' % path)
return
shutil.rmtree(path)
ignore = shutil.ignore_patterns('.ipynb_checkpoints', '*.pyc', '*~')
tree_root = os.path.abspath(example_dir)
if os.path.isdir(tree_root):
shutil.copytree(tree_root, path, ignore=ignore, symlinks=True)
else:
print('Cannot find %s' % tree_root)
示例13: create_exp_dir
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def create_exp_dir(path, scripts_to_save=None):
if not os.path.exists(path):
os.makedirs(path, exist_ok=True)
print('Experiment dir : {}'.format(path))
if scripts_to_save is not None:
try:
os.mkdir(os.path.join(path, 'scripts'))
except FileExistsError as e:
logging.warning('Deleting all the previously stored scripts...')
shutil.rmtree(os.path.join(path, 'scripts'))
os.mkdir(os.path.join(path, 'scripts'))
for script in scripts_to_save:
dst_file = os.path.join(path, 'scripts', os.path.basename(script))
if os.path.isdir(script):
shutil.copytree(script, dst_file, ignore=shutil.ignore_patterns('*.pyc', 'tmp*', '*.ipynb'))
else:
shutil.copyfile(script, dst_file)
示例14: copy_tree
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def copy_tree(src,tgt, ignore_patterns=None, symlinks=False):
"""Copy the tree at src to tgt. This will first remove tgt if it
already exists."""
if verbose(1):
msgb("COPYTREE", tgt + " <- " + src)
if not os.path.exists(src):
error_msg("SRC TREE DOES NOT EXIST", src)
raise Exception
if os.path.exists(tgt):
if verbose(1):
msgb("Removing existing target tree", tgt)
shutil.rmtree(tgt, ignore_errors=True)
if verbose(1):
msgb("Copying to tree", tgt)
if ignore_patterns:
sp = shutil.ignore_patterns(ignore_patterns)
else:
sp = None
shutil.copytree(src,tgt,ignore=sp, symlinks=symlinks)
if verbose(1):
msgb("Done copying tree", tgt)
示例15: copy_source
# 需要导入模块: import shutil [as 别名]
# 或者: from shutil import ignore_patterns [as 别名]
def copy_source(top, source, name=None):
"""Copy the source directory into the SOURCES directory.
Args:
top: The absolute path to the %_topdir.
source: The absolute path to the source directory.
name: The name of the directory to place in SOURCES.
Returns:
The absolute path to the copy.
"""
name = name or os.path.basename(source)
path = os.path.join(top, 'SOURCES', name)
shutil.copytree(
source,
path,
ignore=shutil.ignore_patterns(*IGNORED_PATTERNS),
)
return path