本文整理汇总了Python中os.path.join方法的典型用法代码示例。如果您正苦于以下问题:Python path.join方法的具体用法?Python path.join怎么用?Python path.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类os.path
的用法示例。
在下文中一共展示了path.join方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: isUpdatesAvailable
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def isUpdatesAvailable(cls, path):
if sys.version_info < (3, 0):
return False
# pylint: disable=broad-except
if not os.path.isfile(os.path.join(path, "files.xml")):
return True
try:
available = dict()
for it in ET.parse(os.path.join(path, "files.xml")).iter():
if it.tag == "File":
available[it.text] = datetime.datetime.strptime(it.attrib["Modified"], "%d-%m-%Y")
path = NamedTemporaryFile()
path.close()
urllib.request.urlretrieve("https://www.gurux.fi/obis/files.xml", path.name)
for it in ET.parse(path.name).iter():
if it.tag == "File":
tmp = datetime.datetime.strptime(it.attrib["Modified"], "%d-%m-%Y")
if not it.text in available or available[it.text] != tmp:
return True
except Exception as e:
print(e)
return True
return False
示例2: updateManufactureSettings
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def updateManufactureSettings(cls, directory):
#
# Update manufacturer settings from the Gurux www server.
#
# directory: Target directory.
#
if sys.version_info >= (3, 0):
return
if not os.path.isdir(directory):
os.mkdir(directory)
if not os.path.isdir(directory):
return
path = os.path.join(directory, "files.xml")
urllib.request.urlretrieve("https://www.gurux.fi/obis/files.xml", path)
for it in ET.parse(path).iter():
if it.tag == "File":
path = os.path.join(directory, it.text)
urllib.request.urlretrieve("https://www.gurux.fi/obis/" + it.text, path)
示例3: readManufacturerSettings
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def readManufacturerSettings(cls, manufacturers, path):
# pylint: disable=broad-except
manufacturers = []
files = [f for f in listdir(path) if isfile(join(path, f))]
if files:
for it in files:
if it.endswith(".obx"):
try:
manufacturers.append(cls.__parse(os.path.join(path, it)))
except Exception as e:
print(e)
continue
#
# Serialize manufacturer from the xml.
#
# @param in
# Input stream.
# Serialized manufacturer.
#
示例4: add_base_arguments
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def add_base_arguments(parser, default_help):
import os
from os.path import join as path_join
home = os.environ.get('HOME')
mono_sources_default = os.environ.get('MONO_SOURCE_ROOT', '')
parser.add_argument('--verbose-make', action='store_true', default=False, help=default_help)
# --jobs supports not passing an argument, in which case the 'const' is used,
# which is the number of CPU cores on the host system.
parser.add_argument('--jobs', '-j', nargs='?', const=str(os.cpu_count()), default='1', help=default_help)
parser.add_argument('--configure-dir', default=path_join(home, 'mono-configs'), help=default_help)
parser.add_argument('--install-dir', default=path_join(home, 'mono-installs'), help=default_help)
if mono_sources_default:
parser.add_argument('--mono-sources', default=mono_sources_default, help=default_help)
else:
parser.add_argument('--mono-sources', required=True)
parser.add_argument('--mxe-prefix', default='/usr', help=default_help)
示例5: clean
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def clean(opts: BaseOpts, target: str):
build_dir = path_join(opts.configure_dir, 'llvm-%s' % target)
install_dir = path_join(opts.install_dir, 'llvm-%s' % target)
stamp_file = path_join(opts.configure_dir, '.stamp-%s-make' % target)
rm_rf(stamp_file)
make_args = make_default_args(opts)
make_args += [
'-C', '%s/llvm' % opts.mono_source_root,
'-f', 'build.mk', 'clean-llvm',
'LLVM_BUILD=%s' % build_dir,
'LLVM_PREFIX=%s' % install_dir
]
run_command('make', args=make_args, name='make clean')
示例6: strip_libs
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def strip_libs(opts: DesktopOpts, product: str, target_platform: str, target: str):
if target_platform == 'osx':
# 'strip' doesn't support '--strip-unneeded' on macOS
return
if is_cross_compiling(target_platform) and target_platform == 'windows':
mxe_bin = path_join(opts.mxe_prefix, 'bin')
name_fmt = path_join(mxe_bin, target_arch[target_platform][target] + '-w64-mingw32-%s')
strip = name_fmt % 'strip'
else:
strip = 'strip'
install_dir = path_join(opts.install_dir, '%s-%s-%s' % (product, target, opts.configuration))
out_libs_dir = path_join(install_dir, 'lib')
lib_files = globs(('*.a', '*.so'), dirpath=out_libs_dir)
if len(lib_files):
run_command(strip, args=['--strip-unneeded'] + lib_files, name='strip')
if target_platform == 'windows':
out_bin_dir = path_join(install_dir, 'bin')
dll_files = globs(('*.dll',), dirpath=out_bin_dir)
if len(dll_files):
run_command(strip, args=['--strip-unneeded'] + dll_files, name='strip')
示例7: configure
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def configure(opts: AndroidOpts, product: str, target: str):
env = { 'ANDROID_API_VERSION': get_api_version_or_min(opts, target) }
if is_cross(target):
import llvm
if is_cross_mxe(target):
llvm.make(opts, 'llvmwin64')
setup_android_cross_mxe_template(env, opts, target, host_arch='x86_64')
else:
llvm.make(opts, 'llvm64')
setup_android_cross_template(env, opts, target, host_arch='x86_64')
else:
make_standalone_toolchain(opts, target, env['ANDROID_API_VERSION'])
setup_android_target_template(env, opts, target)
if not os.path.isfile(path_join(opts.mono_source_root, 'configure')):
runtime.run_autogen(opts)
runtime.run_configure(env, opts, product, target)
示例8: wasm_run_configure
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def wasm_run_configure(env: dict, opts: RuntimeOpts, product: str, target: str, emsdk_root: str):
build_dir = path_join(opts.configure_dir, '%s-%s-%s' % (product, target, opts.configuration))
mkdir_p(build_dir)
def str_dict_val(val):
if isinstance(val, list):
return ' '.join(val) # Don't need to surround with quotes
return val
ac_vars = env['_%s_%s_AC_VARS' % (product, target)]
configure_flags = env['_%s_%s_CONFIGURE_FLAGS' % (product, target)]
configure = path_join(opts.mono_source_root, 'configure')
configure_args = ac_vars + configure_flags
configure_env = os.environ.copy()
target_extra_path = env.get('_%s-%s_PATH' % (product, target), '')
if target_extra_path:
configure_env['PATH'] += ':' + target_extra_path
configure_env['PATH'] = emsdk_root + ':' + configure_env['PATH']
run_command('emconfigure', args=[configure] + configure_args, cwd=build_dir, env=configure_env, name='configure')
示例9: run_configure
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def run_configure(env: dict, opts: RuntimeOpts, product: str, target: str):
build_dir = path_join(opts.configure_dir, '%s-%s-%s' % (product, target, opts.configuration))
mkdir_p(build_dir)
def str_dict_val(val):
if isinstance(val, list):
return ' '.join(val) # Don't need to surround with quotes
return val
ac_vars = env['_runtime_%s-%s_AC_VARS' % (product, target)]
configure_env_args = env['_runtime_%s-%s_CONFIGURE_ENVIRONMENT' % (product, target)]
configure_env_args = [('%s=%s' % (key, str_dict_val(value))) for (key, value) in configure_env_args.items()]
configure_flags = env['_runtime_%s-%s_CONFIGURE_FLAGS' % (product, target)]
configure = path_join(opts.mono_source_root, 'configure')
configure_args = ac_vars + configure_env_args + configure_flags
configure_env = os.environ.copy()
target_extra_path = env.get('_%s-%s_PATH' % (product, target), '')
if target_extra_path:
configure_env['PATH'] += ':' + target_extra_path
run_command(configure, args=configure_args, cwd=build_dir, env=configure_env, name='configure')
示例10: get_subset_by_classes
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def get_subset_by_classes(self):
"""Filter imgs by user-defined categories."""
subset_data_infos = []
for data_info in self.data_infos:
img_id = data_info['id']
xml_path = osp.join(self.img_prefix, 'Annotations',
f'{img_id}.xml')
tree = ET.parse(xml_path)
root = tree.getroot()
for obj in root.findall('object'):
name = obj.find('name').text
if name in self.CLASSES:
subset_data_infos.append(data_info)
break
return subset_data_infos
示例11: get_cat_ids
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def get_cat_ids(self, idx):
"""Get category ids in XML file by index.
Args:
idx (int): Index of data.
Returns:
list[int]: All categories in the image of specified index.
"""
cat_ids = []
img_id = self.data_infos[idx]['id']
xml_path = osp.join(self.img_prefix, 'Annotations', f'{img_id}.xml')
tree = ET.parse(xml_path)
root = tree.getroot()
for obj in root.findall('object'):
name = obj.find('name').text
if name not in self.CLASSES:
continue
label = self.cat2label[name]
cat_ids.append(label)
return cat_ids
示例12: test_load_multi_channel_img
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def test_load_multi_channel_img(self):
results = dict(
img_prefix=self.data_prefix,
img_info=dict(filename=['color.jpg', 'color.jpg']))
transform = LoadMultiChannelImageFromFiles()
results = transform(copy.deepcopy(results))
assert results['filename'] == [
osp.join(self.data_prefix, 'color.jpg'),
osp.join(self.data_prefix, 'color.jpg')
]
assert results['ori_filename'] == ['color.jpg', 'color.jpg']
assert results['img'].shape == (288, 512, 3, 2)
assert results['img'].dtype == np.uint8
assert results['img_shape'] == (288, 512, 3, 2)
assert results['ori_shape'] == (288, 512, 3, 2)
assert results['pad_shape'] == (288, 512, 3, 2)
assert results['scale_factor'] == 1.0
assert repr(transform) == transform.__class__.__name__ + \
"(to_float32=False, color_type='unchanged', " + \
"file_client_args={'backend': 'disk'})"
示例13: test_albu_transform
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def test_albu_transform():
results = dict(
img_prefix=osp.join(osp.dirname(__file__), '../data'),
img_info=dict(filename='color.jpg'))
# Define simple pipeline
load = dict(type='LoadImageFromFile')
load = build_from_cfg(load, PIPELINES)
albu_transform = dict(
type='Albu', transforms=[dict(type='ChannelShuffle', p=1)])
albu_transform = build_from_cfg(albu_transform, PIPELINES)
normalize = dict(type='Normalize', mean=[0] * 3, std=[0] * 3, to_rgb=True)
normalize = build_from_cfg(normalize, PIPELINES)
# Execute transforms
results = load(results)
results = albu_transform(results)
results = normalize(results)
assert results['img'].dtype == np.float32
示例14: test_default_format_bundle
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def test_default_format_bundle():
results = dict(
img_prefix=osp.join(osp.dirname(__file__), '../data'),
img_info=dict(filename='color.jpg'))
load = dict(type='LoadImageFromFile')
load = build_from_cfg(load, PIPELINES)
bundle = dict(type='DefaultFormatBundle')
bundle = build_from_cfg(bundle, PIPELINES)
results = load(results)
assert 'pad_shape' not in results
assert 'scale_factor' not in results
assert 'img_norm_cfg' not in results
results = bundle(results)
assert 'pad_shape' in results
assert 'scale_factor' in results
assert 'img_norm_cfg' in results
示例15: main
# 需要导入模块: from os import path [as 别名]
# 或者: from os.path import join [as 别名]
def main():
args = parse_args()
cityscapes_path = args.cityscapes_path
out_dir = args.out_dir if args.out_dir else cityscapes_path
mmcv.mkdir_or_exist(out_dir)
img_dir = osp.join(cityscapes_path, args.img_dir)
gt_dir = osp.join(cityscapes_path, args.gt_dir)
set_name = dict(
train='instancesonly_filtered_gtFine_train.json',
val='instancesonly_filtered_gtFine_val.json',
test='instancesonly_filtered_gtFine_test.json')
for split, json_name in set_name.items():
print(f'Converting {split} into {json_name}')
with mmcv.Timer(
print_tmpl='It tooks {}s to convert Cityscapes annotation'):
files = collect_files(
osp.join(img_dir, split), osp.join(gt_dir, split))
image_infos = collect_annotations(files, nproc=args.nproc)
cvt_annotations(image_infos, osp.join(out_dir, json_name))