def clean(ctx, venv=False, extra=''): """Perform house-keeping.""" notify.banner("Cleaning up project files") # Stop any left-over watchdog if os.path.exists(TEST_FOLDER): ctx.run("cd {} && . .env && inv view --kill".format(TEST_FOLDER)) # Add patterns based on given parameters venv_dirs = ['.venv'] patterns = [TEST_FOLDER + '/', 'pip-selfcheck.json', '**/*~'] if venv: patterns.extend([i + '/' for i in venv_dirs]) if extra: patterns.extend(shlex.split(extra)) # Build fileset patterns = [antglob.includes(i) for i in patterns] if not venv: # Do not scan venv dirs when not cleaning them patterns.extend([antglob.excludes(i + '/') for i in venv_dirs]) fileset = antglob.FileSet('.', patterns) # Iterate over matches and remove them for name in fileset: notify.info('rm {0}'.format(name)) if name.endswith('/'): shutil.rmtree(name) else: os.unlink(name)
def clean(ctx, docs=False, venv=False, extra=""): """Perform house-keeping.""" notify.banner("Cleaning up project files") # Add patterns based on given parameters venv_dirs = [".venv"] patterns = ["new-script/", "pip-selfcheck.json", "**/*~"] if docs: patterns.append("docs/_build/") if venv: patterns.extend([i + "/" for i in venv_dirs]) if extra: patterns.extend(shlex.split(extra)) # Build fileset patterns = [antglob.includes(i) for i in patterns] if not venv: # Do not scan venv dirs when not cleaning them patterns.extend([antglob.excludes(i + "/") for i in venv_dirs]) fileset = antglob.FileSet(".", patterns) # Iterate over matches and remove them for name in fileset: notify.info("rm {0}".format(name)) if name.endswith("/"): shutil.rmtree(name) else: os.unlink(name)
def clean(ctx, venv=False, extra=''): """Perform house-keeping.""" notify.banner("Cleaning up project files") ctx.run("invoke view --kill") # Add patterns based on given parameters venv_dirs = ['bin', 'include', 'lib', 'share', 'local', '.venv'] patterns = ['_html/', 'pip-selfcheck.json'] excludes = ['.git/', '.hg/', '.svn/'] if venv: patterns.extend([i + '/' for i in venv_dirs]) if extra: patterns.extend(shlex.split(extra)) # Build fileset patterns = [antglob.includes(i) for i in patterns] + [antglob.excludes(i) for i in excludes] if not venv: # Do not scan venv dirs when not cleaning them patterns.extend([antglob.excludes(i + '/') for i in venv_dirs]) fileset = antglob.FileSet(BASEDIR, patterns) # Iterate over matches and remove them for name in fileset: notify.info('rm {0}'.format(name)) if name.endswith('/'): shutil.rmtree(os.path.join(BASEDIR, name)) else: os.unlink(os.path.join(BASEDIR, name))
def clean(ctx, docs=False, venv=False, extra=''): """Perform house-keeping.""" notify.banner("Cleaning up project files") # Add patterns based on given parameters venv_dirs = ['.venv'] patterns = ['new-project/', 'pip-selfcheck.json', '**/*~'] if docs: patterns.append('docs/_build/') if venv: patterns.extend([i + '/' for i in venv_dirs]) if extra: patterns.extend(shlex.split(extra)) # Build fileset patterns = [antglob.includes(i) for i in patterns] if not venv: # Do not scan venv dirs when not cleaning them patterns.extend([antglob.excludes(i + '/') for i in venv_dirs]) fileset = antglob.FileSet('.', patterns) # Iterate over matches and remove them for name in fileset: notify.info('rm {0}'.format(name)) if name.endswith('/'): shutil.rmtree(name) else: os.unlink(name)