本文整理汇总了Python中sh.mv函数的典型用法代码示例。如果您正苦于以下问题:Python mv函数的具体用法?Python mv怎么用?Python mv使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mv函数的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: generate_template
def generate_template():
template_file = ""
if not isdir(build_dir):
mkdir(build_dir)
if isdir(build_dir):
template_file = build_dir + "/dekko.dekkoproject.pot"
print("TemplateFile: " + template_file)
cd(build_dir)
print("Running cmake to generate updated template")
cmake('..')
print("Running make")
make("-j2")
if isfile(template_file):
if isdir(po_dir):
print("Moving template to po dir: " + po_dir)
mv(template_file, po_dir)
else:
print("Couldn't find po dir: " + po_dir)
cleanup()
return
else:
cleanup()
print("No template found for: " + template_file)
return
print("Cleaning up")
cleanup()
print("YeeHaa!")
print("All done, you need to commit & push this to bitbucket now :-)")
print("NOTE: this would also be a good time to sync with launchpad, run")
print(" $ python3 launchpad_sync.py")
开发者ID:ubuntu-touch-apps,项目名称:dekko,代码行数:30,代码来源:update_translations.py
示例3: make_bootable
def make_bootable(self):
""" Tworzenie dysku bootowalnego
"""
self.uuid = re.search("UUID=\"(\w*)\"", str(sh.blkid(self.device + "1"))).group(1)
print("Device UUID:", self.uuid)
# W niektórych wersjach windows katalog ten jest z drukowanej
self.boot_folder = self.destination_mount + "/boot"
try: sh.mv(self.destination_mount + "/BOOT", self.boot_folder)
except:
pass
# Instalownie bootloadera
# grub-install --target=i386-pc --boot-directory="/<USB_mount_folder>/boot" /dev/sdX
installer = sh.Command("grub-install")
installer(self.device, target="i386-pc", boot_directory=self.destination_mount + "/boot")
# Tworzenie konfiguracji GRUBa
with open("{}/grub/grub.cfg".format(self.boot_folder), "wt") as config:
config.write("""
set menu_color_normal=white/black
set menu_color_highlight=black/light-gray
menuentry 'Install Windows' {
ntldr /bootmgr
}
""")
开发者ID:poxip,项目名称:pyWinUSB,代码行数:26,代码来源:creator.py
示例4: run
def run(self):
global g, pid
time.sleep(15)
try:
while True:
sstv_debug_log('Encoder', 'Encoder reporting for duty')
convert(
'/tmp/latest.jpg',
'-resize', '320x240!',
'-pointsize', '35',
'-fill', 'black',
'-annotate', '+0+37',
'W8UPD',
'-fill', 'white',
'-annotate', '+0+40',
'W8UPD',
'-fill', 'black',
'-annotate', '+30+230',
'%f, %f' % (g.fix.latitude, g.fix.longitude),
'-fill', 'white',
'-annotate', '+33+233',
'%f, %f' % (g.fix.latitude, g.fix.longitude),
'/tmp/latest.ppm')
robot36_encode('/tmp/latest.ppm', '/tmp/inprogress.wav')
mv('/tmp/inprogress.wav', '/tmp/latest.wav')
except Exception as e:
sstv_debug_log('Encoder', str(e), True)
os._exit(1)
开发者ID:noexc,项目名称:habp,代码行数:28,代码来源:looper.py
示例5: move_services
def move_services(filename, num_ext):
# move to services folder
file_path = filename.rsplit('.', num_ext)[0]
src_path = path.join(app.config['UPLOAD_FOLDER'], file_path, file_path)
dest_path = app.config['SERVICES_FOLDER']
i = 0
while i != -1:
try:
src_path_i = path.join(app.config['UPLOAD_FOLDER'], file_path, file_path+str(i))
src_path_ii = path.join(app.config['UPLOAD_FOLDER'], file_path, file_path+str(i-1))
if i == 0:
mv(src_path, dest_path)
elif i == 1:
mv(src_path, dest_path_i)
mv(dest_path_i, dest_path)
else:
mv(dest_path_ii, dest_path_i)
mv(dest_path_i, dest_path)
i = -1
except:
i += 1
# remove leftover files in tmp
remove(path.join(app.config['UPLOAD_FOLDER'], filename))
rmtree(path.join(app.config['UPLOAD_FOLDER'], file_path))
开发者ID:cglewis,项目名称:wharf,代码行数:27,代码来源:index.py
示例6: move
def move(source, dest, owner=None, group=None, perms=None):
''' Move source to dest.
move() tries to generally follow the behavior of the
'mv --force' command.
move() creates any missing parent dirs of dest.
If dest is a dir, source is copied into dest.
Otherwise, source will overwrite any existing dest.
>>> import os.path, sh, tempfile
>>> def temp_filename(dir=None):
... if dir is None:
... dir = test_dir
... handle, path = tempfile.mkstemp(dir=dir)
... # we don't need the handle
... os.close(handle)
... return path
>>>
>>> test_dir = tempfile.mkdtemp()
>>>
>>> # test move to dir
>>> source = temp_filename()
>>> dest_dir = tempfile.mkdtemp(dir=test_dir)
>>> move(source, dest_dir)
>>> assert not os.path.exists(source)
>>> basename = os.path.basename(source)
>>> assert os.path.exists(os.path.join(dest_dir, basename))
>>>
>>> # test move to new filename
>>> source = temp_filename()
>>> dest_filename = temp_filename(dir=test_dir)
>>> move(source, dest_filename)
>>>
>>> # test move to existing filename
>>> DATA = 'data'
>>> source = temp_filename()
>>> dest_filename = temp_filename()
>>> with open(source, 'w') as sourcefile:
... sourcefile.write(DATA)
>>> move(source, dest_filename)
>>> assert not os.path.exists(source)
>>> assert os.path.exists(dest_filename)
>>> with open(dest_filename) as destfile:
... assert DATA == destfile.read()
>>>
>>> # clean up
>>> sh_result = sh.rm('--force', '--recursive', test_dir)
>>> assert sh_result.exit_code == 0
'''
parent_dir = os.path.dirname(dest)
if not os.path.exists(parent_dir):
makedir(parent_dir, owner=owner, group=None, perms=None)
sh.mv('--force', source, dest)
set_attributes(dest, owner, group, perms, recursive=True)
开发者ID:goodcrypto,项目名称:goodcrypto-libs,代码行数:59,代码来源:fs.py
示例7: make_compliant_fastaa
def make_compliant_fastaa(self):
print "making compliant fastaas"
script = sh.Command(self.orthoMCL_path + "orthomclAdjustFasta")
if not os.path.exists(self.out_dir + "temp"):
os.makedirs(self.out_dir + "temp")
for f in tqdm(self.proteoms):
script(f.split("/")[-1].split(".")[0], f, 1)
sh.mv(f.split("/")[-1].split(".")[0] + ".fasta",self.out_dir + "temp/" )
开发者ID:moritzbuck,项目名称:Pyscratches,代码行数:8,代码来源:orthoMCL.py
示例8: __enter__
def __enter__(self):
try:
sh.test('-d', self.path)
self.already_disabled = False
except sh.ErrorReturnCode_1:
self.already_disabled = True
else:
sh.mv(self.path, self.hidden_path)
开发者ID:kkrampa,项目名称:commcare-hq,代码行数:8,代码来源:rebuildstaging.py
示例9: main
def main():
if not os.path.isfile(PATH + 'cowposts.db'):
db_init()
filename = sys.argv[1]
with open(filename, 'r') as f:
text = f.read()
db_insert(filename, text)
mv(filename, 'posts/')
开发者ID:nmyk,项目名称:cowsay-blog,代码行数:8,代码来源:cowpost.py
示例10: _commit_changes
def _commit_changes(self):
self._ensure_subvolume()
self._ensure_subvolume()
gc_dir = self.gc_dir.format(timestamp=datetime.now().strftime("%s"))
out = sh.mv(self.service_dir, gc_dir)
assert out.exit_code == 0 and out.stderr == ""
out = sh.mv(self.working_dir, self.service_dir)
assert out.exit_code == 0 and out.stderr == ""
开发者ID:diguabo,项目名称:tunasync,代码行数:9,代码来源:btrfs_snapshot.py
示例11: file_sample
def file_sample(language: str, checksum: str, sample: AudioSample) -> None:
sample_name = '{language}-{checksum}.mp3'.format(language=language,
checksum=checksum)
parent_dir = path.join(SAMPLE_DIR, language)
if not path.isdir(parent_dir):
os.mkdir(parent_dir)
dest_file = path.join(parent_dir, sample_name)
sh.mv(sample.filename, dest_file)
开发者ID:larsyencken,项目名称:wide-language-index,代码行数:9,代码来源:add_sample.py
示例12: retry_import_files
def retry_import_files(input):
errors = os.path.join(input, '_ERRORS')
if not os.path.exists(errors):
logger.error("Task dir _ERRORS doesn't exist.")
for dir_name, dir_names, file_names in os.walk(errors):
for file_name in file_names:
error_path = os.path.join(dir_name, file_name)
logger.info('Moving %s to %s' % (error_path, input))
sh.mv(error_path, input)
import_files(input)
开发者ID:gisce,项目名称:atr,代码行数:10,代码来源:tasks.py
示例13: dump_pairs
def dump_pairs(self):
if os.path.exists( "pairs/"):
sh.rm("-r", "pairs/")
if os.path.exists(self.out_dir + "pairs/"):
sh.rm("-r", self.out_dir + "pairs/")
print "dumping pairs"
script = sh.Command(self.orthoMCL_path + "orthomclDumpPairsFiles")
script(self.db_cfg)
sh.mv("mclInput", self.out_dir)
sh.mv( "pairs", self.out_dir)
开发者ID:moritzbuck,项目名称:Pyscratches,代码行数:10,代码来源:orthoMCL.py
示例14: run
def run(self):
data = {"convert":"True"}
with self.output().open('r') as f:
existing = json.load(f)
for folders in existing['folders_list']:
sh.mv(folders,self.dropbox_folder)
with self.output().open('w') as f:
existing.update(data)
json.dump(existing,f)
开发者ID:prodeveloper,项目名称:audio_splitter,代码行数:10,代码来源:run_luigi.py
示例15: after_job
def after_job(self, status=None, ctx={}, *args, **kwargs):
log_file = ctx.get('log_file', None)
log_link = ctx.get('log_link', None)
if log_file == "/dev/null":
return
if status == "fail":
log_file_save = log_file + ".fail"
try:
sh.mv(log_file, log_file_save)
except:
pass
self.create_link(log_link, log_file_save)
开发者ID:mengqingzhong,项目名称:tunasync,代码行数:12,代码来源:loglimit.py
示例16: run
def run(input_file, options, control_file=None, out_dir=None):
out_files = (remove_suffix(input_file) + "_peaks.bed",
remove_suffix(input_file) + "_summits.bed")
cmd = _build_command(input_file, options, control_file, out_dir)
subprocess.check_call(cmd)
if out_dir:
for f in out_files:
sh.mv(f, os.path.join(out_dir, os.path.basename(f)))
out_files = [os.path.join(out_dir, os.path.basename(x)) for
x in out_files]
return out_files
开发者ID:anindya028,项目名称:bipy,代码行数:12,代码来源:macs.py
示例17: tearDownClass
def tearDownClass(cls):
cls.log.debug("\n"+"#"*90)
# Getting back original site.pp
cls.log.debug("Restoring original site.pp ...")
if os.geteuid() != 0:
sh.sudo('/bin/mv', cls.bck_manifest_name, cls.manifest_path + "/site.pp")
else:
sh.mv(cls.bck_manifest_name, cls.manifest_path + "/site.pp")
return
开发者ID:bobcallaway,项目名称:puppet-eseries,代码行数:12,代码来源:netapp_helper_class.py
示例18: disable_etc
def disable_etc(chroot=None):
'''Disable bluetooth etc. directories in /etc.'''
for module in BadModules:
etc_paths_text = sh.find(fullpath('/etc', chroot))
etc_paths = etc_paths_text.strip().split('\n')
for path in etc_paths:
if path.endswith('/{}'.format(module)):
if os.path.exists(path):
try:
sh.mv('--force', path, path + '-unused')
except e:
print(e)
开发者ID:goodcrypto,项目名称:goodcrypto-libs,代码行数:13,代码来源:harden.py
示例19: reduce_python
def reduce_python(self):
print("Reduce python")
oldpwd = os.getcwd()
try:
print("Remove files unlikely to be used")
os.chdir(join(self.ctx.dist_dir, "root", "python"))
sh.rm("-rf", "share")
sh.rm("-rf", "bin")
os.chdir(join(self.ctx.dist_dir, "root", "python", "lib"))
sh.rm("-rf", "pkgconfig")
sh.rm("libpython2.7.a")
os.chdir(join(self.ctx.dist_dir, "root", "python", "lib", "python2.7"))
sh.find(".", "-iname", "*.pyc", "-exec", "rm", "{}", ";")
sh.find(".", "-iname", "*.py", "-exec", "rm", "{}", ";")
#sh.find(".", "-iname", "test*", "-exec", "rm", "-rf", "{}", ";")
sh.rm("-rf", "wsgiref", "bsddb", "curses", "idlelib", "hotshot")
sh.rm("-rf", sh.glob("lib*"))
# now create the zip.
print("Create a python27.zip")
sh.rm("config/libpython2.7.a")
sh.rm("config/python.o")
sh.rm("config/config.c.in")
sh.rm("config/makesetup")
sh.rm("config/install-sh")
sh.mv("config", "..")
sh.mv("site-packages", "..")
sh.zip("-r", "../python27.zip", sh.glob("*"))
sh.rm("-rf", sh.glob("*"))
sh.mv("../config", ".")
sh.mv("../site-packages", ".")
finally:
os.chdir(oldpwd)
开发者ID:524430632,项目名称:kivy-ios,代码行数:33,代码来源:__init__.py
示例20: replace_in_file
def replace_in_file(path, replacements, logger=None):
"""
This helper function performs a line replacement in the file located at 'path'.
:param is_debug_flag: true if method is called from apply_debug_flag. Needed only for managing logger output
:param path: path to the file to be altered
:param replacements: list of string pairs formatted as [old_line_pattern, new_line_replacement]
:param logger: logger object, optional. If not none, used to output if replacement is successful
"""
tmp = path + '.tmp'
if isinstance(replacements[0], string_types):
replacements = [replacements]
regexs = []
for replacement in replacements:
try:
regex = re.compile(replacement[0])
except re.error:
regex = None
regexs.append(regex)
replacements_found = []
with open(tmp, 'w+') as nf:
with open(path) as of:
for line in of.readlines():
for replacement, regex in zip(replacements, regexs):
# try a simple string match
if replacement[0] in line:
line = line.replace(replacement[0], "" if replacement[1] in (None, '') else replacement[1])
replacements_found.append(replacement[0])
# then try a regex match
else:
if regex is not None:
match = regex.search(line)
if match is not None:
try:
line = line.replace(match.groups(0)[0], "" if replacement[1] in (None, '') else replacement[1])
replacements_found.append(match.groups(0)[0])
except IndexError:
line = line.replace(match.group(), replacement[1])
replacements_found.append([match.group()])
break
# write changed line back
nf.write(line)
sh.rm(path)
sh.mv(tmp, path)
if logger:
c = Counter(replacements_found)
for k in c.keys():
logger.debug("Found and replaced {} occurrence{}: \t{} ".format(c[k], ['', 's'][c[k] > 1], k))
开发者ID:dhondta,项目名称:rpl-attacks,代码行数:48,代码来源:helpers.py
注:本文中的sh.mv函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论