本文整理汇总了Python中sh.rm函数的典型用法代码示例。如果您正苦于以下问题:Python rm函数的具体用法?Python rm怎么用?Python rm使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了rm函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: restore_file
def restore_file(filename):
''' Context manager restores a file to its previous state.
If the file exists on entry, it is backed up and restored.
If the file does not exist on entry and does exists on exit,
it is deleted.
'''
exists = os.path.exists(filename)
if exists:
# we just want the pathname, not the handle
# tiny chance of race if someone else gets the temp filename
handle, backup = tempfile.mkstemp()
os.close(handle)
sh.cp('--archive', filename, backup)
try:
yield
finally:
if os.path.exists(filename):
sh.rm(filename)
if exists:
# restore to original state
sh.mv(backup, filename)
开发者ID:goodcrypto,项目名称:goodcrypto-libs,代码行数:27,代码来源:fs.py
示例2: clean
def clean():
proj()
print ". cleaning up build and dist"
try:
sh.rm("-r", sh.glob("dist/*"), sh.glob("build/*"))
except:
print ".. already clean"
开发者ID:JiangKevin,项目名称:blockd3,代码行数:7,代码来源:fabfile.py
示例3: copy_assets
def copy_assets():
"""copy assets for static serving"""
proj()
print(". copying assets ...")
copy_patterns = {
"dist": ["./static/lib/jquery-1.8.3.min.js"] +
sh.glob("./static/config/*.json") +
sh.glob("./static/fragile-min.*"),
"dist/font": sh.glob("./static/lib/awesome/font/*"),
"dist/svg": sh.glob("./static/svg/*.svg"),
"dist/img": sh.glob("./static/img/*.*") or [],
"dist/docs/assets": sh.glob("./docs/assets/*.*") or [],
}
for dst, copy_files in copy_patterns.items():
if not os.path.exists(dst):
sh.mkdir("-p", dst)
for c_file in copy_files:
print "... copying", c_file, dst
sh.cp("-r", c_file, dst)
wa_cache = "./dist/.webassets-cache"
if os.path.exists(wa_cache):
sh.rm("-r", wa_cache)
开发者ID:bollwyvl,项目名称:fragile,代码行数:30,代码来源:fabfile.py
示例4: close_stream
def close_stream(self):
""" Zamykanie urządzenia i kasowanie plików tymczasowych
"""
if self.source_mount is not None:
sh.sync()
sh.umount(self.source_mount, self.destination_mount)
sh.rm(self.mount_folder, '-rf')
开发者ID:poxip,项目名称:pyWinUSB,代码行数:7,代码来源:creator.py
示例5: get_receive_errors
def get_receive_errors(rev_old, rev_new, file_type, function):
checkable = True
if file_type == "js":
checkable = config.getboolean("receive", "CHECK_JAVASCRIPT")
elif file_type == "php":
checkable = config.getboolean("receive", "CHECK_PHP")
if not checkable:
return None
files = _get_receive_files(rev_old, rev_new, file_type)
if not files:
return None
tmp_dir = config.get("receive", "TMP_DIR")
errors = []
for file_path in files:
mkdir("-p", "/".join((tmp_dir + file_path).split("/")[:-1]))
system("git show %s:%s > %s" % (rev_new, file_path, tmp_dir + file_path))
if path.exists(tmp_dir + file_path):
file_error = function(tmp_dir + file_path)
if file_error:
errors.append(file_path + file_error)
rm("-rf", tmp_dir)
return "\n".join(errors)
开发者ID:nanjingboy,项目名称:git_code_sniffer_hooks,代码行数:26,代码来源:common.py
示例6: clean_directory
def clean_directory(directory):
"""Remove all files in a directory"""
for filename in os.listdir(directory):
f = os.path.join(directory, filename)
if os.path.isfile(f):
sh.rm(f)
开发者ID:EnigmaCurry,项目名称:cstar_perf,代码行数:7,代码来源:utils.py
示例7: step_impl
def step_impl(context):
for row in context.input:
assert_that(bucket.head_object(row["name"]).status_code
).is_equal_to(404)
assert_that(os.path.isfile("tmp/" + row["name"])).is_equal_to(True)
sh.rm("-rf", "tmp").wait()
开发者ID:yunify,项目名称:qsctl,代码行数:7,代码来源:mv.py
示例8: get_lambda_code
def get_lambda_code(func_name, retries=1, cache_time=AWS_LAMBDA_CODE_CACHE_TIMEOUT):
if MOCK_OBJ:
return ''
cmd = 'aws lambda get-function --function-name %s' % func_name
out = run(cmd, cache_duration_secs=cache_time)
out = json.loads(out)
loc = out['Code']['Location']
hash = md5(loc)
# print("Location %s %s" % (hash, func_name))
folder = TMP_DOWNLOAD_FILE_PATTERN.replace('*', '%s') % hash
filename = 'archive.zip'
archive = '%s/%s' % (folder, filename)
try:
run('mkdir -p %s' % folder)
if not os.path.isfile(archive):
print("Downloading %s" % archive)
run("wget -O %s '%s'" % (archive, loc))
if len(os.listdir(folder)) <= 1:
print("Unzipping %s/%s" % (folder, filename))
run("cd %s && unzip -o %s" % (folder, filename))
except Exception, e:
print("WARN: %s" % e)
sh.rm('-f', archive)
if retries > 0:
return get_lambda_code(func_name, retries=retries - 1, cache_time=1)
else:
print("WARNING: Unable to retrieve lambda code: %s" % e)
开发者ID:pchaganti,项目名称:localstack,代码行数:27,代码来源:infra.py
示例9: xxd_diff
def xxd_diff(old, new):
'''
just for fun
'''
# xxd -p for pure hexdump
# -p must pass in before file name
shell = check_shell()
# support : bash, zsh
# not support : dash
cmd = 'diff <(xxd -p {}) <(xxd -p {})'.format(old, new)
if shell['bash']:
return sh.bash('-c', cmd, _ok_code=[0, 1])
elif shell['zsh']:
return sh.zsh('-c', cmd, _ok_code=[0, 1])
else:
tmp_old = '/var/tmp/old_hex'
tmp_new = '/var/tmp/new_hex'
sh.xxd('-p', old, _out=tmp_old)
sh.xxd('-p', new, _out=tmp_new)
patch = sh.diff(old, new, _iter=True, _ok_code=[0, 1])
sh.rm('-f', tmp_old)
sh.rm('-f', tmp_new)
return patch
开发者ID:wdv4758h,项目名称:toydiff,代码行数:27,代码来源:toydiff.py
示例10: test_console_script
def test_console_script(cli):
TEST_COMBINATIONS = (
# quote_mode, var_name, var_value, expected_result
("always", "HELLO", "WORLD", 'HELLO="WORLD"\n'),
("never", "HELLO", "WORLD", 'HELLO=WORLD\n'),
("auto", "HELLO", "WORLD", 'HELLO=WORLD\n'),
("auto", "HELLO", "HELLO WORLD", 'HELLO="HELLO WORLD"\n'),
)
with cli.isolated_filesystem():
for quote_mode, variable, value, expected_result in TEST_COMBINATIONS:
sh.touch(dotenv_path)
sh.dotenv('-f', dotenv_path, '-q', quote_mode, 'set', variable, value)
output = sh.cat(dotenv_path)
assert output == expected_result
sh.rm(dotenv_path)
# should fail for not existing file
result = cli.invoke(dotenv.cli.set, ['my_key', 'my_value'])
assert result.exit_code != 0
# should fail for not existing file
result = cli.invoke(dotenv.cli.get, ['my_key'])
assert result.exit_code != 0
# should fail for not existing file
result = cli.invoke(dotenv.cli.list, [])
assert result.exit_code != 0
开发者ID:Gwill,项目名称:python-dotenv,代码行数:27,代码来源:test_cli.py
示例11: add_sudoers_option
def add_sudoers_option(line):
"""
Adds a option to /etc/sudoers file in safe manner.
Generate a bash script which will be invoke itself as visudo EDITOR.
http://stackoverflow.com/a/3706774/315168
"""
from sh import chmod, rm
with sudo:
if not has_line("/etc/sudoers", line):
print "Updating /etc/sudoers to enable %s" % line
tmp = tempfile.NamedTemporaryFile(mode="wt", delete=False)
# Generate visudo EDITOR which adds the line
# https://www.ibm.com/developerworks/mydeveloperworks/blogs/brian/entry/edit_sudoers_file_from_a_script4?lang=en
script = ADD_LINE_VISUDO.format(line=line)
tmp.write(script)
tmp.close()
chmod("u+x", tmp.name)
Command(tmp.name)()
rm(tmp.name)
开发者ID:miohtama,项目名称:senorita.plonetool,代码行数:26,代码来源:main.py
示例12: before_job
def before_job(self, provider, ctx={}, *args, **kwargs):
log_dir = provider.log_dir
self.ensure_log_dir(log_dir)
log_file = provider.log_file.format(
date=datetime.now().strftime("%Y-%m-%d_%H-%M"))
ctx['log_file'] = log_file
if log_file == "/dev/null":
return
log_link = os.path.join(log_dir, "latest")
ctx['log_link'] = log_link
lfiles = [os.path.join(log_dir, lfile)
for lfile in os.listdir(log_dir)
if lfile.startswith(provider.name)]
lfiles_set = set(lfiles)
# sort to get the newest 10 files
lfiles_ts = sorted(
[(os.path.getmtime(lfile), lfile) for lfile in lfiles],
key=lambda x: x[0],
reverse=True)
lfiles_keep = set([x[1] for x in lfiles_ts[:self.limit]])
lfiles_rm = lfiles_set - lfiles_keep
# remove old files
for lfile in lfiles_rm:
try:
sh.rm(lfile)
except:
pass
# create a soft link
self.create_link(log_link, log_file)
开发者ID:mengqingzhong,项目名称:tunasync,代码行数:33,代码来源:loglimit.py
示例13: update_cache
def update_cache(self):
if not self.test_cache():
rm(self.cache_dir, '-rf')
self.cache_dir = mkdtemp()
self.cache_uuid = uuid4()
mkdir(os.path.join(self.cache_dir, 'repodata'))
index_file_url = '/'.join([self.repo_url, self.index_file])
index_file_path = os.path.join(self.cache_dir, self.index_file)
try:
print("Downloading index file '{0}' --> '{1}' ...".format(
index_file_url, index_file_path
))
wget(index_file_url, '-O', index_file_path)
except:
self.broken = True
return
try:
xmlroot = etree.parse(index_file_path).getroot()
xmlns = xmlroot.nsmap[None]
for item in xmlroot.findall("{{{0}}}data".format(xmlns)):
for subitem in item.findall("{{{0}}}location".format(xmlns)):
location = subitem.get('href')
url = '/'.join([self.repo_url, location])
path = '/'.join([self.cache_dir, location])
print("Downloading file '{0}' --> '{1}' ...".format(
url, path
))
wget(url, '-O', path)
except:
self.broken = True
开发者ID:teselkin,项目名称:murano-scripts,代码行数:33,代码来源:package_dependencies.py
示例14: post_syslog
def post_syslog(self, message, response):
output = status.tar_syslog_files(
"/run/shm/syslog-%s.tar.gz" %
(datetime.datetime.now().strftime("%Y%m%d%H%M")))
headers = message.data.get("headers", {})
r = requests.post(
message.data["url"],
files={output: open(output, "rb")},
headers=headers,
verify=False
)
if r.status_code != requests.codes.ok:
return response(
code=r.status_code,
data={"message": "Can't upload config."}
)
sh.rm("-rf", sh.glob("/run/shm/syslog-*.tar.gz"))
resp = r.json()
if "url" not in resp:
return response(
code=500, data={"message": "Can't get file link."})
return response(data={"url": resp["url"]})
开发者ID:Sanji-IO,项目名称:sanji-bundle-status,代码行数:25,代码来源:index.py
示例15: pull_file_from_device
def pull_file_from_device(serial_num, file_path, file_name, output_dir):
if not os.path.exists(output_dir):
sh.mkdir("-p", output_dir)
output_path = "%s/%s" % (output_dir, file_path)
if os.path.exists(output_path):
sh.rm('-rf', output_path)
adb_pull(file_path + '/' + file_name, output_dir, serial_num)
开发者ID:lemonish,项目名称:mace,代码行数:7,代码来源:sh_commands.py
示例16: make_random_fast
def make_random_fast():
''' Link /dev/random to /dev/urandom.
See
Myths about /dev/urandom
http://www.2uo.de/myths-about-urandom/
Hacker news discussion where cperciva does not disagree with "Myths about /dev/urandom"
https://news.ycombinator.com/item?id=10149019
The risk of using urandom is that it can be deterministic.
If you know the seed, you may know all of urandom's output forever.
That is why we prefer to add entropy at runtime, using e.g. haveged.
But does haveged affect urandom? The urandom seed may be set just
once and saved, or set at boot before haveged runs.
'''
# delete /dev/random
if os.path.exists('/dev/random'):
if os.path.isfile('/dev/random') or os.path.islink('/dev/random'):
os.remove('/dev/random')
else:
try:
sh.umount('/dev/random')
except:
sh.rm('--force', '--recursive', '/dev/random')
# "rngd -r /dev/urandom" should only be used during testing, if ever
# if not is_program_running('rngd'):
# sh.rngd('-r', '/dev/urandom')
sh.ln('--symbolic', '/dev/urandom', '/dev/random')
开发者ID:goodcrypto,项目名称:goodcrypto-libs,代码行数:32,代码来源:harden.py
示例17: packaging_lib
def packaging_lib(libmace_output_dir, project_name):
print("* Package libs for %s" % project_name)
tar_package_name = "libmace_%s.tar.gz" % project_name
project_dir = "%s/%s" % (libmace_output_dir, project_name)
tar_package_path = "%s/%s" % (project_dir, tar_package_name)
if os.path.exists(tar_package_path):
sh.rm("-rf", tar_package_path)
print("Start packaging '%s' libs into %s" % (project_name,
tar_package_path))
which_sys = platform.system()
if which_sys == "Linux":
sh.tar(
"cvzf",
"%s" % tar_package_path,
glob.glob("%s/*" % project_dir),
"--exclude",
"%s/_tmp" % project_dir,
_fg=True)
elif which_sys == "Darwin":
sh.tar(
"--exclude",
"%s/_tmp" % project_dir,
"-cvzf",
"%s" % tar_package_path,
glob.glob("%s/*" % project_dir),
_fg=True)
print("Packaging Done!\n")
return tar_package_path
开发者ID:lemonish,项目名称:mace,代码行数:29,代码来源:sh_commands.py
示例18: initialize
def initialize():
# noinspection PyUnresolvedReferences
from sh import wget, tar, rm, shasum
if not os.path.exists(prefix):
os.makedirs(prefix)
if (not os.path.exists(dirs['inputs'])) or (not os.path.exists(dirs['intermediates'])):
try:
if not os.path.exists(prefix):
logger.info("Creating {DIR}".format(DIR=prefix))
os.makedirs(prefix)
logger.info("Downloading data from {URL} to {DIR}".format(URL=data_url, DIR=prefix))
tar(wget(data_url, "-qO-", _piped=True), "xz", _cwd=prefix)
logger.info("Checking checksums of downloaded files")
for line in shasum("-c", _cwd=prefix, _in=checksums, _iter=True):
logger.info(line)
except Exception as e:
logger.info("Error: {}".format(e.message))
logger.info("Deleting {DIR}".format(DIR=dirs['inputs']))
rm(dirs['inputs'], '-rf')
logger.info("Deleting {DIR}".format(DIR=dirs['intermediates']))
rm(dirs['intermediates'], '-rf')
raise
# make sure all those directories exist
for d in (dirs['outputs'], dirs['plots']):
if not os.path.exists(d):
logger.info("Creating {DIR}".format(DIR=d))
os.makedirs(d)
开发者ID:TESScience,项目名称:SPyFFI,代码行数:29,代码来源:settings.py
示例19: tmpdir
def tmpdir():
path = mkdtemp(prefix='arx.')
try:
log.debug('Temporary directory is: %s', path)
yield path
finally:
rm('-rf', path)
开发者ID:drcloud,项目名称:arx,代码行数:7,代码来源:tmp.py
示例20: trial
def trial(num_bins=1, size_bin=500, after_rm=None, max_delta=0.05):
from sh import imgbase, rm, ls
def img_free():
return float(imgbase("layout", "--free-space"))
imgbase = imgbase.bake("--debug")
a = img_free()
[dd(B, size_bin) for B in iter(range(0, num_bins))]
print("Files which were created")
print(ls("-shal", *glob.glob("/var/tmp/*.bin")))
b = img_free()
print("Files are getting removed")
rm("-f", *glob.glob("/var/tmp/*.bin"))
after_rm()
c = img_free()
ratio = a / c
print(a, b, c, ratio)
delta = 1 - ratio
assert delta < max_delta, \
"Delta %s is larger than %s" % (delta, max_delta)
开发者ID:oVirt,项目名称:imgbased,代码行数:25,代码来源:testStorage.py
注:本文中的sh.rm函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论