本文整理汇总了Python中tardis.tardis_portal.models.Location.get_location_for_url方法的典型用法代码示例。如果您正苦于以下问题:Python Location.get_location_for_url方法的具体用法?Python Location.get_location_for_url怎么用?Python Location.get_location_for_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tardis.tardis_portal.models.Location
的用法示例。
在下文中一共展示了Location.get_location_for_url方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: process_enclosure
# 需要导入模块: from tardis.tardis_portal.models import Location [as 别名]
# 或者: from tardis.tardis_portal.models.Location import get_location_for_url [as 别名]
def process_enclosure(self, dataset, enclosure):
filename = getattr(enclosure, 'title', basename(enclosure.href))
datafile = Dataset_File(filename=filename, dataset=dataset)
try:
datafile.mimetype = enclosure.mime
except AttributeError:
pass
try:
datafile.size = enclosure.length
except AttributeError:
pass
try:
hash = enclosure.hash
# Split on white space, then ':' to get tuples to feed into dict
hashdict = dict([s.partition(':')[::2] for s in hash.split()])
# Set SHA-512 sum
datafile.sha512sum = hashdict['sha-512']
except AttributeError:
pass
datafile.save()
url = enclosure.href
# This means we will allow the atom feed to feed us any enclosure
# URL that matches a registered location. Maybe we should restrict
# this to a specific location.
location = Location.get_location_for_url(url)
if not location:
logger.error('Rejected ingestion for unknown location %s' % url)
return
replica = Replica(datafile=datafile, url=url,
location=location)
replica.protocol = enclosure.href.partition('://')[0]
replica.save()
self.make_local_copy(replica)
示例2: _infer_location
# 需要导入模块: from tardis.tardis_portal.models import Location [as 别名]
# 或者: from tardis.tardis_portal.models.Location import get_location_for_url [as 别名]
def _infer_location(path):
if urlparse.urlparse(path).scheme == '':
loc = Location.get_default_location()
else:
loc = Location.get_location_for_url(path)
if loc:
return loc
else:
raise Exception('Cannot infer a location for %s' % path)
示例3: _build_datafile
# 需要导入模块: from tardis.tardis_portal.models import Location [as 别名]
# 或者: from tardis.tardis_portal.models.Location import get_location_for_url [as 别名]
def _build_datafile(self, testfile, filename, dataset, url,
protocol='', checksum=None, size=None, mimetype=''):
filesize, sha512sum = get_size_and_sha512sum(testfile)
datafile = Dataset_File(dataset=dataset, filename=filename,
mimetype=mimetype,
size=str(size if size != None else filesize),
sha512sum=(checksum if checksum else sha512sum))
datafile.save()
if urlparse.urlparse(url).scheme == '':
location = Location.get_location('local')
else:
location = Location.get_location_for_url(url)
if not location:
location = Location.load_location({
'name': filename, 'url': urlparse.urljoin(url, '.'),
'type': 'external',
'priority': 10, 'transfer_provider': 'local'})
replica = Replica(datafile=datafile, protocol=protocol, url=url,
location=location)
replica.verify()
replica.save()
return Dataset_File.objects.get(pk=datafile.pk)