Commits

Evgeniy Tatarkin committed e77d744

support py3k

Comments (0)

Files changed (4)

sadisplay/describe.py

             if mapper is not None:
                 self.name = mapper.class_.__name__
                 self.columns = mapper.columns
-                self.methods = mapper.class_.__dict__.iteritems()
+                self.methods = mapper.class_.__dict__.items()
                 self.inherits = mapper.inherits
                 self.properties = mapper.iterate_properties
                 self.bases = mapper.class_.__bases__
                 self.class_ = mapper.class_
-                self.table_name = unicode(mapper.mapped_table)
+                self.table_name = str(mapper.mapped_table)
 
             elif table is not None:
                 self.name = table.name
                 self.table_name = table.name
                 # prepend schema if exists for foreign key matching
-                if hasattr(table, "schema"):
+                if hasattr(table, "schema") and table.schema:
                     self.table_name = table.schema + "." + self.table_name
                 self.columns = table.columns
             else:
                 pass
 
         def __eq__(self, other):
+            if isinstance(other, type(self)):
+                return self.table_name == other.table_name
             return self.name == other
 
     objects = []
     inherits = []
 
     entries = []
-
     for item in items:
         try:
-            entries.append(EntryItem(mapper=class_mapper(item)))
+            mapper = class_mapper(item)
         except (exc.ArgumentError, orm.exc.UnmappedClassError):
+            if isinstance(item, Table):
+                entity = EntryItem(table=item)
+        else:
+            entity = EntryItem(mapper=mapper)
 
-            if isinstance(item, Table):
-                # Filter if table mapper already appended
-                if item.name not in [i.table_name for i in entries]:
-                    entries.append(EntryItem(table=item))
+        if entity not in entries:
+            entries.append(entity)
 
     for entry in entries:
 

sadisplay/reflect.py

     (options, args) = parser.parse_args()
 
     if not options.url:
-        print '-u/--url option required'
+        print('-u/--url option required')
         exit(1)
 
     engine = create_engine(options.url)
     meta.reflect(bind=engine)
 
     if options.list:
-        print 'Database tables:'
+        print('Database tables:')
         tables = sorted(meta.tables.keys())
 
         def _g(l, i):
                 return ''
 
         for i in xrange(0, len(tables), 2):
-            print '  %s' % _g(tables, i) \
+            print('  %s' % _g(tables, i) \
                 + ' ' * (38 - len(_g(tables, i))) \
-                + _g(tables, i + 1)
+                + _g(tables, i + 1))
 
         exit(0)
 
         tables -= set(map(string.strip, options.exclude.split(',')))
 
     desc = describe(map(lambda x: operator.getitem(meta.tables, x), tables))
-    print getattr(render, options.render)(desc)
+    print(getattr(render, options.render)(desc))
 # -*- coding: utf-8 -*-
 import re
 import os
-from setuptools import setup
+
+try:
+    from setuptools import setup
+except ImportError:
+    from distutils.core import setup
 
 
 here = os.path.dirname(os.path.abspath(__file__))
 version_re = re.compile(r"__version__ = (\'.*?\')")
-f = open(os.path.join(os.path.join(here, 'sadisplay'), '__init__.py'))
-version = None
-for line in f:
-    match = version_re.search(line)
-    if match:
-        version = eval(match.group(1))
-        break
-else:
-    raise Exception("Cannot find version in sadisplay.py")
-f.close()
+with open(os.path.join(os.path.join(here, 'sadisplay'), '__init__.py')) as f:
+    version = None
+    for line in f:
+        match = version_re.search(line)
+        if match:
+            version = eval(match.group(1))
+            break
+    else:
+        raise Exception("Cannot find version in sadisplay.py")
 
 
 setup(
     author_email='tatarkin.evg@gmail.com',
     description='SqlAlchemy schema display script',
     long_description=open(os.path.join(here, 'README.rst')).read(),
-    packages=['sadisplay'],
+    packages=['sadisplay',],
     zip_safe=False,
     platforms='any',
+    tests_require=['nose >= 1.0',],
+    test_suite = 'nose.collector',
     install_requires=[
         'SQLAlchemy >= 0.5',
     ],
         'License :: OSI Approved :: BSD License',
         'Operating System :: OS Independent',
         'Programming Language :: Python',
-    ]
+        'Programming Language :: Python :: 3',
+    ],
 )

tests/test_describe.py

 # -*- coding: utf-8 -*-
-import unittest
 import sadisplay
 import model
 
 
-class TestDescribe(unittest.TestCase):
+class TestDescribe(object):
 
     def test_single_mapper(self):
 
                 'props': [],
                 'methods': [],
             }
-
-
-if __name__ == '__main__':
-    unittest.main()