Mercurial > dive4elements > river
view flys-backend/contrib/shpimporter/utils.py @ 4916:2cec81e697e8 dc-km-filter
[branch dc-km-filter] Builder: Let dc:variables always be global.
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 30 Jan 2013 15:52:50 +0100 |
parents | 1f6e544f7a7f |
children | c0a58558b817 |
line wrap: on
line source
import os import sys from shpimporter import DEBUG, INFO, ERROR SHP='.shp' def findShapefiles(path): shapes = [] for root, dirs, files in os.walk(path): if len(files) == 0: continue DEBUG("Processing directory '%s' with %i files " % (root, len(files))) for f in files: idx = f.find(SHP) if (idx+len(SHP)) == len(f): shapes.append((f.replace(SHP, ''), root + "/" + f)) return shapes def getUTF8Path(path): """ Tries to convert path to utf-8 by first checking the filesystemencoding and trying the default windows encoding afterwards. Returns a valid UTF-8 encoded unicode object or throws a UnicodeDecodeError """ try: return unicode.encode(unicode(path, sys.getfilesystemencoding()), "UTF-8") except UnicodeDecodeError: # Probably European Windows names so lets try again return unicode.encode(unicode(path, "cp1252"), "UTF-8")