本文整理匯總了Python中os.path.endswith方法的典型用法代碼示例。如果您正苦於以下問題:Python path.endswith方法的具體用法?Python path.endswith怎麽用?Python path.endswith使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類os.path
的用法示例。
在下文中一共展示了path.endswith方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run_command
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def run_command(quteproc, server, tmpdir, command):
"""Run a qutebrowser command.
The suffix "with count ..." can be used to pass a count to the command.
"""
if 'with count' in command:
command, count = command.split(' with count ')
count = int(count)
else:
count = None
invalid_tag = ' (invalid command)'
if command.endswith(invalid_tag):
command = command[:-len(invalid_tag)]
invalid = True
else:
invalid = False
command = command.replace('(port)', str(server.port))
command = command.replace('(testdata)', testutils.abs_datapath())
command = command.replace('(tmpdir)', str(tmpdir))
command = command.replace('(dirsep)', os.sep)
command = command.replace('(echo-exe)', _get_echo_exe_path())
quteproc.send_cmd(command, count=count, invalid=invalid)
示例2: uninstallation_paths
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def uninstallation_paths(dist):
"""
Yield all the uninstallation paths for dist based on RECORD-without-.pyc
Yield paths to all the files in RECORD. For each .py file in RECORD, add
the .pyc in the same directory.
UninstallPathSet.add() takes care of the __pycache__ .pyc.
"""
from pip.utils import FakeFile # circular import
r = csv.reader(FakeFile(dist.get_metadata_lines('RECORD')))
for row in r:
path = os.path.join(dist.location, row[0])
yield path
if path.endswith('.py'):
dn, fn = os.path.split(path)
base = fn[:-3]
path = os.path.join(dn, base + '.pyc')
yield path
示例3: __processRemovedDir
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def __processRemovedDir(self, path, dirsToBeRemoved, itemsToReport):
"""called for a disappeared dir in the project tree"""
# it should remove the dirs recursively from the fs snapshot
# and care of items to report
dirsToBeRemoved.append(path)
itemsToReport.append("-" + path)
oldSet = self.__fsSnapshot[path]
for item in oldSet:
if item.endswith(os.path.sep):
# Nested dir
self.__processRemovedDir(path + item, dirsToBeRemoved,
itemsToReport)
else:
# a file
itemsToReport.append("-" + path + item)
del self.__fsSnapshot[path]
示例4: checkOutsidePathChange
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def checkOutsidePathChange(self, path):
"""Checks outside changes for a certain path"""
if path.endswith(os.path.sep):
return
for index in range(self.count()):
widget = self.widget(index)
fileName = widget.getFileName()
if fileName == path:
self._updateIconAndTooltip(index)
currentWidget = self.currentWidget()
if currentWidget == widget:
if widget.doesFileExist():
if not widget.getReloadDialogShown():
widget.showOutsideChangesBar(
self.__countDiskModifiedUnchanged() > 1)
break
示例5: __init__
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def __init__(self, host, path, mode, dryrun):
""" Initialize.
:arg host: ssh host.
"""
# For simplicity, only allow absolute paths
# Don't lose a trailing slash -- it's significant
path = "/" + os.path.normpath(path) + ("/" if path.endswith("/") else "")
super(SSHStore, self).__init__(host, path, mode, dryrun)
self.host = host
self._client = _Client(host, 'r' if dryrun else mode, path)
self.isRemote = True
self.toArg = _Obj2Arg()
self.toObj = _Dict2Obj(self)
示例6: run
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def run(self):
""" Run the server. Returns with system error code. """
normalized = os.path.normpath(self.path) + ("/" if self.path.endswith("/") else "")
if self.path != normalized:
sys.stderr.write("Please use full path '%s'" % (normalized,))
return -1
self.butterStore = ButterStore.ButterStore(None, self.path, self.mode, dryrun=False)
# self.butterStore.ignoreExtraVolumes = True
self.toObj = _Arg2Obj(self.butterStore)
self.toDict = _Obj2Dict()
self.running = True
with self.butterStore:
with self:
while self.running:
self._processCommand()
return 0
示例7: find_address_file
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def find_address_file(self):
"""
Finds the OMXPlayer DBus connection
Assumes there is an alive OMXPlayer process.
:return:
"""
possible_address_files = []
while not possible_address_files:
# filter is used here as glob doesn't support regexp :(
isnt_pid_file = lambda path: not path.endswith('.pid')
possible_address_files = list(filter(isnt_pid_file,
glob('/tmp/omxplayerdbus.*')))
possible_address_files.sort(key=lambda path: os.path.getmtime(path))
time.sleep(0.05)
self.path = possible_address_files[-1]
示例8: test_just_my_code_debug_option_deprecated
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def test_just_my_code_debug_option_deprecated(case_setup, debug_stdlib, debugger_runner_simple):
from _pydev_bundle import pydev_log
with case_setup.test_file('_debugger_case_debug_options.py') as writer:
json_facade = JsonFacade(writer)
json_facade.write_launch(
redirectOutput=True, # Always redirect the output regardless of other values.
debugStdLib=debug_stdlib
)
json_facade.write_make_initial_run()
output = json_facade.wait_for_json_message(
OutputEvent, lambda msg: msg.body.category == 'stdout' and msg.body.output.startswith('{')and msg.body.output.endswith('}'))
settings = json.loads(output.body.output)
# Note: the internal attribute is just_my_code.
assert settings['just_my_code'] == (not debug_stdlib)
json_facade.wait_for_terminated()
contents = []
for f in pydev_log.list_log_files(debugger_runner_simple.pydevd_debug_file):
if os.path.exists(f):
with open(f, 'r') as stream:
contents.append(stream.read())
writer.finished_ok = True
示例9: read_test_set
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def read_test_set(self, path):
data = defaultdict(lambda: [])
if path.endswith('.csv'):
with open(path, 'r') as csvfile:
reader = csv.reader(csvfile)
head = True
for row in reader:
if len(row) < 3:
continue
if not head:
target_word = row[1]
word = row[2]
is_synonym = row[3]
data[target_word].append([word, is_synonym])
head = False
else:
with open(path) as f:
for line in f:
_, target_word, word, is_synonym = line.strip().split()
data[target_word].append([word, is_synonym])
return dict(data)
示例10: read_test_set
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def read_test_set(self, path):
test = defaultdict(lambda: [])
if path.endswith('.csv'):
with open(path, 'r') as csvfile:
reader = csv.reader(csvfile)
head = True
for row in reader:
if len(row) < 2:
continue
if not head:
category = row[1]
word = row[2]
test[category].append(word)
head = False
else:
with open(path) as f:
for line in f:
id, category, word = line.strip().split()
test[category].append(word)
return dict(test)
示例11: read_test_set
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def read_test_set(self, path):
test = defaultdict(lambda: [])
if path.endswith('.csv'):
with open(path, 'r') as csvfile:
reader = csv.reader(csvfile)
head = True
for row in reader:
if len(row) < 3:
continue
if not head:
category = row[1]
word = row[2]
is_outlier = row[3]
test[category].append({'word': word, 'is_outlier': is_outlier})
head = False
else:
with open(path) as f:
for line in f:
_, category, word, is_outlier = line.strip().split()
test[category].append({'word': word, 'is_outlier': is_outlier})
return dict(test)
示例12: _get_config
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def _get_config(path):
if path.endswith('/'):
path = path[:-1]
handler_function = 'handler'
if os.path.isfile(path):
file_name = os.path.basename(path)
name = file_name.rsplit('.',1)[0]
code_uri = os.path.dirname(path)
handler_file = name
else:
name = os.path.basename(path)
code_uri = path
for handler_file in [name, 'index', 'handler']:
if os.path.isfile(os.path.join(path, '{}.py'.format(handler_file))):
break
else:
raise RuntimeError('No handler file found!')
handler = '{}.{}'.format(handler_file, handler_function)
return _config(name, code_uri, handler)
示例13: test_attributes
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def test_attributes():
import datetime
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(uuid=["D79B8D77-BFFC-460B-9312-034F2877D35B"])
assert len(photos) == 1
p = photos[0]
assert p.keywords == ["Kids"]
assert p.original_filename == "Pumkins2.jpg"
assert p.filename == "D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg"
assert p.date == datetime.datetime(
2018, 9, 28, 16, 7, 7, 0, datetime.timezone(datetime.timedelta(seconds=-14400))
)
assert p.description == "Girl holding pumpkin"
assert p.title == "I found one!"
assert sorted(p.albums) == ["Multi Keyword", "Pumpkin Farm", "Test Album"]
assert p.persons == ["Katie"]
assert p.path.endswith(
"tests/Test-10.15.1.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg"
)
assert p.ismissing == False
示例14: test_attributes
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def test_attributes():
import datetime
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(uuid=["15uNd7%8RguTEgNPKHfTWw"])
assert len(photos) == 1
p = photos[0]
assert p.keywords == ["Kids"]
assert p.original_filename == "Pumkins2.jpg"
assert p.filename == "Pumkins2.jpg"
assert p.date == datetime.datetime(
2018, 9, 28, 16, 7, 7, 0, datetime.timezone(datetime.timedelta(seconds=-14400))
)
assert p.description == "Girl holding pumpkin"
assert p.title == "I found one!"
assert sorted(p.albums) == sorted(
["Pumpkin Farm", "AlbumInFolder", "Test Album (1)"]
)
assert p.persons == ["Katie"]
assert p.path.endswith(
"/tests/Test-10.14.6.photoslibrary/Masters/2019/07/27/20190727-131650/Pumkins2.jpg"
)
assert p.ismissing == False
示例15: test_attributes
# 需要導入模塊: from os import path [as 別名]
# 或者: from os.path import endswith [as 別名]
def test_attributes():
import datetime
import osxphotos
photosdb = osxphotos.PhotosDB(dbfile=PHOTOS_DB)
photos = photosdb.photos(uuid=["D79B8D77-BFFC-460B-9312-034F2877D35B"])
assert len(photos) == 1
p = photos[0]
assert p.keywords == ["Kids"]
assert p.original_filename == "Pumkins2.jpg"
assert p.filename == "D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg"
assert p.date == datetime.datetime(
2018, 9, 28, 16, 7, 7, 0, datetime.timezone(datetime.timedelta(seconds=-14400))
)
assert p.description == "Girl holding pumpkin"
assert p.title == "I found one!"
assert sorted(p.albums) == ["Pumpkin Farm", "Test Album"]
assert p.persons == ["Katie"]
assert p.path.endswith(
"tests/Test-10.15.4.photoslibrary/originals/D/D79B8D77-BFFC-460B-9312-034F2877D35B.jpeg"
)
assert p.ismissing == False