Commit d7cea652 authored by Denis Laxalde's avatar Denis Laxalde
Browse files

Make code-base flake8-clean

parent 16e2735300f7
# pylint: disable=W0622
"""cubicweb-postgis application packaging information"""
from os import listdir as _listdir
from os.path import join, isdir
from glob import glob
modname = 'postgis'
distname = 'cubicweb-postgis'
......@@ -13,9 +18,10 @@ author_email = 'contact@logilab.fr'
description = 'Test for postgis'
web = 'http://www.cubicweb.org/project/%s' % distname
__depends__ = {'cubicweb': '>= 3.22.0',
'cwtags': '>= 1.1.0',
}
__depends__ = {
'cubicweb': '>= 3.22.0',
'cwtags': '>= 1.1.0',
}
__recommends__ = {}
classifiers = [
......@@ -28,26 +34,24 @@ classifiers = [
'Topic :: Database',
]
from os import listdir as _listdir
from os.path import join, isdir
from glob import glob
THIS_CUBE_DIR = join('share', 'cubicweb', 'cubes', modname)
def listdir(dirpath):
return [join(dirpath, fname) for fname in _listdir(dirpath)
if fname[0] != '.' and not fname.endswith('.pyc')
and not fname.endswith('~')
and not isdir(join(dirpath, fname))]
data_files = [
# common files
[THIS_CUBE_DIR, [fname for fname in glob('*.py') if fname != 'setup.py']],
]
]
# check for possible extended cube layout
for dname in ('entities', 'views', 'sobjects', 'hooks', 'schema', 'data', 'wdoc', 'i18n', 'migration'):
for dname in ('entities', 'views', 'sobjects', 'hooks', 'schema', 'data',
'wdoc', 'i18n', 'migration'):
if isdir(dname):
data_files.append([join(THIS_CUBE_DIR, dname), listdir(dname)])
# Note: here, you'll need to add subdirectories if you want
# them to be included in the debian package
......@@ -17,11 +17,13 @@
"""cubicweb-postgis schema"""
from yams.buildobjs import make_type
Geometry = make_type('Geometry')
# Example of use:
# Geometry(geom_type='POINT', srid=-1, coord_dimension=2)
Geography = make_type('Geography')
# Example of use:
# Geography(geom_type='POINT', coord_dimension=2)
......@@ -28,12 +28,14 @@ def pg_geometry_sqltype(rdef):
assert rdef.srid
return 'geometry(%s, %s)' % (target_geom_type, rdef.srid)
def pg_geography_sqltype(rdef):
"""Return a PostgreSQL column type corresponding to rdef's geom_type and srid
"""
srid = rdef.srid or 4326
return 'geography(%s, %s)' % (rdef.geom_type, srid)
# Add the datatype to the helper mapping
pghelper = get_db_helper('postgres')
pghelper.TYPE_MAPPING['Geometry'] = pg_geometry_sqltype
......@@ -43,6 +45,7 @@ sqlitehelper = get_db_helper('sqlite')
sqlitehelper.TYPE_MAPPING['Geometry'] = 'text'
sqlitehelper.TYPE_MAPPING['Geography'] = 'text'
# Add a converter for Geometry
def convert_geom(x):
if isinstance(x, SQLExpression):
......@@ -53,10 +56,12 @@ def convert_geom(x):
# We just give the Geometry
return SQLExpression('ST_GeomFromText(%(geo)s, %(srid)s)', geo=x, srid=-1)
def convert_geog(x):
# takes only a Geometry type, assumes GPS srid
return SQLExpression('ST_GeogFromText(%(geo)s)', geo=x)
# Add the converter function to the known SQL_CONVERTERS
pghelper.TYPE_CONVERTERS['Geometry'] = convert_geom
pghelper.TYPE_CONVERTERS['Geography'] = convert_geog
......@@ -66,7 +71,6 @@ sqlitehelper.TYPE_CONVERTERS['Geometry'] = str
sqlitehelper.TYPE_CONVERTERS['Geography'] = str
class ST_EQUALS(FunctionDescr):
minargs = 2
maxargs = 2
......@@ -80,6 +84,7 @@ class ST_INTERSECTS(FunctionDescr):
supported_backends = ('postgres',)
rtype = 'Bool'
class ST_INTERSECTION(FunctionDescr):
minargs = 2
maxargs = 2
......@@ -93,12 +98,14 @@ class ST_OVERLAPS(FunctionDescr):
supported_backends = ('postgres',)
rtype = 'Bool'
class ST_CROSSES(FunctionDescr):
minargs = 2
maxargs = 2
supported_backends = ('postgres',)
rtype = 'Bool'
class ST_TOUCHES(FunctionDescr):
minargs = 2
maxargs = 2
......@@ -210,42 +217,49 @@ class ST_GEOMFROMTEXT(FunctionDescr):
supported_backends = ('postgres',)
rtype = 'Geometry'
class ST_GEOGFROMTEXT(FunctionDescr):
minargs = 1
maxargs = 1
supported_backends = ('postgres',)
rtype = 'Geography'
class ST_COVERS(FunctionDescr):
minargs = 1
maxargs = 2
supported_backends = ('postgres',)
rtype = 'Bool'
class GEOMETRY(FunctionDescr):
minargs = 1
maxargs = 1
supported_backends = ('postgres',)
rtype = 'Geometry'
class ST_UNION(FunctionDescr):
aggregat = True
minargs = 1
supported_backends = ('postgres',)
rtype = 'Geometry'
class ST_COLLECT(FunctionDescr):
aggregat = True
minargs = 1
supported_backends = ('postgres',)
rtype = 'Geometry'
class ST_CONVEXHULL(FunctionDescr):
minargs = 1
maxargs = 1
supported_backends = ('postgres',)
rtype = 'Geometry'
class ST_CONCAVEHULL(FunctionDescr):
minargs = 1
maxargs = 1
......
......@@ -18,6 +18,7 @@
from yams.buildobjs import EntityType, String
from cubes.postgis.schema import Geometry, Geography
class City(EntityType):
name = String(required=True, maxsize=100)
center_4326 = Geometry(srid=4326, geom_type='POINT')
......
......@@ -21,9 +21,11 @@ from cubicweb.devtools import testlib
from cubicweb.devtools import (startpgcluster, stoppgcluster,
PostgresApptestConfiguration)
def setUpModule():
startpgcluster(__file__)
def tearDownModule():
stoppgcluster(__file__)
......@@ -53,9 +55,10 @@ class PostgisTC(testlib.CubicWebTC):
class PostgisSQLiteFakeTC(testlib.CubicWebTC):
def test_schema(self):
sqlqs = "select sql from sqlite_master where type = 'table' and name = 'cw_City'"
with self.admin_access.repo_cnx() as cnx:
self.assertTrue(cnx.find('CWEType', name=u'Geometry'))
city_schema = cnx.system_sql("select sql from sqlite_master where type = 'table' and name = 'cw_City'").fetchall()[0][0]
city_schema = cnx.system_sql(sqlqs).fetchall()[0][0]
self.assertIn('cw_center_4326 text', city_schema)
......
......@@ -78,5 +78,5 @@ class RefpointWidget(formwidgets.TextInput):
"""
posted = form._cw.form
longitude = posted.get(field.input_name(form, 'longitude')).strip() or None
latitude = posted.get(field.input_name(form, 'latitude')).strip() or None
latitude = posted.get(field.input_name(form, 'latitude')).strip() or None
return u'POINT(%s %s)' % (longitude, latitude)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment