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


Python File.type_from_extension方法代码示例

本文整理汇总了Python中file.File.type_from_extension方法的典型用法代码示例。如果您正苦于以下问题:Python File.type_from_extension方法的具体用法?Python File.type_from_extension怎么用?Python File.type_from_extension使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在file.File的用法示例。


在下文中一共展示了File.type_from_extension方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: create_file

# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import type_from_extension [as 别名]
 def create_file(self, filePath, fileName):
   file = File()
   file.name = fileName
   file.relPath = os.path.normpath(os.path.relpath(filePath, self.root))
   file.originalPath = os.path.normpath(os.path.join(filePath, fileName))
   t = os.path.getmtime(file.originalPath)
   file.mTime = datetime.datetime.fromtimestamp(t)
   t = os.path.getctime(file.originalPath)
   file.cTime = datetime.datetime.fromtimestamp(t)
   file.size = os.path.getsize(file.originalPath)
   _, fileExtension = os.path.splitext(file.originalPath)
   file.type = File.type_from_extension(fileExtension)
   if file.type == fileConstants.TYPE_OTHER or file.type == fileConstants.TYPE_UNKNOWN:
     return None
   self.update_exif_metadata(file)
   file.file_type = fileConstants.TYPE_FILESYSTEM
   return file
开发者ID:chuckhays,项目名称:smugsync,代码行数:19,代码来源:filesystem.py

示例2: fetch_album_images

# 需要导入模块: from file import File [as 别名]
# 或者: from file.File import type_from_extension [as 别名]
  def fetch_album_images(self, album):
    with self.max_threads_lock:
      album_last_updated_string = self.get_json_key(album, ['ImagesLastUpdated'])
      album_uri = self.get_json_key(album, ['Uris', 'AlbumImages', 'Uri'])
      # Check cache for album!images results, if not, request from network.
      cached_album_images = None
      with self.cache_lock:
        try:
          _, cached_album_images_json = self.check_cache(album_uri, album_last_updated_string)
          if cached_album_images_json is not None:
            cached_album_images = json.loads(cached_album_images_json)
        except Exception as e:
          print 'Exception checking cache for album: ' + album_uri + ' :: ' + e.message
      if cached_album_images is None:
        if album_uri is None:
          print 'Could not find album images Uri for album: ' + self.get_json_key(album, ['Name'])
          return
        cached_album_images_response = self.session.get(API_ORIGIN + album_uri, params = {'count':'1000000', '_expand' : 'ImageMetadata', '_expandmethod' : 'inline'}, headers={'Accept': 'application/json'})
        cached_album_images = {}
        try:
          cached_album_images = cached_album_images_response.json()
          with self.cache_lock:
            self.put_cache(album_uri, album_last_updated_string, album, cached_album_images_response.text)
        except Exception as e:
          print 'Exception getting album :: ' + album_uri + ' :: ' + e.message + ' :: (%d)' % cached_album_images_response.status_code
          print 'Full response:' + cached_album_images_response.text

      images_array = self.get_json_key(cached_album_images, ['Response', 'AlbumImage'])
      if images_array is None:
        print 'Could not get images array for album: ' + self.get_json_key(album, ['Name']) + 'uri:' + album_uri
        images_array = []

      for image in images_array:
        file = File()
        file.name = self.get_json_key(image, ['FileName'])
        is_video = self.get_json_key(image, ['IsVideo'])
        if is_video == True:
          #print 'Video: ' + file.name
          continue
        file.relativePath = os.path.normpath(self.get_json_key(album, ['UrlPath']))
        file.originalPath = os.path.normpath(os.path.join(file.relativePath, file.name))
        file.source = self.get_json_key(image, ['ArchivedUri'])
        file.thumbnail = self.get_json_key(image, ['ThumbnailUrl'])
        file.weburi = self.get_json_key(image, ['WebUri'])
        file.uri = self.get_json_key(image, ['Uri'])
        file.size = self.get_json_key(image, ['ArchivedSize'])
        file.md5 = self.get_json_key(image, ['ArchivedMD5'])
        _, file_extension = os.path.splitext(file.name)
        file.type = File.type_from_extension(file_extension)
        if file.type == fileConstants.TYPE_OTHER or file.type == fileConstants.TYPE_UNKNOWN:
          pass
        metadata = self.get_json_key(image, ['Uris', 'ImageMetadata', 'ImageMetadata'])
        file.exif_width = self.get_json_key(image, ['OriginalWidth'])
        file.exif_height = self.get_json_key(image, ['OriginalHeight'])
        file.file_type = fileConstants.TYPE_SMUGMUG
        if metadata is not None:
          file.metadata = metadata
          file.exif_aperture = self.get_json_key(metadata, ['Aperture'])
          file.exif_date = self.get_json_key(metadata, ['DateTime']) or self.get_json_key(metadata, ['DateTimeCreated']) or self.get_json_key(metadata, ['DateTimeOriginal'])
          file.exif_date_parsed = file.convert_time_string(file.exif_date)
          file.exif_iso = self.get_json_key(metadata, ['ISO'])
          # fl is a string, strip 'mm', convert to a double
          try:
            file.exif_focal_length = float(self.get_json_key(metadata, ['FocalLength']).replace('mm', ''))
          except:
            pass
          file.exif_exposure = self.get_json_key(metadata, ['Exposure'])
          file.exif_camera = self.get_json_key(metadata, ['Camera']) or self.get_json_key(metadata, ['Model'])

        with self.output_lock:
          self.add_file_to_hash(file, self.images)
      self.increment_threadcount()
开发者ID:chuckhays,项目名称:smugsync,代码行数:74,代码来源:smugmug.py


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