def sh_mktemp(base_path, directory=True, **kwargs): with quiet(): args = ['--tmpdir={0}'.format(base_path)] if directory: args.append('-d') args = ' '.join(args) return run_cmd('mktemp {0}'.format(args), **kwargs)
def sh_listdir(path, **kwargs): with quiet(): content = run_cmd('find {0} -maxdepth 1'.format(path), **kwargs) items = content.split('\n') items = [item.strip() for item in items] esc = lambda path: re.escape(path + '/' if not path.endswith('/') else path) items = [re.sub('^' + esc(path), '', item) for item in items] items = [item for item in items if item and not item == path] return items
def sh_chown(path, user=None, group=None, recursive=False, **kwargs): if user: mask = '{0}'.format(user) if group: mask = '{0}:{1}'.format(mask, group) with quiet(): extra_args = '' if recursive: extra_args = ' -R' return run_cmd('chown {0} {1} {2}'.format(extra_args, mask, path), capture=True, **kwargs)
def sh_copytree(src, dest, **kwargs): with quiet(): return run_cmd('cp -r {0} {1}'.format(src, dest), capture=True, **kwargs)
def sh_chmod(path, mask, **kwargs): with quiet(): return run_cmd('chmod {0} {1}'.format(mask, path), capture=True, **kwargs)
def sh_rmtree(path, **kwargs): with quiet(): return run_cmd('find {0} -delete'.format(path), **kwargs)
def sh_makedirs(path, user=None, group=None, **kwargs): with quiet(): run_cmd('mkdir -p {0}'.format(path), **kwargs) mask = '{0}:{1}'.format(user or '', group or '') run_cmd('chown {0} {1}'.format(mask, path), **kwargs)
def sh_ln(src, dest, symbolic=True, **kwargs): with quiet(): sym = ' -s' if symbolic else '' return run_cmd('ln{0} {1} {2}'.format(sym, src, dest), **kwargs).succeeded
def sh_file_exists(path, **kwargs): with quiet(): return run_cmd('test -f {0}'.format(path), **kwargs).succeeded
def sh_rm(path, **kwargs): with quiet(): return run_cmd('rm -f {0}'.format(path), **kwargs)
def sh_which(path, **kwargs): with quiet(): return run_cmd('which {0}'.format(path), **kwargs)
def sh_cat(path, **kwargs): with quiet(): return run_cmd('cat {0}'.format(path), capture=True, **kwargs)