Example #1
0
def tileSet_from_yaml(mapName):
    """ Import a TileSet and related models from a YAML file.
    Example:
    >>> ts = tileSet_from_yaml('stlhom')
    >>> ts.name
    'stlhom'
    >>> import models
    >>> t = models.TileSet.get_by_key_name('ts:stlhom')
    >>> t.name
    'stlhom'
    >>> t.overview
    'o:stlhom'
    >>> t.ids
    'tsids:stlhom'
    """
    from dynTileMapper.dtm_wsgi.models import TileSet,Overview,TileSet_IDS
    ymlfile = os.path.join(MAP_FILE_HOME,mapName,'dtm.yaml')
    m = yaml.load(open(ymlfile).read())
    overview = Overview(key_name='o:'+m.name)
    overview.typ = m.overview_typ
    overview.dat = base64.b64decode(m.overview_dat)
    overview.width = m.overview_width
    overview.height = m.overview_height
    overview_key = overview.put()
    tsids = TileSet_IDS(key_name='tsids:'+m.name)
    tsids.ids = zlib.compress(m.ids)
    tsids_key = tsids.put()
    tile_set = TileSet(key_name='ts:'+m.name)
    tile_set.public = True
    tile_set.name = m.name
    tile_set.notes = m.notes
    tile_set.source = m.source
    tile_set.idName = m.variableNames[m.idVariable]
    tile_set.idlen = len(m.ids.split(','))
    tile_set.cLng = m.cLng
    tile_set.cLat = m.cLat
    tile_set.minx = m.minx
    tile_set.miny = m.miny
    tile_set.maxx = m.maxx
    tile_set.maxy = m.maxy
    tile_set.GMERC_BOUNDS = m.gmerc_bounds
    tile_set.maxZoom = 20
    tile_set.overview = overview_key
    tile_set.ids = tsids_key
    tile_set.put()
    return tile_set
Example #2
0
    def run(self):
        f = open(self.mapConfig,'r')
        m = yaml.load(f)
        if isinstance(m,M_DyMaps2):
            remote_api_stub.ConfigureRemoteDatastore(None,DTM_REMOTE_API_URL,self._auth,self.server)
            app_id = os.getenv('APPLICATION_ID')
            os.putenv('AUTH_DOMAIN', 'gmail.com')
            if self.checkMap:
                self.checkOverview = True
                self.checkIDS = True
            #PUT OVERVIEW
            if self.checkOverview:
                overview = Overview(key_name=OVERVIEW_PREFIX+m.name)
                overview.typ = m.overview_typ
                overview.dat = base64.b64decode(m.overview_dat)
                overview.width = m.overview_width
                overview.height = m.overview_height
                overview_key = overview.put()
                print overview_key
            #PUT IDS
            if self.checkIDS:
                ids = TileSet_IDS(key_name=TILESET_IDS_PREFIX+m.name)
                ids.ids = zlib.compress(m.ids)
                ids_key = ids.put()
                print ids_key
            #PUT TILESET
            if self.checkMap:
                tile_set = TileSet(key_name=TILE_SET_PREFIX+m.name)
                tile_set.owner = users.User(email=self.user,_auth_domain=self.user.split('@')[1])
                tile_set.name = m.name
                tile_set.notes = m.notes
                tile_set.source = m.source
                tile_set.idName = m.variableNames[m.idVariable]
                tile_set.idlen = len(m.ids.split(','))
                tile_set.cLng = m.cLng
                tile_set.cLat = m.cLat
                tile_set.minx = m.minx
                tile_set.miny = m.miny
                tile_set.maxx = m.maxx
                tile_set.maxy = m.maxy
                tile_set.GMERC_BOUNDS = m.gmerc_bounds
                tile_set.maxZoom = max(m.scales)
                if overview_key:
                    tile_set.overview = overview_key
                if ids_key:
                    tile_set.ids = ids_key
                print tile_set.put()

            #PUT TILES
            if self.checkTiles:
                bulk_args = {}
                bulk_args['url'] = 'http://%s%s'%(self.server,DTM_REMOTE_API_URL)
                bulk_args['filename'] = m.cacheFile
                fname = os.tempnam()
                o = open(fname,'w')
                o.write(Loader.LOADER_FILE)
                o.close()
                bulk_args['config_file'] = fname
                #bulk_args['config_file'] = "../webApp/Loader.py"
                bulk_args['kind'] = 'Tile'
                bulk_args['loader_opts'] = m.name

                #begin google defaults
                bulk_args['batch_size'] = bulkloader.DEFAULT_BATCH_SIZE
                bulk_args['num_threads'] = bulkloader.DEFAULT_THREAD_COUNT
                bulk_args['bandwidth_limit'] = bulkloader.DEFAULT_BANDWIDTH_LIMIT
                bulk_args['rps_limit'] = bulkloader.DEFAULT_RPS_LIMIT
                bulk_args['http_limit'] = bulkloader.DEFAULT_REQUEST_LIMIT
                bulk_args['db_filename'] = None
                bulk_args['app_id'] = app_id
                bulk_args['auth_domain'] = 'gmail.com'
                bulk_args['has_header'] = True
                bulk_args['result_db_filename'] = None
                bulk_args['download'] = False
                bulk_args['exporter_opts'] = None
                bulk_args['debug'] = False
                bulk_args['log_file'] = None
                bulk_args['email'] = self.user
                bulk_args['passin'] = True
                bulk_args['map'] = None #added in SDK 1.2.4
                bulk_args['mapper_opts'] = None #added in SDK 1.2.4
                #end google defaults
                
                stdin = sys.stdin
                sys.stdin = StringIO.StringIO(self.passwd)
                sys.stdin.fileno = stdin.fileno
                bulkloader.Run(bulk_args)
                sys.stidin = stdin
                os.remove(fname)
        else:
            raise TypeError,'Invald Model File'