本文整理汇总了Python中utils.file_path.get_native_path_case函数的典型用法代码示例。如果您正苦于以下问题:Python get_native_path_case函数的具体用法?Python get_native_path_case怎么用?Python get_native_path_case使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_native_path_case函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: process_isolate_options
def process_isolate_options(parser, options, cwd=None, require_isolated=True):
"""Handles options added with 'add_isolate_options'.
Mutates |options| in place, by normalizing path to isolate file, values of
variables, etc.
"""
cwd = file_path.get_native_path_case(unicode(cwd or os.getcwd()))
# Parse --isolated option.
if options.isolated:
options.isolated = os.path.normpath(os.path.join(cwd, options.isolated.replace("/", os.path.sep)))
if require_isolated and not options.isolated:
parser.error("--isolated is required.")
if options.isolated and not options.isolated.endswith(".isolated"):
parser.error("--isolated value must end with '.isolated'")
# Processes all the --<foo>-variable flags.
def try_make_int(s):
"""Converts a value to int if possible, converts to unicode otherwise."""
try:
return int(s)
except ValueError:
return s.decode("utf-8")
options.config_variables = dict((k, try_make_int(v)) for k, v in options.config_variables)
options.path_variables = dict(options.path_variables)
options.extra_variables = dict(options.extra_variables)
# Normalize the path in --isolate.
if options.isolate:
# TODO(maruel): Work with non-ASCII.
# The path must be in native path case for tracing purposes.
options.isolate = unicode(options.isolate).replace("/", os.path.sep)
options.isolate = os.path.normpath(os.path.join(cwd, options.isolate))
options.isolate = file_path.get_native_path_case(options.isolate)
开发者ID:qlb7707,项目名称:webrtc_src,代码行数:35,代码来源:isolate.py
示例2: test_native_case_non_existing
def test_native_case_non_existing(self):
# Make sure it doesn't throw on non-existing files.
non_existing = 'trace_input_test_this_file_should_not_exist'
path = os.path.expanduser('~/' + non_existing)
self.assertFalse(os.path.exists(path))
path = file_path.get_native_path_case(ROOT_DIR) + os.path.sep
self.assertEqual(file_path.get_native_path_case(path), path)
开发者ID:mellowdistrict,项目名称:luci-py,代码行数:7,代码来源:file_path_test.py
示例3: test_native_case_symlink_right_case
def test_native_case_symlink_right_case(self):
actual = file_path.get_native_path_case(os.path.join(BASE_DIR, "trace_inputs"))
self.assertEqual("trace_inputs", os.path.basename(actual))
# Make sure the symlink is not resolved.
actual = file_path.get_native_path_case(os.path.join(BASE_DIR, "trace_inputs", "files2"))
self.assertEqual("files2", os.path.basename(actual))
开发者ID:rzr,项目名称:Tizen_Crosswalk,代码行数:7,代码来源:file_path_test.py
示例4: test_subdir
def test_subdir(self):
# The resulting .isolated file will be missing ../../isolate.py. It is
# because this file is outside the --subdir parameter.
isolate_file = os.path.join(
ROOT_DIR, 'tests', 'isolate', 'touch_root.isolate')
options = self._get_option(isolate_file)
complete_state = isolate.load_complete_state(
options, self.cwd, os.path.join('tests', 'isolate'), False)
actual_isolated = complete_state.saved_state.to_isolated()
actual_saved_state = complete_state.saved_state.flatten()
expected_isolated = {
'algo': 'sha-1',
'command': ['python', 'touch_root.py'],
'files': {
os.path.join(u'tests', 'isolate', 'touch_root.py'): {
'm': 488,
'h': hash_file('tests', 'isolate', 'touch_root.py'),
's': _size('tests', 'isolate', 'touch_root.py'),
},
},
'relative_cwd': os.path.join(u'tests', 'isolate'),
'version': isolate.isolateserver.ISOLATED_FILE_VERSION,
}
self._cleanup_isolated(expected_isolated)
self.assertEqual(expected_isolated, actual_isolated)
expected_saved_state = {
'OS': sys.platform,
'algo': 'sha-1',
'child_isolated_files': [],
'command': ['python', 'touch_root.py'],
'config_variables': {
'OS': 'linux',
'chromeos': 1,
},
'extra_variables': {
'foo': 'bar',
},
'files': {
os.path.join(u'tests', 'isolate', 'touch_root.py'): {
'm': 488,
'h': hash_file('tests', 'isolate', 'touch_root.py'),
's': _size('tests', 'isolate', 'touch_root.py'),
},
},
'isolate_file': file_path.safe_relpath(
file_path.get_native_path_case(isolate_file),
os.path.dirname(options.isolated)),
'path_variables': {},
'relative_cwd': os.path.join(u'tests', 'isolate'),
'root_dir': file_path.get_native_path_case(ROOT_DIR),
'version': isolate.SavedState.EXPECTED_VERSION,
}
self._cleanup_isolated(expected_saved_state)
self._cleanup_saved_state(actual_saved_state)
self.assertEqual(expected_saved_state, actual_saved_state)
开发者ID:bpsinc-native,项目名称:src_tools_swarming_client,代码行数:57,代码来源:isolate_test.py
示例5: test_native_case_not_sensitive_non_existent
def test_native_case_not_sensitive_non_existent(self):
# This test also ensures that the output is independent on the input
# string case.
non_existing = os.path.join("trace_input_test_this_dir_should_not_exist", "really not", "")
path = os.path.expanduser(os.path.join(u"~", non_existing))
path = path.replace("/", os.path.sep)
self.assertFalse(os.path.exists(path))
lower = file_path.get_native_path_case(path.lower())
upper = file_path.get_native_path_case(path.upper())
# Make sure non-existing element is not modified:
self.assertTrue(lower.endswith(non_existing.lower()))
self.assertTrue(upper.endswith(non_existing.upper()))
self.assertEqual(lower[: -len(non_existing)], upper[: -len(non_existing)])
开发者ID:rzr,项目名称:Tizen_Crosswalk,代码行数:13,代码来源:file_path_test.py
示例6: test_native_case_not_sensitive
def test_native_case_not_sensitive(self):
# The home directory is almost guaranteed to have mixed upper/lower case
# letters on both Windows and OSX.
# This test also ensures that the output is independent on the input
# string case.
path = os.path.expanduser(u"~")
self.assertTrue(os.path.isdir(path))
path = path.replace("/", os.path.sep)
if sys.platform == "win32":
# Make sure the drive letter is upper case for consistency.
path = path[0].upper() + path[1:]
# This test assumes the variable is in the native path case on disk, this
# should be the case. Verify this assumption:
self.assertEqual(path, file_path.get_native_path_case(path))
self.assertEqual(file_path.get_native_path_case(path.lower()), file_path.get_native_path_case(path.upper()))
开发者ID:rzr,项目名称:Tizen_Crosswalk,代码行数:15,代码来源:file_path_test.py
示例7: _expected_saved_state
def _expected_saved_state(
self, args, read_only, empty_file, extra_vars, root_dir):
expected = {
u'OS': unicode(sys.platform),
u'algo': u'sha-1',
u'child_isolated_files': [],
u'command': [],
u'config_variables': {
u'OS': u'mac',
u'chromeos': 0,
},
u'extra_variables': {
u'EXECUTABLE_SUFFIX': u'.exe' if sys.platform == 'win32' else u'',
},
u'files': self._gen_files(read_only, empty_file, True),
u'isolate_file': file_path.safe_relpath(
file_path.get_native_path_case(unicode(self.filename())),
unicode(os.path.dirname(self.isolated))),
u'path_variables': {},
u'relative_cwd': unicode(RELATIVE_CWD[self.case()]),
u'root_dir': unicode(root_dir or os.path.dirname(self.filename())),
u'version': unicode(isolate.SavedState.EXPECTED_VERSION),
}
if args:
expected[u'command'] = [u'python'] + [unicode(x) for x in args]
expected['extra_variables'].update(extra_vars or {})
with open(self.saved_state(), 'r') as f:
self.assertEqual(expected, json.load(f))
开发者ID:Crawping,项目名称:chromium_extract,代码行数:28,代码来源:isolate_smoke_test.py
示例8: _expected_saved_state
def _expected_saved_state(self, args, read_only, empty_file, extra_vars):
flavor = isolate.get_flavor()
chromeos_value = int(flavor == 'linux')
expected = {
u'algo': u'sha-1',
u'child_isolated_files': [],
u'command': [],
u'config_variables': {
u'OS': unicode(flavor),
u'chromeos': chromeos_value,
},
u'extra_variables': {
u'EXECUTABLE_SUFFIX': u'.exe' if flavor == 'win' else u'',
},
u'files': self._gen_files(read_only, empty_file, True),
u'isolate_file': file_path.safe_relpath(
file_path.get_native_path_case(unicode(self.filename())),
unicode(os.path.dirname(self.isolated))),
u'relative_cwd': unicode(RELATIVE_CWD[self.case()]),
u'path_variables': {},
u'version': unicode(isolate.isolateserver.ISOLATED_FILE_VERSION),
}
if args:
expected[u'command'] = [u'python'] + [unicode(x) for x in args]
expected['extra_variables'].update(extra_vars or {})
self.assertEqual(expected, json.load(open(self.saved_state(), 'r')))
开发者ID:Tkkg1994,项目名称:Platfrom-kccat6,代码行数:26,代码来源:isolate_smoke_test.py
示例9: test_native_case_symlink_wrong_case
def test_native_case_symlink_wrong_case(self):
base_dir = file_path.get_native_path_case(BASE_DIR)
trace_inputs_dir = os.path.join(base_dir, "trace_inputs")
actual = file_path.get_native_path_case(trace_inputs_dir)
self.assertEqual(trace_inputs_dir, actual)
# Make sure the symlink is not resolved.
data = os.path.join(trace_inputs_dir, "Files2")
actual = file_path.get_native_path_case(data)
self.assertEqual(os.path.join(trace_inputs_dir, "files2"), actual)
data = os.path.join(trace_inputs_dir, "Files2", "")
actual = file_path.get_native_path_case(data)
self.assertEqual(os.path.join(trace_inputs_dir, "files2", ""), actual)
data = os.path.join(trace_inputs_dir, "Files2", "Child1.py")
actual = file_path.get_native_path_case(data)
# TODO(maruel): Should be child1.py.
self.assertEqual(os.path.join(trace_inputs_dir, "files2", "Child1.py"), actual)
开发者ID:rzr,项目名称:Tizen_Crosswalk,代码行数:19,代码来源:file_path_test.py
示例10: test_native_case_alternate_datastream
def test_native_case_alternate_datastream(self):
# Create the file manually, since tempfile doesn't support ADS.
tempdir = unicode(tempfile.mkdtemp(prefix="trace_inputs"))
try:
tempdir = file_path.get_native_path_case(tempdir)
basename = "foo.txt"
filename = basename + ":Zone.Identifier"
filepath = os.path.join(tempdir, filename)
open(filepath, "w").close()
self.assertEqual(filepath, file_path.get_native_path_case(filepath))
data_suffix = ":$DATA"
self.assertEqual(filepath + data_suffix, file_path.get_native_path_case(filepath + data_suffix))
open(filepath + "$DATA", "w").close()
self.assertEqual(filepath + data_suffix, file_path.get_native_path_case(filepath + data_suffix))
# Ensure the ADS weren't created as separate file. You love NTFS, don't
# you?
self.assertEqual([basename], os.listdir(tempdir))
finally:
shutil.rmtree(tempdir)
开发者ID:rzr,项目名称:Tizen_Crosswalk,代码行数:20,代码来源:file_path_test.py
示例11: normalize_path_variables
def normalize_path_variables(cwd, path_variables, relative_base_dir):
"""Processes path variables as a special case and returns a copy of the dict.
For each 'path' variable: first normalizes it based on |cwd|, verifies it
exists then sets it as relative to relative_base_dir.
"""
logging.info("normalize_path_variables(%s, %s, %s)", cwd, path_variables, relative_base_dir)
assert isinstance(cwd, unicode), cwd
assert isinstance(relative_base_dir, unicode), relative_base_dir
relative_base_dir = file_path.get_native_path_case(relative_base_dir)
return dict((k, _normalize_path_variable(cwd, relative_base_dir, k, v)) for k, v in path_variables.iteritems())
开发者ID:qlb7707,项目名称:webrtc_src,代码行数:11,代码来源:isolate.py
示例12: _check_merge
def _check_merge(self, filename):
filepath = file_path.get_native_path_case(
os.path.join(unicode(ROOT_DIR), 'tests', 'isolate', filename))
expected = 'Updating %s\n' % isolate.safe_relpath(filepath, self.tempdir)
with open(filepath, 'rb') as f:
old_content = f.read()
out = self._execute('merge', filename, [], True) or ''
self.assertEqual(expected, out)
with open(filepath, 'rb') as f:
new_content = f.read()
self.assertEqual(old_content, new_content)
开发者ID:rzr,项目名称:Tizen_Crosswalk,代码行数:11,代码来源:isolate_smoke_test.py
示例13: test_variable_not_exist
def test_variable_not_exist(self):
isolate_file = os.path.join(
ROOT_DIR, 'tests', 'isolate', 'touch_root.isolate')
options = self._get_option(isolate_file)
options.path_variables['PRODUCT_DIR'] = os.path.join(u'tests', u'isolate')
native_cwd = file_path.get_native_path_case(unicode(self.cwd))
try:
isolate.load_complete_state(options, self.cwd, None, False)
self.fail()
except isolate.ExecutionError, e:
self.assertEqual(
'PRODUCT_DIR=%s is not a directory' %
os.path.join(native_cwd, 'tests', 'isolate'),
e.args[0])
开发者ID:bpsinc-native,项目名称:src_tools_swarming_client,代码行数:14,代码来源:isolate_test.py
示例14: _normalize_path_variable
def _normalize_path_variable(cwd, relative_base_dir, key, value):
"""Normalizes a path variable into a relative directory.
"""
# Variables could contain / or \ on windows. Always normalize to
# os.path.sep.
x = os.path.join(cwd, value.strip().replace("/", os.path.sep))
normalized = file_path.get_native_path_case(os.path.normpath(x))
if not os.path.isdir(normalized):
raise ExecutionError("%s=%s is not a directory" % (key, normalized))
# All variables are relative to the .isolate file.
normalized = os.path.relpath(normalized, relative_base_dir)
logging.debug("Translated variable %s from %s to %s", key, value, normalized)
return normalized
开发者ID:qlb7707,项目名称:webrtc_src,代码行数:14,代码来源:isolate.py
示例15: _test_missing_trailing_slash
def _test_missing_trailing_slash(self, mode):
try:
self._execute(mode, 'missing_trailing_slash.isolate', [])
self.fail()
except subprocess.CalledProcessError as e:
self.assertEqual('', e.output)
out = e.stderr
self._expect_no_result()
root = file_path.get_native_path_case(unicode(self.isolate_dir))
expected = (
'Input directory %s must have a trailing slash' %
os.path.join(root, 'tests', 'isolate', 'files1')
)
self.assertIn(expected, out)
开发者ID:Crawping,项目名称:chromium_extract,代码行数:14,代码来源:isolate_smoke_test.py
示例16: _test_non_existent
def _test_non_existent(self, mode):
try:
self._execute(mode, 'non_existent.isolate', [])
self.fail()
except subprocess.CalledProcessError as e:
self.assertEqual('', e.output)
out = e.stderr
self._expect_no_result()
root = file_path.get_native_path_case(unicode(self.isolate_dir))
expected = (
'Input file %s doesn\'t exist' %
os.path.join(root, 'tests', 'isolate', 'A_file_that_do_not_exist')
)
self.assertIn(expected, out)
开发者ID:Crawping,项目名称:chromium_extract,代码行数:14,代码来源:isolate_smoke_test.py
示例17: setUp
def setUp(self):
self.tempdir = None
self.trace_inputs_path = os.path.join(ROOT_DIR, 'trace_inputs.py')
# Wraps up all the differences between OSes here.
# - Windows doesn't track initial_cwd.
# - OSX replaces /usr/bin/python with /usr/bin/python2.7.
self.cwd = os.path.join(ROOT_DIR, u'tests')
self.initial_cwd = unicode(self.cwd)
self.expected_cwd = unicode(ROOT_DIR)
if sys.platform == 'win32':
# Not supported on Windows.
self.initial_cwd = None
self.expected_cwd = None
# There's 3 kinds of references to python, self.executable,
# self.real_executable and self.naked_executable. It depends how python was
# started.
self.executable = sys.executable
if sys.platform == 'darwin':
# /usr/bin/python is a thunk executable that decides which version of
# python gets executed.
suffix = '.'.join(map(str, sys.version_info[0:2]))
if os.access(self.executable + suffix, os.X_OK):
# So it'll look like /usr/bin/python2.7
self.executable += suffix
self.real_executable = file_path.get_native_path_case(
unicode(self.executable))
self.tempdir = file_path.get_native_path_case(
unicode(tempfile.mkdtemp(prefix='trace_smoke_test')))
self.log = os.path.join(self.tempdir, 'log')
# self.naked_executable will only be naked on Windows.
self.naked_executable = unicode(sys.executable)
if sys.platform == 'win32':
self.naked_executable = os.path.basename(sys.executable)
开发者ID:rzr,项目名称:Tizen_Crosswalk,代码行数:37,代码来源:trace_inputs_smoke_test.py
示例18: test_trace
def test_trace(self):
expected = self._gen_dict_full_gyp()
results = self._execute_trace(self.get_child_command(True))
actual = results.flatten()
self.assertTrue(actual['root'].pop('pid'))
self.assertTrue(actual['root']['children'][0].pop('pid'))
self.assertEqual(expected, actual)
files = [
u'tests/trace_inputs/child1.py'.replace('/', os.path.sep),
u'tests/trace_inputs/child2.py'.replace('/', os.path.sep),
u'tests/trace_inputs/files1/'.replace('/', os.path.sep),
u'tests/trace_inputs/test_file.txt'.replace('/', os.path.sep),
u'tests/trace_inputs_smoke_test.py'.replace('/', os.path.sep),
u'trace_inputs.py',
]
def blacklist(f):
return f.endswith(('.pyc', 'do_not_care.txt', '.git', '.svn'))
simplified = trace_inputs.extract_directories(
file_path.get_native_path_case(unicode(ROOT_DIR)),
results.files,
blacklist)
self.assertEqual(files, [f.path for f in simplified])
开发者ID:rzr,项目名称:Tizen_Crosswalk,代码行数:22,代码来源:trace_inputs_smoke_test.py
示例19: setUp
def setUp(self):
self.temp_file = None
self.initial_cwd = GOOGLETEST_DIR
if sys.platform == 'win32':
# Windows has no kernel mode concept of current working directory.
self.initial_cwd = None
# There's 2 kinds of references to python, self.executable,
# self.real_executable. It depends how python was started and on which OS.
self.executable = unicode(sys.executable)
if sys.platform == 'darwin':
# /usr/bin/python is a thunk executable that decides which version of
# python gets executed.
suffix = '.'.join(map(str, sys.version_info[0:2]))
if os.access(self.executable + suffix, os.X_OK):
# So it'll look like /usr/bin/python2.7
self.executable += suffix
self.real_executable = file_path.get_native_path_case(self.executable)
# Make sure there's no environment variable that could do side effects.
os.environ.pop('GTEST_SHARD_INDEX', '')
os.environ.pop('GTEST_TOTAL_SHARDS', '')
开发者ID:rzr,项目名称:Tizen_Crosswalk,代码行数:23,代码来源:trace_test_cases_smoke_test.py
示例20: test_native_case_end_with_dot_os_path_sep
def test_native_case_end_with_dot_os_path_sep(self):
path = file_path.get_native_path_case(ROOT_DIR + os.path.sep)
self.assertEqual(
file_path.get_native_path_case(path + '.' + os.path.sep),
path)
开发者ID:mellowdistrict,项目名称:luci-py,代码行数:5,代码来源:file_path_test.py
注:本文中的utils.file_path.get_native_path_case函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论