예제 #1
0
    def _extract(self, table, rel_path, metadata):

        from ambry.util import temp_file_name
        from ambry.util.flo import copy_file_or_flo
        import shutil
        import os

        rel_path = self.mangle_name(rel_path)

        shapefile_dir = temp_file_name()

        self._extract_shapes(shapefile_dir, table)

        zf = temp_file_name()

        self.zip_dir(table, shapefile_dir, zf)

        copy_file_or_flo(
            zf,
            self.cache.put_stream(
                rel_path,
                metadata=metadata))

        shutil.rmtree(shapefile_dir)
        os.remove(zf)

        return self.cache.path(rel_path)
예제 #2
0
파일: extractors.py 프로젝트: Gudinya/ambry
    def _extract(self, table, rel_path, metadata):

        from ambry.util import temp_file_name
        from ambry.util.flo import copy_file_or_flo
        import shutil
        import os

        rel_path = self.mangle_name(rel_path)

        shapefile_dir = temp_file_name()

        self._extract_shapes(shapefile_dir, table)

        zf = temp_file_name()

        self.zip_dir(table, shapefile_dir, zf)

        copy_file_or_flo(
            zf,
            self.cache.put_stream(
                rel_path,
                metadata=metadata))

        shutil.rmtree(shapefile_dir)
        os.remove(zf)

        return self.cache.path(rel_path)
예제 #3
0
파일: test_library.py 프로젝트: kball/ambry
    def new_db():
        from ambry.util import temp_file_name
        from ambry.library.database import LibraryDb
        db_file = temp_file_name()+".db"

        db = LibraryDb(driver='sqlite', dbname=db_file)

        return db_file, db
예제 #4
0
    def new_db():
        from ambry.util import temp_file_name
        from ambry.library.database import LibraryDb
        db_file = temp_file_name() + ".db"

        db = LibraryDb(driver='sqlite', dbname=db_file)

        return db_file, db
예제 #5
0
    def make_test_file(self):
        from ambry.util import temp_file_name

        fn = temp_file_name()

        with open(fn, 'wb') as f:
            for i in range(1000):
                f.write("{:03d}:".format(i))

        return fn
예제 #6
0
    def make_test_file(self):
        from ambry.util import temp_file_name

        fn = temp_file_name()

        with open(fn, "wb") as f:
            for i in range(1000):
                f.write("{:03d}:".format(i))

        return fn
예제 #7
0
파일: extractors.py 프로젝트: Gudinya/ambry
    def _extract(self, table, rel_path, metadata):
        from ambry.util import temp_file_name
        from ambry.util.flo import copy_file_or_flo
        import os

        rel_path = self.mangle_name(rel_path)

        tf = temp_file_name() + '.geojson'

        self._extract_shapes(tf, table)

        copy_file_or_flo(
            tf,
            self.cache.put_stream(
                rel_path,
                metadata=metadata))

        os.remove(tf)

        return self.cache.path(rel_path)
예제 #8
0
    def _extract(self, table, rel_path, metadata):
        from ambry.util import temp_file_name
        from ambry.util.flo import copy_file_or_flo
        import os

        rel_path = self.mangle_name(rel_path)

        tf = temp_file_name()

        self._extract_shapes(tf, table)

        copy_file_or_flo(
            tf,
            self.cache.put_stream(
                rel_path,
                metadata=metadata))

        os.remove(tf)

        return self.cache.path(rel_path)
예제 #9
0
    def test_compression(self):
        from ambry.run import get_runconfig
        from ambry.cache import new_cache
        from ambry.util import temp_file_name, md5_for_file, copy_file_or_flo

        rc = get_runconfig((os.path.join(self.bundle_dir, "test-run-config.yaml"), RunConfig.USER_CONFIG))

        comp_cache = new_cache(rc.filesystem("compressioncache"))

        test_file_name = "test_file"

        fn = temp_file_name()
        print "orig file ", fn
        with open(fn, "wb") as f:
            for i in range(1000):
                f.write("{:03d}:".format(i))

        cf = comp_cache.put(fn, test_file_name)

        with open(cf) as stream:
            from ambry.util.sgzip import GzipFile

            stream = GzipFile(stream)

            uncomp_cache = new_cache(rc.filesystem("fscache"))

            uncomp_stream = uncomp_cache.put_stream("decomp")

            copy_file_or_flo(stream, uncomp_stream)

        uncomp_stream.close()

        dcf = uncomp_cache.get("decomp")

        self.assertEquals(md5_for_file(fn), md5_for_file(dcf))

        os.remove(fn)
예제 #10
0
 def new_db():
     db_file = util.temp_file_name() + '.db'
     db = LibraryDb(driver='sqlite', dbname=db_file)
     return db_file, db
예제 #11
0
파일: test_library.py 프로젝트: kball/ambry
    def test_simple_install(self):

        from ambry.util import temp_file_name
        import pprint
        import os
        
        l = self.get_library()
        print "Library: ", l.database.dsn
     
        r = l.put(self.bundle) #@UnusedVariable

        r = l.get(self.bundle.identity.sname)
        self.assertTrue(r is not False)
        self.assertEquals(self.bundle.identity.sname, r.identity.sname)

        r = l.get('dibberish')
        self.assertFalse(r)

        for partition in self.bundle.partitions:
            print "Install and check: ", partition.identity.vname
            r = l.put(partition)

            # Get the partition with a name
            r = l.get(partition.identity.sname)
            self.assertTrue(r is not False)
            self.assertEquals(partition.identity.sname, r.partition.identity.sname)
            self.assertEquals(self.bundle.identity.sname, r.identity.sname)
            
            # Get the partition with an id
            r = l.get(partition.identity.id_)

            self.assertTrue(bool(r))
            self.assertEquals(partition.identity.sname, r.partition.identity.sname)
            self.assertEquals(self.bundle.identity.sname, r.identity.sname)

        self.assertTrue(l.database.needs_dump())

        backup_file = temp_file_name()+".db"
        
        l.database.dump(backup_file)
        
        l.database.close()
        os.remove(l.database.dbname)
        l.database.create()

        r = l.get(self.bundle.identity.sname)
    
        self.assertTrue(not r)
        
        l.database.restore(backup_file)
        
        r = l.get(self.bundle.identity.sname)
        self.assertTrue(r is not False)
        self.assertEquals(self.bundle.identity.sname, r.identity.sname)

        os.remove(backup_file)

        # An extra change so the following tests work
        l.put(self.bundle)
        
        self.assertFalse(l.database.needs_dump())

        import time; time.sleep(10)

        self.assertTrue(l.database.needs_dump())
예제 #12
0
파일: extractors.py 프로젝트: Gudinya/ambry
 def temp_dest(self):
     from ambry.util import temp_file_name
     return temp_file_name()
예제 #13
0
 def temp_dest(self):
     from ambry.util import temp_file_name
     return temp_file_name()