本文整理汇总了Python中common_py.system.filesystem.FileSystem.remove方法的典型用法代码示例。如果您正苦于以下问题:Python FileSystem.remove方法的具体用法?Python FileSystem.remove怎么用?Python FileSystem.remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类common_py.system.filesystem.FileSystem
的用法示例。
在下文中一共展示了FileSystem.remove方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_snapshot_contents
# 需要导入模块: from common_py.system.filesystem import FileSystem [as 别名]
# 或者: from common_py.system.filesystem.FileSystem import remove [as 别名]
def get_snapshot_contents(js_path, snapshot_tool, literals=None):
""" Convert the given module with the snapshot generator
and return the resulting bytes.
"""
wrapped_path = js_path + ".wrapped"
snapshot_path = js_path + ".snapshot"
module_name = os.path.splitext(os.path.basename(js_path))[0]
with open(wrapped_path, 'w') as fwrapped, open(js_path, "r") as fmodule:
if module_name != "iotjs":
fwrapped.write("(function(exports, require, module, native) {\n")
fwrapped.write(fmodule.read())
if module_name != "iotjs":
fwrapped.write("});\n")
cmd = [snapshot_tool, "generate", "-o", snapshot_path]
if literals:
cmd.extend(["--static", "--load-literals-list-format", literals])
ret = subprocess.call(cmd + [wrapped_path])
fs.remove(wrapped_path)
if ret != 0:
if literals == None:
msg = "Failed to dump %s: - %d" % (js_path, ret)
print("%s%s%s" % ("\033[1;31m", msg, "\033[0m"))
exit(1)
else:
print("Unable to create static snapshot from '%s'. Falling back "
"to normal snapshot." % js_path)
return snapshot_path
示例2: get_snapshot_contents
# 需要导入模块: from common_py.system.filesystem import FileSystem [as 别名]
# 或者: from common_py.system.filesystem.FileSystem import remove [as 别名]
def get_snapshot_contents(module_name, snapshot_generator):
""" Convert the given module with the snapshot generator
and return the resulting bytes.
"""
js_path = fs.join(path.SRC_ROOT, 'js', module_name + '.js')
wrapped_path = js_path + ".wrapped"
snapshot_path = js_path + ".snapshot"
with open(wrapped_path, 'w') as fwrapped, open(js_path, "r") as fmodule:
if module_name != "iotjs":
fwrapped.write("(function(exports, require, module) {\n")
fwrapped.write(fmodule.read())
if module_name != "iotjs":
fwrapped.write("});\n")
ret = subprocess.call([snapshot_generator,
"--save-snapshot-for-eval",
snapshot_path,
wrapped_path])
if ret != 0:
msg = "Failed to dump %s: - %d" % (js_path, ret)
print("%s%s%s" % ("\033[1;31m", msg, "\033[0m"))
exit(1)
with open(snapshot_path, 'rb') as snapshot:
code = snapshot.read()
fs.remove(wrapped_path)
fs.remove(snapshot_path)
return code
示例3: get_snapshot_contents
# 需要导入模块: from common_py.system.filesystem import FileSystem [as 别名]
# 或者: from common_py.system.filesystem.FileSystem import remove [as 别名]
def get_snapshot_contents(js_path, snapshot_tool):
""" Convert the given module with the snapshot generator
and return the resulting bytes.
"""
wrapped_path = js_path + ".wrapped"
snapshot_path = js_path + ".snapshot"
module_name = os.path.splitext(os.path.basename(js_path))[0]
with open(wrapped_path, 'w') as fwrapped, open(js_path, "r") as fmodule:
if module_name != "iotjs":
fwrapped.write("(function(exports, require, module, native) {\n")
fwrapped.write(fmodule.read())
if module_name != "iotjs":
fwrapped.write("});\n")
ret = subprocess.call([snapshot_tool,
"generate",
"--context", "eval",
"-o", snapshot_path,
wrapped_path])
fs.remove(wrapped_path)
if ret != 0:
msg = "Failed to dump %s: - %d" % (js_path, ret)
print("%s%s%s" % ("\033[1;31m", msg, "\033[0m"))
fs.remove(snapshot_path)
exit(1)
return snapshot_path
示例4: merge_snapshots
# 需要导入模块: from common_py.system.filesystem import FileSystem [as 别名]
# 或者: from common_py.system.filesystem.FileSystem import remove [as 别名]
def merge_snapshots(snapshot_infos, snapshot_tool):
output_path = fs.join(path.SRC_ROOT, 'js','merged.modules')
cmd = [snapshot_tool, "merge", "-o", output_path]
cmd.extend([item['path'] for item in snapshot_infos])
ret = subprocess.call(cmd)
if ret != 0:
msg = "Failed to merge %s: - %d" % (snapshot_infos, ret)
print("%s%s%s" % ("\033[1;31m", msg, "\033[0m"))
exit(1)
for item in snapshot_infos:
fs.remove(item['path'])
with open(output_path, 'rb') as snapshot:
code = snapshot.read()
fs.remove(output_path)
return code
示例5: js2c
# 需要导入模块: from common_py.system.filesystem import FileSystem [as 别名]
# 或者: from common_py.system.filesystem.FileSystem import remove [as 别名]
def js2c(options, js_modules):
is_debug_mode = (options.buildtype == "debug")
snapshot_tool = options.snapshot_tool
no_snapshot = (snapshot_tool == None)
verbose = options.verbose
magic_string_set = set()
str_const_regex = re.compile('^#define IOTJS_MAGIC_STRING_\w+\s+"(\w+)"$')
with open(fs.join(path.SRC_ROOT, 'iotjs_magic_strings.in'), 'r') as fin_h:
for line in fin_h:
result = str_const_regex.search(line)
if result:
magic_string_set.add(result.group(1))
# generate the code for the modules
with open(fs.join(path.SRC_ROOT, 'iotjs_js.h'), 'w') as fout_h, \
open(fs.join(path.SRC_ROOT, 'iotjs_js.c'), 'w') as fout_c:
fout_h.write(LICENSE)
fout_h.write(HEADER1)
fout_c.write(LICENSE)
fout_c.write(HEADER2)
snapshot_infos = []
js_module_names = []
if no_snapshot:
for idx, module in enumerate(sorted(js_modules)):
[name, js_path] = module.split('=', 1)
js_module_names.append(name)
if verbose:
print('Processing module: %s' % name)
code = get_js_contents(js_path, is_debug_mode)
code_string = format_code(code, 1)
fout_h.write(MODULE_VARIABLES_H.format(NAME=name))
fout_c.write(MODULE_VARIABLES_C.format(NAME=name,
NAME_UPPER=name.upper(),
SIZE=len(code),
CODE=code_string))
modules_struct = [
' {{ {0}_n, {0}_s, SIZE_{1} }},'.format(name, name.upper())
for name in sorted(js_module_names)
]
modules_struct.append(' { NULL, NULL, 0 }')
native_struct_h = NATIVE_STRUCT_H
else:
# Generate snapshot files from JS files
for idx, module in enumerate(sorted(js_modules)):
[name, js_path] = module.split('=', 1)
js_module_names.append(name)
if verbose:
print('Processing (1st phase) module: %s' % name)
code_path = get_snapshot_contents(js_path, snapshot_tool)
info = {'name': name, 'path': code_path, 'idx': idx}
snapshot_infos.append(info)
# Get the literal list from the snapshots
if verbose:
print('Creating literal list file for static snapshot '
'creation')
literals_path = get_literals_from_snapshots(snapshot_tool,
[info['path'] for info in snapshot_infos])
magic_string_set |= read_literals(literals_path)
# Update the literals list file
write_literals_to_file(magic_string_set, literals_path)
# Generate static-snapshots if possible
for idx, module in enumerate(sorted(js_modules)):
[name, js_path] = module.split('=', 1)
if verbose:
print('Processing (2nd phase) module: %s' % name)
get_snapshot_contents(js_path, snapshot_tool, literals_path)
fout_h.write(MODULE_SNAPSHOT_VARIABLES_H.format(NAME=name))
fout_c.write(MODULE_SNAPSHOT_VARIABLES_C.format(NAME=name,
IDX=idx))
fs.remove(literals_path)
# Merge the snapshot files
code = merge_snapshots(snapshot_infos, snapshot_tool)
code_string = format_code(code, 1)
name = 'iotjs_js_modules'
fout_h.write(MODULE_VARIABLES_H.format(NAME=name))
fout_c.write(MODULE_VARIABLES_C.format(NAME=name,
NAME_UPPER=name.upper(),
SIZE=len(code),
CODE=code_string))
modules_struct = [
' {{ module_{0}, MODULE_{0}_IDX }},'.format(info['name'])
for info in snapshot_infos
]
modules_struct.append(' { NULL, 0 }')
native_struct_h = NATIVE_SNAPSHOT_STRUCT_H
fout_h.write(native_struct_h)
fout_h.write(FOOTER1)
#.........这里部分代码省略.........