Ignore:
Timestamp:
03/25/12 17:37:16 (2 years ago)
Author:
xkolman2 <xkolman2@…>
Branches:
master
Children:
0b8050c2
Parents:
842e5a0
git-author:
xkolman2 <xkolman2@…> (03/25/12 17:37:16)
git-committer:
xkolman2 <xkolman2@…> (03/25/12 17:37:16)
Message:

remove libmagic dependency

git-svn-id: https://nlp.fi.muni.cz/svn/gps_navigace/trunk@711 0858a4d0-ffff-46e5-938e-62b5ecb34222

File:
1 edited

Legend:

Unmodified
Added
Removed
  • modules/modrana_utils.py

    rdd45fdf r3919add  
    44import threading 
    55import os 
    6 try: 
    7   import white_magic as magic 
    8   magicAvailable = True 
    9 except ImportError: 
    10   magicAvailable = False 
    11   print("WARNING : libmagic is not installed : WARNING") 
    12   print("this means that batch-downloaded tiles will not be checked,") 
    13   print("to remove HTML error pages from real tiles") 
    14   print("-> this can result in tiles not showing up after batch-download") 
    15   print("WARNING : : WARNING") 
    166from cStringIO import StringIO 
    177#import time 
     
    144134  """test if the string contains an image 
    145135  by reading its magic number""" 
    146 #  start = time.clock() 
    147   if magicAvailable: 
    148     # create a file like object 
    149     f = StringIO(s) 
    150     mime = str(magic.from_buffer(f.read(1024), mime=True)) 
    151     f.close() # cleanup 
    152     # get lists mime 
    153     mimeSplit = mime.split('/') 
    154     mime1 = mimeSplit[0] 
    155     # check if its an image 
    156  
    157   #  print("mime checked in %1.2f ms" % (1000 * (time.clock() - start))) 
    158     if mime1 == 'image': 
    159       return True 
    160     else: 
    161       return False 
    162   else: 
    163     # mime checking not available 
    164     # lets hope it really is a tile 
    165     return True 
     136 
     137  # create a file-like object 
     138  f = StringIO(s) 
     139  # read the header from it 
     140  h = f.read(32) 
     141  # cleanup 
     142  f.close() 
     143 
     144  # NOTE: magic numbers taken from imghdr source code 
     145 
     146  # as most tiles are PNGs, check for PNG first 
     147  if h[:8] == "\211PNG\r\n\032\n": 
     148    return True 
     149  elif h[6:10] in ('JFIF','Exif'): # JPEG in JFIF or Exif format 
     150    return True 
     151  elif h[:6] in ('GIF87a', 'GIF89a'): # GIF ('87 and '89 variants) 
     152    return True 
     153  elif h[:2] in ('MM', 'II', 'BM'): # tiff or BMP 
     154    return True 
     155  else: # probably not an image file 
     156    return False 
    166157 
    167158def createFolderPath(newPath): 
Note: See TracChangeset for help on using the changeset viewer.