当前位置: 首页>>代码示例>>Python>>正文


Python Location.get_location_for_url方法代码示例

本文整理汇总了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)
开发者ID:crawley,项目名称:mytardis-app-atom,代码行数:36,代码来源:atom_ingest.py

示例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)
开发者ID:guillaumeprevost,项目名称:mytardis,代码行数:11,代码来源:generate.py

示例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)
开发者ID:crawley,项目名称:mytardis,代码行数:24,代码来源:test_download.py


注:本文中的tardis.tardis_portal.models.Location.get_location_for_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。