From 2f1fa130a72dc0d098a3f71d38671369be2aeff9 Mon Sep 17 00:00:00 2001 From: Mauro Bianchi Date: Thu, 16 Feb 2012 12:34:47 +0100 Subject: [PATCH 1/7] Added single table option --- inspectdb/management/commands/inspectdb.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/inspectdb/management/commands/inspectdb.py b/inspectdb/management/commands/inspectdb.py index a1a85dd..f9f4723 100644 --- a/inspectdb/management/commands/inspectdb.py +++ b/inspectdb/management/commands/inspectdb.py @@ -28,6 +28,14 @@ class Command(NoArgsCommand): default=False, help=('Forces the field key word argument ``db_column``'), ), + make_option( + '-s', + '--single.table', + action='store', + dest='single_table', + default=None, + help=('Inspects a single table'), + ), ) requires_model_validation = False @@ -43,11 +51,17 @@ def handle_noargs(self, **options): def handle_inspection(self, options): alias = options['database'] force_db_column = options['force_db_column'] + single_table = options['single_table'] self.engine = settings.DATABASES[alias]['ENGINE'] self.connection = connections[alias] cursor = self.connection.cursor() yield 'from %s import models' % self.db_module - for table_name in self.connection.introspection.get_table_list(cursor): + if single_table is None: + tables_list = self.connection.introspection.get_table_list(cursor) + else: + tables_list = [single_table] + + for table_name in tables_list: yield '' yield '' yield 'class %s(models.Model):' % to_model(table_name) From cc48106c6496b49e7094a8711bcce3d0adf48d76 Mon Sep 17 00:00:00 2001 From: Mauro Bianchi Date: Thu, 16 Feb 2012 19:29:09 +0100 Subject: [PATCH 2/7] Added excluded tables and selected tables as comma separated lists --- inspectdb/management/commands/inspectdb.py | 43 +++++++++++++++++----- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/inspectdb/management/commands/inspectdb.py b/inspectdb/management/commands/inspectdb.py index f9f4723..b4b8140 100644 --- a/inspectdb/management/commands/inspectdb.py +++ b/inspectdb/management/commands/inspectdb.py @@ -29,12 +29,20 @@ class Command(NoArgsCommand): help=('Forces the field key word argument ``db_column``'), ), make_option( - '-s', - '--single.table', + '-t', + '--tables', action='store', - dest='single_table', + dest='selected_tables', default=None, - help=('Inspects a single table'), + help=('Inspects tables in list (comma separated)'), + ), + make_option( + '-e', + '--excluded-tables', + action='store', + dest='excluded_tables', + default=None, + help=('Do not inspect tables in list (comma separated)'), ), ) @@ -51,17 +59,32 @@ def handle_noargs(self, **options): def handle_inspection(self, options): alias = options['database'] force_db_column = options['force_db_column'] - single_table = options['single_table'] + selected_tables = options['selected_tables'] + excluded_tables = options['excluded_tables'] self.engine = settings.DATABASES[alias]['ENGINE'] self.connection = connections[alias] cursor = self.connection.cursor() yield 'from %s import models' % self.db_module - if single_table is None: - tables_list = self.connection.introspection.get_table_list(cursor) - else: - tables_list = [single_table] - for table_name in tables_list: + all_tables_list = self.connection.introspection.get_table_list(cursor)[:] + if selected_tables is None and excluded_tables is None: + selected_tables_list = all_tables_list + elif selected_tables and len(selected_tables): + try: + selected_tables_list = selected_tables.split(",") + tables_not_found = [t for t in selected_tables_list if t not in all_tables_list] + if len(tables_not_found): + raise + except: + raise CommandError("With the -t or --tables, you must provide a comma separated list of existing tables") + elif excluded_tables and len(excluded_tables): + try: + excluded_tables_list = excluded_tables.split(",") + selected_tables_list = [x for x in all_tables_list if x not in excluded_tables_list] + except Exception, e: + raise CommandError("With the -e or --excluded-tables, you must provide a comma separated list of tables") + + for table_name in selected_tables_list: yield '' yield '' yield 'class %s(models.Model):' % to_model(table_name) From 6bfa0f3b5f1619a975550b2c90c4c04a3e00662e Mon Sep 17 00:00:00 2001 From: Mauro Bianchi Date: Fri, 17 Feb 2012 15:21:03 +0100 Subject: [PATCH 3/7] Updated README --- README.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.rst b/README.rst index 429b606..b19f153 100644 --- a/README.rst +++ b/README.rst @@ -27,6 +27,20 @@ Just use it as the normal `inspectdb management command`_:: python manage.py inspectdb > models.py +The following command-line switches are available: + +-d,--database + + python manage.py inspectdb -d yourdbname > models.py + +-t,--tables + + python manage.py inspectdb -t yourtablename1,yourtablename2 > models.py + +-e,--exclude-tables + + python manage.py inspectdb -e yourtablename1,yourtablename2 > models.py + .. _ticket #5725: http://code.djangoproject.com/ticket/5725 .. _inspectdb management command: http://docs.djangoproject.com/en/1.3/howto/legacy-databases/#auto-generate-the-models From 8005b1046b73b92688702f973d526bc38a3ea32d Mon Sep 17 00:00:00 2001 From: Mauro Bianchi Date: Fri, 17 Feb 2012 15:21:51 +0100 Subject: [PATCH 4/7] README --- README.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index b19f153..6309b5c 100644 --- a/README.rst +++ b/README.rst @@ -29,15 +29,15 @@ Just use it as the normal `inspectdb management command`_:: The following command-line switches are available: --d,--database + -d,--database python manage.py inspectdb -d yourdbname > models.py --t,--tables + -t,--tables python manage.py inspectdb -t yourtablename1,yourtablename2 > models.py --e,--exclude-tables + -e,--exclude-tables python manage.py inspectdb -e yourtablename1,yourtablename2 > models.py From 99785560587c05491ad674a7a6f53115d635d558 Mon Sep 17 00:00:00 2001 From: Mauro Bianchi Date: Sun, 19 Feb 2012 23:32:53 +0100 Subject: [PATCH 5/7] Back to original README --- README.rst | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/README.rst b/README.rst index 429b606..6309b5c 100644 --- a/README.rst +++ b/README.rst @@ -27,6 +27,20 @@ Just use it as the normal `inspectdb management command`_:: python manage.py inspectdb > models.py +The following command-line switches are available: + + -d,--database + + python manage.py inspectdb -d yourdbname > models.py + + -t,--tables + + python manage.py inspectdb -t yourtablename1,yourtablename2 > models.py + + -e,--exclude-tables + + python manage.py inspectdb -e yourtablename1,yourtablename2 > models.py + .. _ticket #5725: http://code.djangoproject.com/ticket/5725 .. _inspectdb management command: http://docs.djangoproject.com/en/1.3/howto/legacy-databases/#auto-generate-the-models From e6dcd7d81f343347fdafcb0b3f0d7d9c420a987c Mon Sep 17 00:00:00 2001 From: Mauro Bianchi Date: Sun, 19 Feb 2012 23:37:55 +0100 Subject: [PATCH 6/7] Stripping table names passed with -t or -e opts --- inspectdb/management/commands/inspectdb.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/inspectdb/management/commands/inspectdb.py b/inspectdb/management/commands/inspectdb.py index b4b8140..c6ee320 100644 --- a/inspectdb/management/commands/inspectdb.py +++ b/inspectdb/management/commands/inspectdb.py @@ -72,6 +72,7 @@ def handle_inspection(self, options): elif selected_tables and len(selected_tables): try: selected_tables_list = selected_tables.split(",") + selected_tables_list = [x.strip() for x in selected_tables_list] tables_not_found = [t for t in selected_tables_list if t not in all_tables_list] if len(tables_not_found): raise @@ -80,6 +81,7 @@ def handle_inspection(self, options): elif excluded_tables and len(excluded_tables): try: excluded_tables_list = excluded_tables.split(",") + excluded_tables_list = [x.strip() for x in excluded_tables_list] selected_tables_list = [x for x in all_tables_list if x not in excluded_tables_list] except Exception, e: raise CommandError("With the -e or --excluded-tables, you must provide a comma separated list of tables") From 74e08995a45bc1d44cc42b8d5d227c8b565e1a64 Mon Sep 17 00:00:00 2001 From: Mauro Bianchi Date: Sat, 20 Oct 2018 14:19:41 +0200 Subject: [PATCH 7/7] commit before archive --- MANIFEST.in | 1 + 1 file changed, 1 insertion(+) diff --git a/MANIFEST.in b/MANIFEST.in index 8dce522..6979822 100644 --- a/MANIFEST.in +++ b/MANIFEST.in @@ -1 +1,2 @@ include LICENSE README.rst +recursive-include openlayers/templates *.txt *.html *.xml *.js \ No newline at end of file