From 2efdd61b2c9121f47b2ceb3d5984032e953598f7 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Wed, 1 Feb 2023 13:57:59 +0900 Subject: [PATCH 01/58] replace create.py to install ckan command create table --- development/misc/create.py | 182 +++++++++++++++++++++++++++++++++++-- 1 file changed, 172 insertions(+), 10 deletions(-) diff --git a/development/misc/create.py b/development/misc/create.py index 0a9b34bf..bfff9582 100644 --- a/development/misc/create.py +++ b/development/misc/create.py @@ -1,15 +1,177 @@ -# encoding: utf-8 - +import psycopg2 import click -@click.group(name=u'create', short_help=u"Create database tables") -def create(): - """Create the required database tables. +DB_HOST = "db" +DB_PORT = "5432" +DB_NAME = "ckan" +DB_USER = "ckan" +DB_PASS = "ckan" + +UTILIZATION = """ + CREATE TABLE utilization ( + id TEXT NOT NULL, + resource_id TEXT NOT NULL, + title TEXT, + url TEXT, + description TEXT, + created TIMESTAMP, + approval BOOLEAN DEFAULT false, + approved TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (resource_id) REFERENCES resource (id) + ); + """ + +UTILIZATION_SUMMARY = """ + CREATE TABLE utilization_summary ( + id TEXT NOT NULL, + utilization_id TEXT NOT NULL, + issue_resolution INTEGER, + created TIMESTAMP, + updated TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (utilization_id) REFERENCES utilization (id) + ); + """ + +UTILIZATION_FEEDBACK = """ + CREATE TYPE genre1 AS ENUM ('1', '2'); + CREATE TABLE utilization_feedback ( + id TEXT NOT NULL, + utilization_id TEXT NOT NULL, + type genre1 NOT NULL, + desctiption TEXT, + created TIMESTAMP, + approval BOOLEAN DEFAULT false, + approved TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (utilization_id) REFERENCES utilization (id) + ); + """ + +ISSUE_RESOLUTION = """ + CREATE TABLE issue_resolution ( + id TEXT NOT NULL, + utilization_id TEXT NOT NULL, + description TEXT, + created TIMESTAMP, + creator_user_id TEXT, + PRIMARY KEY (id), + FOREIGN KEY (utilization_id) REFERENCES utilization (id) + ); + """ + +UTILIZATION_FEEDBACK_REPLY = """ + CREATE TABLE utilization_feedback_reply ( + id TEXT NOT NULL, + utilization_feedback_id TEXT NOT NULL, + description TEXT, + created TIMESTAMP, + creator_user_id TEXT, + PRIMARY KEY (id), + FOREIGN KEY (utilization_feedback_id) REFERENCES utilization_feedback (id) + ); + """ + +RESOURCE_FEEDBACK = """ + CREATE TYPE genre2 AS ENUM ('1', '2'); + CREATE TABLE resource_feedback ( + id TEXT NOT NULL, + resource_id TEXT NOT NULL, + type genre2 NOT NULL, + description TEXT, + rating INTEGER, + created TIMESTAMP, + approval BOOLEAN DEFAULT false, + approved TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (resource_id) REFERENCES resource (id) + ); + """ + +RESOURCE_FEEDBACK_REPLY = """ + CREATE TABLE resource_feedback_reply ( + id TEXT NOT NULL, + resource_feedback_id TEXT NOT NULL, + desctiption TEXT, + created TIMESTAMP, + created_user_id TEXT, + PRIMARY KEY (id), + FOREIGN KEY (resource_feedback_id) REFERENCES resource_feedback (id) + ); """ - pass -@create.command() -def create_tables(): - """Create the required database tables. +RESOURCE_SUMMARY = """ + CREATE TABLE resource_summary ( + id TEXT NOT NULL, + resource_id TEXT NOT NULL, + utilization INTEGER, + download INTEGER, + created TIMESTAMP, + updated TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (resource_id) REFERENCES resource (id) + ); """ - click.secho(u'The create_tables command was executed successfully.', fg=u'green', bold=True) \ No newline at end of file + + +@click.group(short_help="create tables to use extension") +def create(): + pass + + +def get_connection(): + return psycopg2.connect( + "postgresql://{user}:{password}@{host}:{port}/{dbname}".format( + user=DB_USER, password=DB_PASS, host=DB_HOST, port=DB_PORT, dbname=DB_NAME + ) + ) + + +@create.command(name="table", short_help="create tables in ckan db.") +@click.option( + "-u", + "--utilization", + is_flag=True, + help=( + "create tables which are " + "utilization, utilization_summary, " + "utilization_feedback, issue_resolution, " + "utilization_feedback_reply." + ), +) +@click.option( + "-r", + "--resource", + is_flag=True, + help=("create tables which are " "resource_feedback, resource_feedback_reply."), +) +@click.option( + "-c", "--count", is_flag=True, help=("create table which is " "resource_summary") +) +@click.option("-A", "--alltables", is_flag=True) +def table(alltables, utilization, resource, count): + + with get_connection() as conn: + with conn.cursor() as cur: + + if alltables: + utilization = True + resource = True + count = True + + if utilization: + cur.execute(UTILIZATION) + cur.execute(UTILIZATION_SUMMARY) + cur.execute(UTILIZATION_FEEDBACK) + cur.execute(ISSUE_RESOLUTION) + cur.execute(UTILIZATION_FEEDBACK_REPLY) + + if resource: + cur.execute(RESOURCE_FEEDBACK) + cur.execute(RESOURCE_FEEDBACK_REPLY) + + if count: + cur.execute(RESOURCE_SUMMARY) + + conn.commit() From 6903abd6a78d16acafec00b55bd5e194ae8d8d00 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Wed, 1 Feb 2023 14:08:33 +0900 Subject: [PATCH 02/58] delete some words which dont need --- development/misc/create.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/development/misc/create.py b/development/misc/create.py index bfff9582..f31cc4fc 100644 --- a/development/misc/create.py +++ b/development/misc/create.py @@ -144,12 +144,13 @@ def get_connection(): "-r", "--resource", is_flag=True, - help=("create tables which are " "resource_feedback, resource_feedback_reply."), + help=("create tables which are resource_feedback, resource_feedback_reply."), ) @click.option( - "-c", "--count", is_flag=True, help=("create table which is " "resource_summary") + "-c", "--count", is_flag=True, help=("create table which is resource_summary") +) +@click.option("-A", "--alltables", is_flag=True, help=("create all tables") ) -@click.option("-A", "--alltables", is_flag=True) def table(alltables, utilization, resource, count): with get_connection() as conn: From ca16e7d46db60eda4fc849e7616c4214352506e3 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 7 Feb 2023 10:43:56 +0900 Subject: [PATCH 03/58] rename create.py to feedback.py and rewrite cli.py create to feedback to use feedback command --- development/misc/cli.py | 4 ++-- development/misc/{create.py => feedback.py} | 0 2 files changed, 2 insertions(+), 2 deletions(-) rename development/misc/{create.py => feedback.py} (100%) diff --git a/development/misc/cli.py b/development/misc/cli.py index 39b4a293..92b1f0d9 100644 --- a/development/misc/cli.py +++ b/development/misc/cli.py @@ -30,7 +30,7 @@ less, generate, user, - create + feedback ) from ckan.cli import seed @@ -222,4 +222,4 @@ def ckan(): ckan.add_command(less.less) ckan.add_command(generate.generate) ckan.add_command(user.user) -ckan.add_command(create.create) +ckan.add_command(feedback.feedback) diff --git a/development/misc/create.py b/development/misc/feedback.py similarity index 100% rename from development/misc/create.py rename to development/misc/feedback.py From b5ba5a95b70907800d0b7fafb04a7504a6fdacf8 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 7 Feb 2023 10:45:28 +0900 Subject: [PATCH 04/58] add feedback.py to take feedback --- development/misc/feedback.py | 192 ++++++++++++++++++----------------- 1 file changed, 101 insertions(+), 91 deletions(-) diff --git a/development/misc/feedback.py b/development/misc/feedback.py index f31cc4fc..12f4ae84 100644 --- a/development/misc/feedback.py +++ b/development/misc/feedback.py @@ -1,11 +1,32 @@ +import os import psycopg2 import click +import ckan.plugins.toolkit as tk + DB_HOST = "db" -DB_PORT = "5432" -DB_NAME = "ckan" -DB_USER = "ckan" -DB_PASS = "ckan" +DB_PORT = os.environ.get('POSTGRES_PORT') +DB_NAME = os.environ.get('POSTGRES_DB') +DB_USER = os.environ.get('POSTGRES_USER') +DB_PASS = os.environ.get('POSTGRES_PASSWORD') + +UTILIZATION_CLEAN = """ + DROP TABLE IF EXISTS utilization CASCADE; + DROP TABLE IF EXISTS utilization_feedback CASCADE; + DROP TABLE IF EXISTS utilization_feedback_reply CASCADE; + DROP TABLE IF EXISTS utilization_summary CASCADE; + DROP TYPE IF EXISTS genre1; + """ + +REVIEW_CLEAN = """ + DROP TABLE IF EXISTS resource_feedback CASCADE; + DROP TABLE IF EXISTS resource_feedback_reply CASCADE; + DROP TYPE IF EXISTS genre2; + """ + +DOWNLOAD_CLEAN = """ + DROP TABLE IF EXISTS utilization_summary CASCADE; + """ UTILIZATION = """ CREATE TABLE utilization ( @@ -20,60 +41,44 @@ PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - """ - -UTILIZATION_SUMMARY = """ - CREATE TABLE utilization_summary ( - id TEXT NOT NULL, - utilization_id TEXT NOT NULL, - issue_resolution INTEGER, - created TIMESTAMP, - updated TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY (utilization_id) REFERENCES utilization (id) - ); - """ -UTILIZATION_FEEDBACK = """ CREATE TYPE genre1 AS ENUM ('1', '2'); CREATE TABLE utilization_feedback ( id TEXT NOT NULL, utilization_id TEXT NOT NULL, type genre1 NOT NULL, - desctiption TEXT, + description TEXT, created TIMESTAMP, approval BOOLEAN DEFAULT false, approved TIMESTAMP, PRIMARY KEY (id), FOREIGN KEY (utilization_id) REFERENCES utilization (id) ); - """ -ISSUE_RESOLUTION = """ - CREATE TABLE issue_resolution ( + CREATE TABLE utilization_feedback_reply ( id TEXT NOT NULL, - utilization_id TEXT NOT NULL, + utilization_feedback_id TEXT NOT NULL, description TEXT, created TIMESTAMP, creator_user_id TEXT, PRIMARY KEY (id), - FOREIGN KEY (utilization_id) REFERENCES utilization (id) + FOREIGN KEY (utilization_feedback_id) REFERENCES utilization_feedback (id) ); - """ -UTILIZATION_FEEDBACK_REPLY = """ - CREATE TABLE utilization_feedback_reply ( + CREATE TABLE utilization_summary ( id TEXT NOT NULL, - utilization_feedback_id TEXT NOT NULL, - description TEXT, + resource_id TEXT NOT NULL, + utilization INTEGER, + download INTEGER, + issue_resolution INTEGER, created TIMESTAMP, - creator_user_id TEXT, + updated TIMESTAMP, PRIMARY KEY (id), - FOREIGN KEY (utilization_feedback_id) REFERENCES utilization_feedback (id) + FOREIGN KEY (resource_id) REFERENCES resource (id) ); """ -RESOURCE_FEEDBACK = """ +REVIEW = """ CREATE TYPE genre2 AS ENUM ('1', '2'); CREATE TABLE resource_feedback ( id TEXT NOT NULL, @@ -87,26 +92,26 @@ PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - """ -RESOURCE_FEEDBACK_REPLY = """ CREATE TABLE resource_feedback_reply ( id TEXT NOT NULL, resource_feedback_id TEXT NOT NULL, - desctiption TEXT, + description TEXT, created TIMESTAMP, - created_user_id TEXT, + creator_user_id TEXT, PRIMARY KEY (id), FOREIGN KEY (resource_feedback_id) REFERENCES resource_feedback (id) + ); """ -RESOURCE_SUMMARY = """ - CREATE TABLE resource_summary ( +DOWNLOAD = """ + CREATE TABLE utilization_summary ( id TEXT NOT NULL, resource_id TEXT NOT NULL, utilization INTEGER, download INTEGER, + issue_resolution INTEGER, created TIMESTAMP, updated TIMESTAMP, PRIMARY KEY (id), @@ -114,65 +119,70 @@ ); """ - @click.group(short_help="create tables to use extension") -def create(): +def feedback(): pass -def get_connection(): - return psycopg2.connect( - "postgresql://{user}:{password}@{host}:{port}/{dbname}".format( - user=DB_USER, password=DB_PASS, host=DB_HOST, port=DB_PORT, dbname=DB_NAME +def get_connection(user, password, host, port, name): + try: + connector = psycopg2.connect( + "postgresql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}".format( + db_user=user, db_password=password, db_host=host, db_port=port, db_name=name + ) ) - ) - - -@create.command(name="table", short_help="create tables in ckan db.") -@click.option( - "-u", - "--utilization", - is_flag=True, - help=( - "create tables which are " - "utilization, utilization_summary, " - "utilization_feedback, issue_resolution, " - "utilization_feedback_reply." - ), -) -@click.option( - "-r", - "--resource", - is_flag=True, - help=("create tables which are resource_feedback, resource_feedback_reply."), -) -@click.option( - "-c", "--count", is_flag=True, help=("create table which is resource_summary") -) -@click.option("-A", "--alltables", is_flag=True, help=("create all tables") -) -def table(alltables, utilization, resource, count): - - with get_connection() as conn: + except Exception as e: + tk.error_shout(e) + else: + return connector + + +@feedback.command(name="init", short_help="create tables in ckan db.") +@click.option("-m", "--modules", multiple=True, type=click.Choice(["utilization", "review", "download"])) +@click.option("-h", "--host", default="db") +@click.option("-p", "--port", default=DB_PORT) +@click.option("-n", "--name", default=DB_PORT) +@click.option("-u", "--user", default=DB_USER) +@click.option("-pw", "--password", default=DB_PASS) +def table(modules, host, port, name, user, password): + with get_connection(user, password, host, port, name) as conn: with conn.cursor() as cur: - if alltables: - utilization = True - resource = True - count = True - - if utilization: - cur.execute(UTILIZATION) - cur.execute(UTILIZATION_SUMMARY) - cur.execute(UTILIZATION_FEEDBACK) - cur.execute(ISSUE_RESOLUTION) - cur.execute(UTILIZATION_FEEDBACK_REPLY) - - if resource: - cur.execute(RESOURCE_FEEDBACK) - cur.execute(RESOURCE_FEEDBACK_REPLY) - - if count: - cur.execute(RESOURCE_SUMMARY) + if (bool(modules)): + for module in modules: + if module == "utilization": + try: + cur.execute(UTILIZATION_CLEAN) + cur.execute(UTILIZATION) + except Exception as e: + tk.error_shout(e) + else: + click.secho('Initialize utilization: SUCCESS', fg=u'green', bold=True) + if module == "review": + try: + cur.execute(REVIEW_CLEAN) + cur.execute(REVIEW) + except Exception as e: + tk.error_shout(e) + else: + click.secho('Initialize review: SUCCESS', fg=u'green', bold=True) + if module == "download": + try: + cur.execute(DOWNLOAD_CLEAN) + cur.execute(DOWNLOAD) + except Exception as e: + tk.error_shout(e) + else: + click.secho('Initialize download: SUCCESS', fg=u'green', bold=True) + else: + try: + cur.execute(UTILIZATION_CLEAN) + cur.execute(UTILIZATION) + cur.execute(REVIEW_CLEAN) + cur.execute(REVIEW) + except Exception as e: + tk.error_shout(e) + else: + click.secho('Initialization: SUCCESS', fg=u'green', bold=True) conn.commit() From 4fba29293d8be2b01f7f37571995f83dcb279693 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 7 Feb 2023 14:17:21 +0900 Subject: [PATCH 05/58] set default of ckan db setting and change where commit() is --- development/misc/feedback.py | 78 ++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 22 deletions(-) diff --git a/development/misc/feedback.py b/development/misc/feedback.py index 12f4ae84..3b0ace56 100644 --- a/development/misc/feedback.py +++ b/development/misc/feedback.py @@ -4,11 +4,11 @@ import ckan.plugins.toolkit as tk -DB_HOST = "db" -DB_PORT = os.environ.get('POSTGRES_PORT') -DB_NAME = os.environ.get('POSTGRES_DB') -DB_USER = os.environ.get('POSTGRES_USER') -DB_PASS = os.environ.get('POSTGRES_PASSWORD') +DB_HOST = os.getenv("POSTGRES_HOST", "db") +DB_PORT = os.getenv("POSTGRES_PORT", "5432") +DB_NAME = os.getenv("POSTGRES_DB", "ckan") +DB_USER = os.getenv("POSTGRES_USER", "ckan") +DB_PASS = os.getenv("POSTGRES_PASSWORD", "ckan") UTILIZATION_CLEAN = """ DROP TABLE IF EXISTS utilization CASCADE; @@ -119,6 +119,7 @@ ); """ + @click.group(short_help="create tables to use extension") def feedback(): pass @@ -128,7 +129,11 @@ def get_connection(user, password, host, port, name): try: connector = psycopg2.connect( "postgresql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}".format( - db_user=user, db_password=password, db_host=host, db_port=port, db_name=name + db_user=user, + db_password=password, + db_host=host, + db_port=port, + db_name=name, ) ) except Exception as e: @@ -137,52 +142,81 @@ def get_connection(user, password, host, port, name): return connector -@feedback.command(name="init", short_help="create tables in ckan db.") -@click.option("-m", "--modules", multiple=True, type=click.Choice(["utilization", "review", "download"])) -@click.option("-h", "--host", default="db") -@click.option("-p", "--port", default=DB_PORT) -@click.option("-n", "--name", default=DB_PORT) -@click.option("-u", "--user", default=DB_USER) -@click.option("-pw", "--password", default=DB_PASS) +@feedback.command( + name="init", short_help="create tables in ckan db to activate modules." +) +@click.option( + "-m", + "--modules", + multiple=True, + type=click.Choice(["utilization", "resource", "download"]), + help="specify the module you want to use from 'utilization', 'resource', 'download'", +) +@click.option( + "-h", "--host", default=DB_HOST, help="specify the host name of postgresql" +) +@click.option( + "-p", "--port", default=DB_PORT, help="specify the port number of postgresql" +) +@click.option("-n", "--name", default=DB_NAME, help="specify the name of postgresql") +@click.option( + "-u", "--user", default=DB_USER, help="specify the user name of postgresql" +) +@click.option( + "-pw", + "--password", + default=DB_PASS, + help="specify the password to connect postgresql", +) def table(modules, host, port, name, user, password): with get_connection(user, password, host, port, name) as conn: with conn.cursor() as cur: - if (bool(modules)): + if bool(modules): for module in modules: if module == "utilization": try: cur.execute(UTILIZATION_CLEAN) cur.execute(UTILIZATION) + conn.commit() except Exception as e: - tk.error_shout(e) + tk.error_shout(e) else: - click.secho('Initialize utilization: SUCCESS', fg=u'green', bold=True) - if module == "review": + click.secho( + "Initialize utilization: SUCCESS", fg="green", bold=True + ) + if module == "resource": try: cur.execute(REVIEW_CLEAN) cur.execute(REVIEW) + conn.commit() except Exception as e: tk.error_shout(e) else: - click.secho('Initialize review: SUCCESS', fg=u'green', bold=True) + click.secho( + "Initialize resource: SUCCESS", fg="green", bold=True + ) if module == "download": try: cur.execute(DOWNLOAD_CLEAN) cur.execute(DOWNLOAD) + conn.commit() except Exception as e: tk.error_shout(e) else: - click.secho('Initialize download: SUCCESS', fg=u'green', bold=True) + click.secho( + "Initialize download: SUCCESS", fg="green", bold=True + ) else: try: cur.execute(UTILIZATION_CLEAN) cur.execute(UTILIZATION) cur.execute(REVIEW_CLEAN) cur.execute(REVIEW) + conn.commit() except Exception as e: tk.error_shout(e) else: - click.secho('Initialization: SUCCESS', fg=u'green', bold=True) - - conn.commit() + click.secho( + "Initialize all modules: SUCCESS", fg="green", bold=True + ) From f9e244ea2007ac7ae1ee417f9fb0df480cc22138 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 7 Feb 2023 16:38:47 +0900 Subject: [PATCH 06/58] add execute of download module --- development/misc/feedback.py | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/development/misc/feedback.py b/development/misc/feedback.py index 3b0ace56..814c18fc 100644 --- a/development/misc/feedback.py +++ b/development/misc/feedback.py @@ -64,18 +64,6 @@ PRIMARY KEY (id), FOREIGN KEY (utilization_feedback_id) REFERENCES utilization_feedback (id) ); - - CREATE TABLE utilization_summary ( - id TEXT NOT NULL, - resource_id TEXT NOT NULL, - utilization INTEGER, - download INTEGER, - issue_resolution INTEGER, - created TIMESTAMP, - updated TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY (resource_id) REFERENCES resource (id) - ); """ REVIEW = """ @@ -213,6 +201,8 @@ def table(modules, host, port, name, user, password): cur.execute(UTILIZATION) cur.execute(REVIEW_CLEAN) cur.execute(REVIEW) + cur.execute(DOWNLOAD_CLEAN) + cur.execute(DOWNLOAD) conn.commit() except Exception as e: tk.error_shout(e) From 35468625d737b5fb05c01b6878aebefd57ad6ecf Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 7 Feb 2023 16:46:20 +0900 Subject: [PATCH 07/58] integrate if and for to change for xxxxx in modules --- development/misc/feedback.py | 67 ++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/development/misc/feedback.py b/development/misc/feedback.py index 814c18fc..2e547984 100644 --- a/development/misc/feedback.py +++ b/development/misc/feedback.py @@ -161,40 +161,39 @@ def table(modules, host, port, name, user, password): with conn.cursor() as cur: if bool(modules): - for module in modules: - if module == "utilization": - try: - cur.execute(UTILIZATION_CLEAN) - cur.execute(UTILIZATION) - conn.commit() - except Exception as e: - tk.error_shout(e) - else: - click.secho( - "Initialize utilization: SUCCESS", fg="green", bold=True - ) - if module == "resource": - try: - cur.execute(REVIEW_CLEAN) - cur.execute(REVIEW) - conn.commit() - except Exception as e: - tk.error_shout(e) - else: - click.secho( - "Initialize resource: SUCCESS", fg="green", bold=True - ) - if module == "download": - try: - cur.execute(DOWNLOAD_CLEAN) - cur.execute(DOWNLOAD) - conn.commit() - except Exception as e: - tk.error_shout(e) - else: - click.secho( - "Initialize download: SUCCESS", fg="green", bold=True - ) + if "utilization" in modules: + try: + cur.execute(UTILIZATION_CLEAN) + cur.execute(UTILIZATION) + conn.commit() + except Exception as e: + tk.error_shout(e) + else: + click.secho( + "Initialize utilization: SUCCESS", fg="green", bold=True + ) + if "resource" in modules: + try: + cur.execute(REVIEW_CLEAN) + cur.execute(REVIEW) + conn.commit() + except Exception as e: + tk.error_shout(e) + else: + click.secho( + "Initialize resource: SUCCESS", fg="green", bold=True + ) + if "download" in modules: + try: + cur.execute(DOWNLOAD_CLEAN) + cur.execute(DOWNLOAD) + conn.commit() + except Exception as e: + tk.error_shout(e) + else: + click.secho( + "Initialize download: SUCCESS", fg="green", bold=True + ) else: try: cur.execute(UTILIZATION_CLEAN) From 09898597bffc4a75bc69081e6825806cda42a70b Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 7 Feb 2023 16:51:19 +0900 Subject: [PATCH 08/58] change bool(modules) for modules is None --- development/misc/feedback.py | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/development/misc/feedback.py b/development/misc/feedback.py index 2e547984..825aa518 100644 --- a/development/misc/feedback.py +++ b/development/misc/feedback.py @@ -160,7 +160,22 @@ def table(modules, host, port, name, user, password): with get_connection(user, password, host, port, name) as conn: with conn.cursor() as cur: - if bool(modules): + if module is None: + try: + cur.execute(UTILIZATION_CLEAN) + cur.execute(UTILIZATION) + cur.execute(REVIEW_CLEAN) + cur.execute(REVIEW) + cur.execute(DOWNLOAD_CLEAN) + cur.execute(DOWNLOAD) + conn.commit() + except Exception as e: + tk.error_shout(e) + else: + click.secho( + "Initialize all modules: SUCCESS", fg="green", bold=True + ) + else: if "utilization" in modules: try: cur.execute(UTILIZATION_CLEAN) @@ -194,18 +209,3 @@ def table(modules, host, port, name, user, password): click.secho( "Initialize download: SUCCESS", fg="green", bold=True ) - else: - try: - cur.execute(UTILIZATION_CLEAN) - cur.execute(UTILIZATION) - cur.execute(REVIEW_CLEAN) - cur.execute(REVIEW) - cur.execute(DOWNLOAD_CLEAN) - cur.execute(DOWNLOAD) - conn.commit() - except Exception as e: - tk.error_shout(e) - else: - click.secho( - "Initialize all modules: SUCCESS", fg="green", bold=True - ) From 4b8c66d7481909257e47496d3778494b215f8680 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 7 Feb 2023 17:19:31 +0900 Subject: [PATCH 09/58] add s which forgets attaching module --- development/misc/feedback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/development/misc/feedback.py b/development/misc/feedback.py index 825aa518..7d7f3bd6 100644 --- a/development/misc/feedback.py +++ b/development/misc/feedback.py @@ -160,7 +160,7 @@ def table(modules, host, port, name, user, password): with get_connection(user, password, host, port, name) as conn: with conn.cursor() as cur: - if module is None: + if modules is None: try: cur.execute(UTILIZATION_CLEAN) cur.execute(UTILIZATION) From 3494fe6730c6e967a0732f85de1c61d924d3f50f Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Wed, 8 Feb 2023 09:48:38 +0900 Subject: [PATCH 10/58] move and integrate CLEAN at the first of init action --- development/misc/feedback.py | 34 ++++++++++++++-------------------- 1 file changed, 14 insertions(+), 20 deletions(-) diff --git a/development/misc/feedback.py b/development/misc/feedback.py index 7d7f3bd6..2d4df1b2 100644 --- a/development/misc/feedback.py +++ b/development/misc/feedback.py @@ -10,24 +10,17 @@ DB_USER = os.getenv("POSTGRES_USER", "ckan") DB_PASS = os.getenv("POSTGRES_PASSWORD", "ckan") -UTILIZATION_CLEAN = """ +CLEAN = """ DROP TABLE IF EXISTS utilization CASCADE; DROP TABLE IF EXISTS utilization_feedback CASCADE; DROP TABLE IF EXISTS utilization_feedback_reply CASCADE; DROP TABLE IF EXISTS utilization_summary CASCADE; - DROP TYPE IF EXISTS genre1; - """ - -REVIEW_CLEAN = """ DROP TABLE IF EXISTS resource_feedback CASCADE; DROP TABLE IF EXISTS resource_feedback_reply CASCADE; + DROP TYPE IF EXISTS genre1; DROP TYPE IF EXISTS genre2; """ -DOWNLOAD_CLEAN = """ - DROP TABLE IF EXISTS utilization_summary CASCADE; - """ - UTILIZATION = """ CREATE TABLE utilization ( id TEXT NOT NULL, @@ -151,7 +144,7 @@ def get_connection(user, password, host, port, name): "-u", "--user", default=DB_USER, help="specify the user name of postgresql" ) @click.option( - "-pw", + "-P", "--password", default=DB_PASS, help="specify the password to connect postgresql", @@ -160,15 +153,20 @@ def table(modules, host, port, name, user, password): with get_connection(user, password, host, port, name) as conn: with conn.cursor() as cur: + try: + cur.execute(CLEAN) + except Exception as e: + tk.error_shout(e) + else: + click.secho( + "Clean all modules: SUCCESS", fg="green", bold=True + ) + if modules is None: try: - cur.execute(UTILIZATION_CLEAN) cur.execute(UTILIZATION) - cur.execute(REVIEW_CLEAN) cur.execute(REVIEW) - cur.execute(DOWNLOAD_CLEAN) cur.execute(DOWNLOAD) - conn.commit() except Exception as e: tk.error_shout(e) else: @@ -178,9 +176,7 @@ def table(modules, host, port, name, user, password): else: if "utilization" in modules: try: - cur.execute(UTILIZATION_CLEAN) cur.execute(UTILIZATION) - conn.commit() except Exception as e: tk.error_shout(e) else: @@ -189,9 +185,7 @@ def table(modules, host, port, name, user, password): ) if "resource" in modules: try: - cur.execute(REVIEW_CLEAN) cur.execute(REVIEW) - conn.commit() except Exception as e: tk.error_shout(e) else: @@ -200,12 +194,12 @@ def table(modules, host, port, name, user, password): ) if "download" in modules: try: - cur.execute(DOWNLOAD_CLEAN) cur.execute(DOWNLOAD) - conn.commit() except Exception as e: tk.error_shout(e) else: click.secho( "Initialize download: SUCCESS", fg="green", bold=True ) + + conn.commit() From 1604c9f368c080bed7d5b36bfa863ff93721dd9e Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Wed, 8 Feb 2023 09:49:45 +0900 Subject: [PATCH 11/58] rename incorrect names --- development/misc/feedback.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/development/misc/feedback.py b/development/misc/feedback.py index 2d4df1b2..45c492a0 100644 --- a/development/misc/feedback.py +++ b/development/misc/feedback.py @@ -59,7 +59,7 @@ ); """ -REVIEW = """ +RESOURCE = """ CREATE TYPE genre2 AS ENUM ('1', '2'); CREATE TABLE resource_feedback ( id TEXT NOT NULL, @@ -149,7 +149,7 @@ def get_connection(user, password, host, port, name): default=DB_PASS, help="specify the password to connect postgresql", ) -def table(modules, host, port, name, user, password): +def init(modules, host, port, name, user, password): with get_connection(user, password, host, port, name) as conn: with conn.cursor() as cur: @@ -165,7 +165,7 @@ def table(modules, host, port, name, user, password): if modules is None: try: cur.execute(UTILIZATION) - cur.execute(REVIEW) + cur.execute(RESOURCE) cur.execute(DOWNLOAD) except Exception as e: tk.error_shout(e) @@ -185,7 +185,7 @@ def table(modules, host, port, name, user, password): ) if "resource" in modules: try: - cur.execute(REVIEW) + cur.execute(RESOURCE) except Exception as e: tk.error_shout(e) else: From 8a513e01406a4a8e3b8e444063c9e3fe03b80133 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Wed, 8 Feb 2023 09:52:35 +0900 Subject: [PATCH 12/58] exit from programme if error occurs --- development/misc/feedback.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/development/misc/feedback.py b/development/misc/feedback.py index 45c492a0..3c36420a 100644 --- a/development/misc/feedback.py +++ b/development/misc/feedback.py @@ -1,4 +1,5 @@ import os +import sys import psycopg2 import click @@ -119,6 +120,7 @@ def get_connection(user, password, host, port, name): ) except Exception as e: tk.error_shout(e) + sys.exit() else: return connector @@ -157,6 +159,7 @@ def init(modules, host, port, name, user, password): cur.execute(CLEAN) except Exception as e: tk.error_shout(e) + sys.exit() else: click.secho( "Clean all modules: SUCCESS", fg="green", bold=True @@ -169,6 +172,7 @@ def init(modules, host, port, name, user, password): cur.execute(DOWNLOAD) except Exception as e: tk.error_shout(e) + sys.exit() else: click.secho( "Initialize all modules: SUCCESS", fg="green", bold=True @@ -179,6 +183,7 @@ def init(modules, host, port, name, user, password): cur.execute(UTILIZATION) except Exception as e: tk.error_shout(e) + sys.exit() else: click.secho( "Initialize utilization: SUCCESS", fg="green", bold=True @@ -188,6 +193,7 @@ def init(modules, host, port, name, user, password): cur.execute(RESOURCE) except Exception as e: tk.error_shout(e) + sys.exit() else: click.secho( "Initialize resource: SUCCESS", fg="green", bold=True @@ -197,6 +203,7 @@ def init(modules, host, port, name, user, password): cur.execute(DOWNLOAD) except Exception as e: tk.error_shout(e) + sys.exit() else: click.secho( "Initialize download: SUCCESS", fg="green", bold=True From f938e658bb943d078ebf525e96949d683ac79be3 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Wed, 8 Feb 2023 09:58:45 +0900 Subject: [PATCH 13/58] format the programme --- development/misc/feedback.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/development/misc/feedback.py b/development/misc/feedback.py index 3c36420a..a37341ce 100644 --- a/development/misc/feedback.py +++ b/development/misc/feedback.py @@ -83,7 +83,7 @@ creator_user_id TEXT, PRIMARY KEY (id), FOREIGN KEY (resource_feedback_id) REFERENCES resource_feedback (id) - + ); """ @@ -161,9 +161,7 @@ def init(modules, host, port, name, user, password): tk.error_shout(e) sys.exit() else: - click.secho( - "Clean all modules: SUCCESS", fg="green", bold=True - ) + click.secho("Clean all modules: SUCCESS", fg="green", bold=True) if modules is None: try: @@ -208,5 +206,5 @@ def init(modules, host, port, name, user, password): click.secho( "Initialize download: SUCCESS", fg="green", bold=True ) - + conn.commit() From eb1347b2e66890ae801bf021f9d4e950a69c9798 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Wed, 8 Feb 2023 11:15:21 +0900 Subject: [PATCH 14/58] change if statement to do action after cleaning --- development/misc/feedback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/development/misc/feedback.py b/development/misc/feedback.py index a37341ce..b577372f 100644 --- a/development/misc/feedback.py +++ b/development/misc/feedback.py @@ -163,7 +163,7 @@ def init(modules, host, port, name, user, password): else: click.secho("Clean all modules: SUCCESS", fg="green", bold=True) - if modules is None: + if not modules: try: cur.execute(UTILIZATION) cur.execute(RESOURCE) From da742a03fba35303fbbbe847115ea96758bff39d Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Wed, 8 Feb 2023 12:14:59 +0900 Subject: [PATCH 15/58] add 1 as an argument of exit --- development/misc/feedback.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/development/misc/feedback.py b/development/misc/feedback.py index b577372f..3c7a8711 100644 --- a/development/misc/feedback.py +++ b/development/misc/feedback.py @@ -120,7 +120,7 @@ def get_connection(user, password, host, port, name): ) except Exception as e: tk.error_shout(e) - sys.exit() + sys.exit(1) else: return connector @@ -159,7 +159,7 @@ def init(modules, host, port, name, user, password): cur.execute(CLEAN) except Exception as e: tk.error_shout(e) - sys.exit() + sys.exit(1) else: click.secho("Clean all modules: SUCCESS", fg="green", bold=True) @@ -170,7 +170,7 @@ def init(modules, host, port, name, user, password): cur.execute(DOWNLOAD) except Exception as e: tk.error_shout(e) - sys.exit() + sys.exit(1) else: click.secho( "Initialize all modules: SUCCESS", fg="green", bold=True @@ -181,7 +181,7 @@ def init(modules, host, port, name, user, password): cur.execute(UTILIZATION) except Exception as e: tk.error_shout(e) - sys.exit() + sys.exit(1) else: click.secho( "Initialize utilization: SUCCESS", fg="green", bold=True @@ -191,7 +191,7 @@ def init(modules, host, port, name, user, password): cur.execute(RESOURCE) except Exception as e: tk.error_shout(e) - sys.exit() + sys.exit(1) else: click.secho( "Initialize resource: SUCCESS", fg="green", bold=True @@ -201,7 +201,7 @@ def init(modules, host, port, name, user, password): cur.execute(DOWNLOAD) except Exception as e: tk.error_shout(e) - sys.exit() + sys.exit(1) else: click.secho( "Initialize download: SUCCESS", fg="green", bold=True From ae8da13e0a97c4bf6bda4545d982c8950cf88950 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Wed, 8 Feb 2023 16:29:20 +0900 Subject: [PATCH 16/58] add README.md about ckan command 'feedback init' --- development/misc/README.md | 120 +++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 development/misc/README.md diff --git a/development/misc/README.md b/development/misc/README.md new file mode 100644 index 00000000..51fdd7da --- /dev/null +++ b/development/misc/README.md @@ -0,0 +1,120 @@ +## ckanコマンドの仕様 + +### デフォルト + +``` +ckan feedback init +``` + +* ```ckanext-feedback```で利用する全てのテーブル作成を行う + * すでにテーブルが作成されている場合は全て削除した後にテーブル作成を行う + +#### 成功時 + +* 以下のログが出力される +``` +Clean all modules: SUCCESS +Initialize all modules: SUCCESS +``` + +#### 失敗時 + +* エラー文が出力される + +* __コマンド実行前の状態に戻る__ + +### オプション + +#### Moduleに関連したオプション + +``` +--modules -m +``` + +* ```ckanext-feedback```のオンオフ機能と連動して、必要になるテーブルを作成する + * 以下の中から選択が可能 + * utilization (利活用方法) + * resource (データリソース) + * download (ダウンロード数) + +* 使用例 (```utilization```の機能に関連したテーブル作成を行う) +``` +ckan --config=/etc/ckan/production.ini feedback init -m utilization +``` + +#### 成功時 + +* ```utilization```指定時は以下のログが出力される +``` +Clean all modules: SUCCESS +Initialize utilization: SUCCESS +``` +* ```resource```指定時は以下のログが出力される +``` +Clean all modules: SUCCESS +Initialize resource: SUCCESS +``` +* ```download```指定時は以下のログが出力される +``` +Clean all modules: SUCCESS +Initialize download: SUCCESS +``` + +#### 失敗時 + +* エラー文が出力される + +* __コマンド実行前の状態に戻る__ + +#### Postgresqlに関連したオプション + +##### 参照される順番について + +* 以下の優先順位で値を参照する + * オプションで指定した値 + * 以下の名前の環境変数として設定されている値 + * ```POSTGRES_HOST``` + * ```POSTGRES_PORT``` + * ```POSTGRES_DB``` + * ```POSTGRES_USER``` + * ```POSTGRES_PASSWORD``` + * デフォルト値としてはCKANにデフォルトで設定されている値 + * ホスト名:```db``` + * ポート番号:```5432``` + * データベース名:```ckan``` + * ユーザー名:```ckan``` + * パスワード:```ckan``` + +※ 環境変数を登録する方法は以下の通り + +* ```ckan/contrib/docker/.env```に環境変数を記述する + (例) POSTGRES_PORT=5432 +* ```ckan/contrib/docker/docker-compose.yml```の```ckan```の```environment```に上で設定した環境変数を記述する + (例) POSTGRES_PORT=${POSTGRES_PORT} + +##### オプションについて + +``` +--host -h +``` +* Postgresql の接続に使うホスト名をコマンド上から指定する際に利用する + +``` +--port -p +``` +* Postgresql の接続に使うポート番号をコマンド上から指定する際に利用する + +``` +--name -n +``` +* Postgresql の接続に使うデータベース名をコマンド上から指定する際に利用する + +``` +--user -u +``` +* Postgresql の接続に使うユーザー名をコマンド上から指定する際に利用する + +``` +--password -P +``` +* Postgresql の接続に使うパスワードをコマンド上から指定する際に利用する \ No newline at end of file From cd69b6de28123d5ec2529a506263baa2f7882636 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Wed, 8 Feb 2023 16:33:43 +0900 Subject: [PATCH 17/58] modify README.md about ckan command --- development/misc/README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/development/misc/README.md b/development/misc/README.md index 51fdd7da..37878de4 100644 --- a/development/misc/README.md +++ b/development/misc/README.md @@ -32,6 +32,7 @@ Initialize all modules: SUCCESS ``` * ```ckanext-feedback```のオンオフ機能と連動して、必要になるテーブルを作成する + * すでにテーブルが作成されている場合は全て削除をしてから指定の機能のテーブルを作成する * 以下の中から選択が可能 * utilization (利活用方法) * resource (データリソース) @@ -94,27 +95,27 @@ Initialize download: SUCCESS ##### オプションについて +* Postgresql の接続に使うホスト名をコマンド上から指定する際に利用する ``` --host -h ``` -* Postgresql の接続に使うホスト名をコマンド上から指定する際に利用する +* Postgresql の接続に使うポート番号をコマンド上から指定する際に利用する ``` --port -p ``` -* Postgresql の接続に使うポート番号をコマンド上から指定する際に利用する +* Postgresql の接続に使うデータベース名をコマンド上から指定する際に利用する ``` --name -n ``` -* Postgresql の接続に使うデータベース名をコマンド上から指定する際に利用する +* Postgresql の接続に使うユーザー名をコマンド上から指定する際に利用する ``` --user -u ``` -* Postgresql の接続に使うユーザー名をコマンド上から指定する際に利用する +* Postgresql の接続に使うパスワードをコマンド上から指定する際に利用する ``` --password -P -``` -* Postgresql の接続に使うパスワードをコマンド上から指定する際に利用する \ No newline at end of file +``` \ No newline at end of file From a58453a1820c9eb40f7d521b05c830a4c91bf428 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Wed, 8 Feb 2023 16:37:27 +0900 Subject: [PATCH 18/58] modify README.md about color of sentences --- development/misc/README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/development/misc/README.md b/development/misc/README.md index 37878de4..4d940487 100644 --- a/development/misc/README.md +++ b/development/misc/README.md @@ -11,7 +11,7 @@ ckan feedback init #### 成功時 -* 以下のログが出力される +* 以下のログが出力される(緑色太字) ``` Clean all modules: SUCCESS Initialize all modules: SUCCESS @@ -45,17 +45,17 @@ ckan --config=/etc/ckan/production.ini feedback init -m utilization #### 成功時 -* ```utilization```指定時は以下のログが出力される +* ```utilization```指定時は以下のログが出力される(緑色太字) ``` Clean all modules: SUCCESS Initialize utilization: SUCCESS ``` -* ```resource```指定時は以下のログが出力される +* ```resource```指定時は以下のログが出力される(緑色太字) ``` Clean all modules: SUCCESS Initialize resource: SUCCESS ``` -* ```download```指定時は以下のログが出力される +* ```download```指定時は以下のログが出力される(緑色太字) ``` Clean all modules: SUCCESS Initialize download: SUCCESS From 35ae9f4147d052080c94ca0b1e71d2fb40b51110 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Wed, 8 Feb 2023 16:43:45 +0900 Subject: [PATCH 19/58] add explanation about information of postgresql --- development/misc/README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/development/misc/README.md b/development/misc/README.md index 4d940487..51a3646c 100644 --- a/development/misc/README.md +++ b/development/misc/README.md @@ -71,15 +71,15 @@ Initialize download: SUCCESS ##### 参照される順番について -* 以下の優先順位で値を参照する +* 以下の優先順位で値を参照する(上から優先度が高い) * オプションで指定した値 - * 以下の名前の環境変数として設定されている値 + * 以下の環境変数名で設定されている値 * ```POSTGRES_HOST``` * ```POSTGRES_PORT``` * ```POSTGRES_DB``` * ```POSTGRES_USER``` * ```POSTGRES_PASSWORD``` - * デフォルト値としてはCKANにデフォルトで設定されている値 + * CKANにデフォルトで設定されている値 * ホスト名:```db``` * ポート番号:```5432``` * データベース名:```ckan``` From c6f571fe39abfc08bd7eaa868f9cc37849a37fbd Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Fri, 10 Feb 2023 00:37:00 +0900 Subject: [PATCH 20/58] delete README.md --- development/misc/README.md | 121 ------------------------------------- 1 file changed, 121 deletions(-) delete mode 100644 development/misc/README.md diff --git a/development/misc/README.md b/development/misc/README.md deleted file mode 100644 index 51a3646c..00000000 --- a/development/misc/README.md +++ /dev/null @@ -1,121 +0,0 @@ -## ckanコマンドの仕様 - -### デフォルト - -``` -ckan feedback init -``` - -* ```ckanext-feedback```で利用する全てのテーブル作成を行う - * すでにテーブルが作成されている場合は全て削除した後にテーブル作成を行う - -#### 成功時 - -* 以下のログが出力される(緑色太字) -``` -Clean all modules: SUCCESS -Initialize all modules: SUCCESS -``` - -#### 失敗時 - -* エラー文が出力される - -* __コマンド実行前の状態に戻る__ - -### オプション - -#### Moduleに関連したオプション - -``` ---modules -m -``` - -* ```ckanext-feedback```のオンオフ機能と連動して、必要になるテーブルを作成する - * すでにテーブルが作成されている場合は全て削除をしてから指定の機能のテーブルを作成する - * 以下の中から選択が可能 - * utilization (利活用方法) - * resource (データリソース) - * download (ダウンロード数) - -* 使用例 (```utilization```の機能に関連したテーブル作成を行う) -``` -ckan --config=/etc/ckan/production.ini feedback init -m utilization -``` - -#### 成功時 - -* ```utilization```指定時は以下のログが出力される(緑色太字) -``` -Clean all modules: SUCCESS -Initialize utilization: SUCCESS -``` -* ```resource```指定時は以下のログが出力される(緑色太字) -``` -Clean all modules: SUCCESS -Initialize resource: SUCCESS -``` -* ```download```指定時は以下のログが出力される(緑色太字) -``` -Clean all modules: SUCCESS -Initialize download: SUCCESS -``` - -#### 失敗時 - -* エラー文が出力される - -* __コマンド実行前の状態に戻る__ - -#### Postgresqlに関連したオプション - -##### 参照される順番について - -* 以下の優先順位で値を参照する(上から優先度が高い) - * オプションで指定した値 - * 以下の環境変数名で設定されている値 - * ```POSTGRES_HOST``` - * ```POSTGRES_PORT``` - * ```POSTGRES_DB``` - * ```POSTGRES_USER``` - * ```POSTGRES_PASSWORD``` - * CKANにデフォルトで設定されている値 - * ホスト名:```db``` - * ポート番号:```5432``` - * データベース名:```ckan``` - * ユーザー名:```ckan``` - * パスワード:```ckan``` - -※ 環境変数を登録する方法は以下の通り - -* ```ckan/contrib/docker/.env```に環境変数を記述する - (例) POSTGRES_PORT=5432 -* ```ckan/contrib/docker/docker-compose.yml```の```ckan```の```environment```に上で設定した環境変数を記述する - (例) POSTGRES_PORT=${POSTGRES_PORT} - -##### オプションについて - -* Postgresql の接続に使うホスト名をコマンド上から指定する際に利用する -``` ---host -h -``` - -* Postgresql の接続に使うポート番号をコマンド上から指定する際に利用する -``` ---port -p -``` - -* Postgresql の接続に使うデータベース名をコマンド上から指定する際に利用する -``` ---name -n -``` - -* Postgresql の接続に使うユーザー名をコマンド上から指定する際に利用する -``` ---user -u -``` - -* Postgresql の接続に使うパスワードをコマンド上から指定する際に利用する -``` ---password -P -``` \ No newline at end of file From c424fae179d105e2c1cafd77be4740d64a9bf2ee Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Sun, 12 Feb 2023 20:31:48 +0900 Subject: [PATCH 21/58] change option name from --name to -dbname --- development/misc/feedback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/development/misc/feedback.py b/development/misc/feedback.py index 3c7a8711..bb8fd973 100644 --- a/development/misc/feedback.py +++ b/development/misc/feedback.py @@ -141,7 +141,7 @@ def get_connection(user, password, host, port, name): @click.option( "-p", "--port", default=DB_PORT, help="specify the port number of postgresql" ) -@click.option("-n", "--name", default=DB_NAME, help="specify the name of postgresql") +@click.option("-d", "--dbname", default=DB_NAME, help="specify the name of postgresql") @click.option( "-u", "--user", default=DB_USER, help="specify the user name of postgresql" ) From 882fa6f0a168f27ebd818c5014a1cbdefb23b9eb Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Sun, 12 Feb 2023 20:40:19 +0900 Subject: [PATCH 22/58] delete feedback commnad from cli.py --- development/misc/cli.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/development/misc/cli.py b/development/misc/cli.py index 92b1f0d9..e7625e1b 100644 --- a/development/misc/cli.py +++ b/development/misc/cli.py @@ -30,7 +30,6 @@ less, generate, user, - feedback ) from ckan.cli import seed @@ -222,4 +221,3 @@ def ckan(): ckan.add_command(less.less) ckan.add_command(generate.generate) ckan.add_command(user.user) -ckan.add_command(feedback.feedback) From 516498bbc8f748674c51000d7f7d170605c72f47 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Sun, 12 Feb 2023 20:46:26 +0900 Subject: [PATCH 23/58] change the location of feedback.py --- {development/misc => ckanext/feedback}/feedback.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {development/misc => ckanext/feedback}/feedback.py (100%) diff --git a/development/misc/feedback.py b/ckanext/feedback/feedback.py similarity index 100% rename from development/misc/feedback.py rename to ckanext/feedback/feedback.py From 836e13588e54e56e8188c52794ad62bd883c5462 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Sun, 12 Feb 2023 20:49:54 +0900 Subject: [PATCH 24/58] change from \' to " --- ckanext/feedback/feedback.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index bb8fd973..ec8bd007 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -36,7 +36,7 @@ FOREIGN KEY (resource_id) REFERENCES resource (id) ); - CREATE TYPE genre1 AS ENUM ('1', '2'); + CREATE TYPE genre1 AS ENUM ("1", "2"); CREATE TABLE utilization_feedback ( id TEXT NOT NULL, utilization_id TEXT NOT NULL, @@ -61,7 +61,7 @@ """ RESOURCE = """ - CREATE TYPE genre2 AS ENUM ('1', '2'); + CREATE TYPE genre2 AS ENUM ("1", "2"); CREATE TABLE resource_feedback ( id TEXT NOT NULL, resource_id TEXT NOT NULL, @@ -133,7 +133,7 @@ def get_connection(user, password, host, port, name): "--modules", multiple=True, type=click.Choice(["utilization", "resource", "download"]), - help="specify the module you want to use from 'utilization', 'resource', 'download'", + help="specify the module you want to use from "utilization", "resource", "download"", ) @click.option( "-h", "--host", default=DB_HOST, help="specify the host name of postgresql" From d3356e9d6110a36e52f0cf33b2724730739bffab Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Sun, 12 Feb 2023 20:57:05 +0900 Subject: [PATCH 25/58] add environment variable in click.option --- ckanext/feedback/feedback.py | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index ec8bd007..2b09772e 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -5,12 +5,6 @@ import ckan.plugins.toolkit as tk -DB_HOST = os.getenv("POSTGRES_HOST", "db") -DB_PORT = os.getenv("POSTGRES_PORT", "5432") -DB_NAME = os.getenv("POSTGRES_DB", "ckan") -DB_USER = os.getenv("POSTGRES_USER", "ckan") -DB_PASS = os.getenv("POSTGRES_PASSWORD", "ckan") - CLEAN = """ DROP TABLE IF EXISTS utilization CASCADE; DROP TABLE IF EXISTS utilization_feedback CASCADE; @@ -136,19 +130,20 @@ def get_connection(user, password, host, port, name): help="specify the module you want to use from "utilization", "resource", "download"", ) @click.option( - "-h", "--host", default=DB_HOST, help="specify the host name of postgresql" + "-h", "--host", envvar="POSTGRES_HOST", default="db", help="specify the host name of postgresql" ) @click.option( - "-p", "--port", default=DB_PORT, help="specify the port number of postgresql" + "-p", "--port", envvar="POSTGRES_PORT", default="5432", help="specify the port number of postgresql" ) -@click.option("-d", "--dbname", default=DB_NAME, help="specify the name of postgresql") +@click.option("-d", "--dbname", envvar="POSTGRES_DB", default="ckan", help="specify the name of postgresql") @click.option( - "-u", "--user", default=DB_USER, help="specify the user name of postgresql" + "-u", "--user", envvar="POSTGRES_USER", default="ckan", help="specify the user name of postgresql" ) @click.option( "-P", "--password", - default=DB_PASS, + envvar="POSTGRES_PASSWORD", + default="ckan", help="specify the password to connect postgresql", ) def init(modules, host, port, name, user, password): From bea74df490ba47a8ab3d29d85aa4ed32205f887c Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Sun, 12 Feb 2023 20:59:02 +0900 Subject: [PATCH 26/58] delete short_help about click.group --- ckanext/feedback/feedback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index 2b09772e..015084e4 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -96,7 +96,7 @@ """ -@click.group(short_help="create tables to use extension") +@click.group() def feedback(): pass From 467648cc2295c25a37f580866b88fc427ae5d1ca Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Sun, 12 Feb 2023 21:02:57 +0900 Subject: [PATCH 27/58] add explanation about feedback command --- ckanext/feedback/feedback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index 015084e4..308365c3 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -98,7 +98,7 @@ @click.group() def feedback(): - pass + """CLI tool for ckanext-feedback plugin.""" def get_connection(user, password, host, port, name): From a08d7d0bc19f50b05a1d55f56f0c5863280e57f1 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Sun, 12 Feb 2023 21:07:17 +0900 Subject: [PATCH 28/58] change cur and conn to cursor and connection --- ckanext/feedback/feedback.py | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index 308365c3..384401a4 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -147,11 +147,10 @@ def get_connection(user, password, host, port, name): help="specify the password to connect postgresql", ) def init(modules, host, port, name, user, password): - with get_connection(user, password, host, port, name) as conn: - with conn.cursor() as cur: - + with get_connection(user, password, host, port, name) as connection: + with connection.cursor() as cursor: try: - cur.execute(CLEAN) + cursor.execute(CLEAN) except Exception as e: tk.error_shout(e) sys.exit(1) @@ -160,9 +159,9 @@ def init(modules, host, port, name, user, password): if not modules: try: - cur.execute(UTILIZATION) - cur.execute(RESOURCE) - cur.execute(DOWNLOAD) + cursor.execute(UTILIZATION) + cursor.execute(RESOURCE) + cursor.execute(DOWNLOAD) except Exception as e: tk.error_shout(e) sys.exit(1) @@ -173,7 +172,7 @@ def init(modules, host, port, name, user, password): else: if "utilization" in modules: try: - cur.execute(UTILIZATION) + cursor.execute(UTILIZATION) except Exception as e: tk.error_shout(e) sys.exit(1) @@ -183,7 +182,7 @@ def init(modules, host, port, name, user, password): ) if "resource" in modules: try: - cur.execute(RESOURCE) + cursor.execute(RESOURCE) except Exception as e: tk.error_shout(e) sys.exit(1) @@ -193,7 +192,7 @@ def init(modules, host, port, name, user, password): ) if "download" in modules: try: - cur.execute(DOWNLOAD) + cursor.execute(DOWNLOAD) except Exception as e: tk.error_shout(e) sys.exit(1) @@ -202,4 +201,4 @@ def init(modules, host, port, name, user, password): "Initialize download: SUCCESS", fg="green", bold=True ) - conn.commit() + connection.commit() From 7d38c480d43695c2e7b84f07c7e7263ce35fc223 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Sun, 12 Feb 2023 21:11:07 +0900 Subject: [PATCH 29/58] change the order of get_connection's argument --- ckanext/feedback/feedback.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index 384401a4..e8e728cf 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -101,7 +101,7 @@ def feedback(): """CLI tool for ckanext-feedback plugin.""" -def get_connection(user, password, host, port, name): +def get_connection(host, port, dbname, user, password): try: connector = psycopg2.connect( "postgresql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}".format( @@ -146,8 +146,8 @@ def get_connection(user, password, host, port, name): default="ckan", help="specify the password to connect postgresql", ) -def init(modules, host, port, name, user, password): - with get_connection(user, password, host, port, name) as connection: +def init(modules, host, port, dbname, user, password): + with get_connection(host, port, dbname, user, password) as connection: with connection.cursor() as cursor: try: cursor.execute(CLEAN) From 4d45a9ec14b2f14c02453c3761d9f5bd5dc8c10e Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Sun, 12 Feb 2023 21:16:17 +0900 Subject: [PATCH 30/58] delete else to reduce the nest --- ckanext/feedback/feedback.py | 61 ++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index e8e728cf..ff64487f 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -169,36 +169,35 @@ def init(modules, host, port, dbname, user, password): click.secho( "Initialize all modules: SUCCESS", fg="green", bold=True ) - else: - if "utilization" in modules: - try: - cursor.execute(UTILIZATION) - except Exception as e: - tk.error_shout(e) - sys.exit(1) - else: - click.secho( - "Initialize utilization: SUCCESS", fg="green", bold=True - ) - if "resource" in modules: - try: - cursor.execute(RESOURCE) - except Exception as e: - tk.error_shout(e) - sys.exit(1) - else: - click.secho( - "Initialize resource: SUCCESS", fg="green", bold=True - ) - if "download" in modules: - try: - cursor.execute(DOWNLOAD) - except Exception as e: - tk.error_shout(e) - sys.exit(1) - else: - click.secho( - "Initialize download: SUCCESS", fg="green", bold=True - ) + elif "utilization" in modules: + try: + cursor.execute(UTILIZATION) + except Exception as e: + tk.error_shout(e) + sys.exit(1) + else: + click.secho( + "Initialize utilization: SUCCESS", fg="green", bold=True + ) + elif "resource" in modules: + try: + cursor.execute(RESOURCE) + except Exception as e: + tk.error_shout(e) + sys.exit(1) + else: + click.secho( + "Initialize resource: SUCCESS", fg="green", bold=True + ) + elif "download" in modules: + try: + cursor.execute(DOWNLOAD) + except Exception as e: + tk.error_shout(e) + sys.exit(1) + else: + click.secho( + "Initialize download: SUCCESS", fg="green", bold=True + ) connection.commit() From 4a8a3a1c06556fe7b646f09cf3a0bea53f808023 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Sun, 12 Feb 2023 21:26:03 +0900 Subject: [PATCH 31/58] put together error process --- ckanext/feedback/feedback.py | 52 ++++++++---------------------------- 1 file changed, 11 insertions(+), 41 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index ff64487f..14c90720 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -151,53 +151,23 @@ def init(modules, host, port, dbname, user, password): with connection.cursor() as cursor: try: cursor.execute(CLEAN) - except Exception as e: - tk.error_shout(e) - sys.exit(1) - else: click.secho("Clean all modules: SUCCESS", fg="green", bold=True) - - if not modules: - try: + if not modules: cursor.execute(UTILIZATION) cursor.execute(RESOURCE) cursor.execute(DOWNLOAD) - except Exception as e: - tk.error_shout(e) - sys.exit(1) - else: - click.secho( - "Initialize all modules: SUCCESS", fg="green", bold=True - ) - elif "utilization" in modules: - try: + click.secho("Initialize all modules: SUCCESS", fg="green", bold=True) + elif "utilization" in modules: cursor.execute(UTILIZATION) - except Exception as e: - tk.error_shout(e) - sys.exit(1) - else: - click.secho( - "Initialize utilization: SUCCESS", fg="green", bold=True - ) - elif "resource" in modules: - try: + click.secho("Initialize utilization: SUCCESS", fg="green", bold=True) + elif "resource" in modules: cursor.execute(RESOURCE) - except Exception as e: - tk.error_shout(e) - sys.exit(1) - else: - click.secho( - "Initialize resource: SUCCESS", fg="green", bold=True - ) - elif "download" in modules: - try: + click.secho("Initialize resource: SUCCESS", fg="green", bold=True) + elif "download" in modules: cursor.execute(DOWNLOAD) - except Exception as e: - tk.error_shout(e) - sys.exit(1) - else: - click.secho( - "Initialize download: SUCCESS", fg="green", bold=True - ) + click.secho("Initialize download: SUCCESS", fg="green", bold=True) + except Exception as e: + tk.error_shout(e) + sys.exit(1) connection.commit() From 9d028983646bf4e5035d08f9cd5c4e14601d0e74 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 08:53:34 +0900 Subject: [PATCH 32/58] move README.md about ckan command from misc to docs --- development/docs/README.md | 87 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 development/docs/README.md diff --git a/development/docs/README.md b/development/docs/README.md new file mode 100644 index 00000000..cb77e8e8 --- /dev/null +++ b/development/docs/README.md @@ -0,0 +1,87 @@ +# ckan feedback init + +## 概要 + +指定した機能に関係するPostgreSQLのテーブルを初期化する。 + +## 実行 + +``` +ckan feedback init [options] +``` + +### オプション + +#### -m, --modules < utilization/ resource/ download > + +**任意項目** + +一部の機能を利用する場合に以下の3つから指定して実行する。(複数選択可) +このオプションの指定がない場合は全てのテーブルに対して初期化処理を行う。 +* utilization +* resource +* download + +##### 実行例 + +``` +ckan --config=/etc/ckan/production.ini feedback init +ckan --config=/etc/ckan/production.ini feedback init -m utilization +ckan --config=/etc/ckan/production.ini feedback init -m resource -m download +``` + +#### -h, --host + +**任意項目** + +PosgreSQLコンテナのホスト名を指定する。 +指定しない場合、以下の順で参照された値を使用する。 +1. 環境変数 ```POSTGRES_HOST``` +2. CKANのデフォルト値 ```db``` + +#### -p, --port + +**任意項目** + +PosgreSQLコンテナのポート番号を指定する。 +指定しない場合、以下の順で参照された値を使用する。 +1. 環境変数 ```POSTGRES_PORT``` +2. CKANのデフォルト値 ```5432``` + +#### -d, --dbname + +**任意項目** + +PosgreSQLのデータベース名を指定する。 +指定しない場合、以下の順で参照された値を使用する。 +1. 環境変数 ```POSTGRES_DB``` +2. CKANのデフォルト値 ```ckan``` + +#### -u, --user + +**任意項目** + +PosgreSQLに接続するためのユーザ名を指定する。 +指定しない場合、以下の順で参照された値を使用する。 +1. 環境変数 ```POSTGRES_USER``` +2. CKANのデフォルト値 ```ckan``` + +#### -P, --password + +**任意項目** + +PosgreSQLに接続するためのパスワードを指定する。 +指定しない場合、以下の順で参照された値を使用する。 +1. 環境変数 ```POSTGRES_PASSWORD``` +2. CKANのデフォルト値 ```ckan``` + +##### 実行例 + +``` +ckan --config=/etc/ckan/production.ini feedback init -h postgresdb +ckan --config=/etc/ckan/production.ini feedback init -p 5000 +ckan --config=/etc/ckan/production.ini feedback init -d ckandb +ckan --config=/etc/ckan/production.ini feedback init -u root +ckan --config=/etc/ckan/production.ini feedback init -P root +ckan --config=/etc/ckan/production.ini feedback init -h postgresdb -u root -P root +``` \ No newline at end of file From b50aaf39368f31a4bafd73d19e84ccbe2bf982dd Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 09:12:55 +0900 Subject: [PATCH 33/58] add comment to example code --- development/docs/README.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/development/docs/README.md b/development/docs/README.md index cb77e8e8..6059951b 100644 --- a/development/docs/README.md +++ b/development/docs/README.md @@ -25,8 +25,19 @@ ckan feedback init [options] ##### 実行例 ``` +# ckanext-feedback plugins に関わる全てのテーブルに対して初期化を行う ckan --config=/etc/ckan/production.ini feedback init + +# utilization(利活用方法)機能に関わるテーブルに対して初期化を行う ckan --config=/etc/ckan/production.ini feedback init -m utilization + +# resource(データリソース)機能に関わるテーブルに対して初期化を行う +ckan --config=/etc/ckan/production.ini feedback init -m resource + +# download(ダウンロード)機能に関わるテーブルに対して初期化を行う +ckan --config=/etc/ckan/production.ini feedback init -m download + +# resource(データリソース)機能とdownload(ダウンロード)機能に関わるテーブルに対して初期化を行う ckan --config=/etc/ckan/production.ini feedback init -m resource -m download ``` @@ -78,10 +89,21 @@ PosgreSQLに接続するためのパスワードを指定する。 ##### 実行例 ``` +# ホスト名として"postgresdb"を指定する ckan --config=/etc/ckan/production.ini feedback init -h postgresdb + +# ポート番号として"5000"を指定する ckan --config=/etc/ckan/production.ini feedback init -p 5000 + +# データベース名として"ckandb"を指定する ckan --config=/etc/ckan/production.ini feedback init -d ckandb + +# ユーザ名として"root"を指定する ckan --config=/etc/ckan/production.ini feedback init -u root + +# パスワードとして"root"を指定する ckan --config=/etc/ckan/production.ini feedback init -P root + +# ホスト名として"postgresdb", ユーザ名として"root", パスワードとして"root"を指定する ckan --config=/etc/ckan/production.ini feedback init -h postgresdb -u root -P root ``` \ No newline at end of file From 66e453861994f27b719a8b7f643b270ebee37f17 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 10:36:13 +0900 Subject: [PATCH 34/58] delete cli.py and modify setup.sh because of movement of feedback.py --- development/misc/cli.py | 223 ---------------------------------------- development/setup.sh | 5 +- 2 files changed, 1 insertion(+), 227 deletions(-) delete mode 100644 development/misc/cli.py diff --git a/development/misc/cli.py b/development/misc/cli.py deleted file mode 100644 index e7625e1b..00000000 --- a/development/misc/cli.py +++ /dev/null @@ -1,223 +0,0 @@ -# encoding: utf-8 - -import logging -from collections import defaultdict -from pkg_resources import iter_entry_points - -import six -import click -import sys - -import ckan.plugins as p -import ckan.cli as ckan_cli -from ckan.config.middleware import make_app -from ckan.exceptions import CkanConfigurationException -from ckan.cli import ( - config_tool, - jobs, - front_end_build, - db, search_index, server, - profile, - asset, - sysadmin, - translation, - dataset, - views, - plugin_info, - notify, - tracking, - minify, - less, - generate, - user, -) - -from ckan.cli import seed - -META_ATTR = u'_ckan_meta' -CMD_TYPE_PLUGIN = u'plugin' -CMD_TYPE_ENTRY = u'entry_point' - -log = logging.getLogger(__name__) - -_no_config_commands = [ - [u'config-tool'], - [u'generate', u'config'], - [u'generate', u'extension'], -] - - -class CtxObject(object): - - def __init__(self, conf=None): - # Don't import `load_config` by itself, rather call it using - # module so that it can be patched during tests - self.config = ckan_cli.load_config(conf) - self.app = make_app(self.config) - - -class ExtendableGroup(click.Group): - _section_titles = { - CMD_TYPE_PLUGIN: u'Plugins', - CMD_TYPE_ENTRY: u'Entry points', - } - - def format_commands(self, ctx, formatter): - """Print help message. - - Includes information about commands that were registered by extensions. - """ - # click won't parse config file from envvar if no other options - # provided, except for `--help`. In this case it has to be done - # manually. - if not ctx.obj: - _add_ctx_object(ctx) - _add_external_commands(ctx) - - commands = [] - ext_commands = defaultdict(lambda: defaultdict(list)) - - for subcommand in self.list_commands(ctx): - cmd = self.get_command(ctx, subcommand) - if cmd is None: - continue - if cmd.hidden: - continue - help = cmd.short_help or u'' - - meta = getattr(cmd, META_ATTR, None) - if meta: - ext_commands[meta[u'type']][meta[u'name']].append( - (subcommand, help)) - else: - commands.append((subcommand, help)) - - if commands: - with formatter.section(u'Commands'): - formatter.write_dl(commands) - - for section, group in ext_commands.items(): - with formatter.section(self._section_titles.get(section, section)): - for rows in group.values(): - formatter.write_dl(rows) - - def parse_args(self, ctx, args): - """Preprocess options and arguments. - - As long as at least one option is provided, click won't fallback to - printing help message. That means that `ckan -c config.ini` will be - executed as command, instead of just printing help message(as `ckan -c - config.ini --help`). - In order to fix it, we have to check whether there is at least one - argument. If no, let's print help message manually - - """ - result = super(ExtendableGroup, self).parse_args(ctx, args) - if not ctx.protected_args and not ctx.args: - click.echo(ctx.get_help(), color=ctx.color) - ctx.exit() - return result - - -def _init_ckan_config(ctx, param, value): - if any(sys.argv[1:len(cmd) + 1] == cmd for cmd in _no_config_commands): - return - _add_ctx_object(ctx, value) - _add_external_commands(ctx) - - -def _add_ctx_object(ctx, path=None): - """Initialize CKAN App using config file available under provided path. - - """ - try: - ctx.obj = CtxObject(path) - except CkanConfigurationException as e: - p.toolkit.error_shout(e) - ctx.abort() - - if six.PY2: - ctx.meta["flask_app"] = ctx.obj.app.apps["flask_app"]._wsgi_app - else: - ctx.meta["flask_app"] = ctx.obj.app._wsgi_app - - -def _add_external_commands(ctx): - for cmd in _get_commands_from_entry_point(): - ctx.command.add_command(cmd) - - plugins = p.PluginImplementations(p.IClick) - for cmd in _get_commands_from_plugins(plugins): - ctx.command.add_command(cmd) - - -def _command_with_ckan_meta(cmd, name, type_): - """Mark command as one retrived from CKAN extension. - - This information is used when CLI help text is generated. - """ - setattr(cmd, META_ATTR, {u'name': name, u'type': type_}) - return cmd - - -def _get_commands_from_plugins(plugins): - """Register commands that are available when plugin enabled. - - """ - for plugin in plugins: - for cmd in plugin.get_commands(): - yield _command_with_ckan_meta(cmd, plugin.name, CMD_TYPE_PLUGIN) - - -def _get_commands_from_entry_point(entry_point=u'ckan.click_command'): - """Register commands that are available even if plugin is not enabled. - - """ - registered_entries = {} - for entry in iter_entry_points(entry_point): - if entry.name in registered_entries: - p.toolkit.error_shout(( - u'Attempt to override entry_point `{name}`.\n' - u'First encounter:\n\t{first!r}\n' - u'Second encounter:\n\t{second!r}\n' - u'Either uninstall one of mentioned extensions or update' - u' corresponding `setup.py` and re-install the extension.' - ).format( - name=entry.name, - first=registered_entries[entry.name].dist, - second=entry.dist)) - raise click.Abort() - registered_entries[entry.name] = entry - - yield _command_with_ckan_meta(entry.load(), entry.name, CMD_TYPE_ENTRY) - - -@click.group(cls=ExtendableGroup) -@click.option(u'-c', u'--config', metavar=u'CONFIG', - is_eager=True, callback=_init_ckan_config, expose_value=False, - help=u'Config file to use (default: ckan.ini)') -@click.help_option(u'-h', u'--help') -def ckan(): - pass - - -ckan.add_command(jobs.jobs) -ckan.add_command(config_tool.config_tool) -ckan.add_command(front_end_build.front_end_build) -ckan.add_command(server.run) -ckan.add_command(profile.profile) -ckan.add_command(seed.seed) -ckan.add_command(db.db) -ckan.add_command(search_index.search_index) -ckan.add_command(sysadmin.sysadmin) -ckan.add_command(asset.asset) -ckan.add_command(translation.translation) -ckan.add_command(dataset.dataset) -ckan.add_command(views.views) -ckan.add_command(plugin_info.plugin_info) -ckan.add_command(notify.notify) -ckan.add_command(tracking.tracking) -ckan.add_command(minify.minify) -ckan.add_command(less.less) -ckan.add_command(generate.generate) -ckan.add_command(user.user) diff --git a/development/setup.sh b/development/setup.sh index 99d975d9..80956584 100755 --- a/development/setup.sh +++ b/development/setup.sh @@ -4,7 +4,4 @@ git submodule update --init --recursive # Copy docker/.env.template as .env cp external/ckan/contrib/docker/.env.template external/ckan/contrib/docker/.env # Build and compose docker containers -docker compose -f external/ckan/contrib/docker/docker-compose.yml -f docker-compose.yml up --build -d -# Copy cli.py and create.py to the CKAN container ckan/cli/ folder -docker cp misc/cli.py ckan:/usr/lib/ckan/venv/src/ckan/ckan/cli/cli.py -docker cp misc/create.py ckan:/usr/lib/ckan/venv/src/ckan/ckan/cli/create.py +docker compose -f external/ckan/contrib/docker/docker-compose.yml -f docker-compose.yml up --build -d \ No newline at end of file From b3fda2d7dcc016168033d2e968188de49108f286 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 10:46:32 +0900 Subject: [PATCH 35/58] change double-quart to single-quart --- ckanext/feedback/feedback.py | 68 ++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 34 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index 14c90720..8c3e25c7 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -5,7 +5,7 @@ import ckan.plugins.toolkit as tk -CLEAN = """ +CLEAN = ''' DROP TABLE IF EXISTS utilization CASCADE; DROP TABLE IF EXISTS utilization_feedback CASCADE; DROP TABLE IF EXISTS utilization_feedback_reply CASCADE; @@ -14,9 +14,9 @@ DROP TABLE IF EXISTS resource_feedback_reply CASCADE; DROP TYPE IF EXISTS genre1; DROP TYPE IF EXISTS genre2; - """ + ''' -UTILIZATION = """ +UTILIZATION = ''' CREATE TABLE utilization ( id TEXT NOT NULL, resource_id TEXT NOT NULL, @@ -30,7 +30,7 @@ FOREIGN KEY (resource_id) REFERENCES resource (id) ); - CREATE TYPE genre1 AS ENUM ("1", "2"); + CREATE TYPE genre1 AS ENUM ('1', '2'); CREATE TABLE utilization_feedback ( id TEXT NOT NULL, utilization_id TEXT NOT NULL, @@ -52,10 +52,10 @@ PRIMARY KEY (id), FOREIGN KEY (utilization_feedback_id) REFERENCES utilization_feedback (id) ); - """ + ''' -RESOURCE = """ - CREATE TYPE genre2 AS ENUM ("1", "2"); +RESOURCE = ''' + CREATE TYPE genre2 AS ENUM ('1', '2'); CREATE TABLE resource_feedback ( id TEXT NOT NULL, resource_id TEXT NOT NULL, @@ -79,9 +79,9 @@ FOREIGN KEY (resource_feedback_id) REFERENCES resource_feedback (id) ); - """ + ''' -DOWNLOAD = """ +DOWNLOAD = ''' CREATE TABLE utilization_summary ( id TEXT NOT NULL, resource_id TEXT NOT NULL, @@ -93,18 +93,18 @@ PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - """ + ''' @click.group() def feedback(): - """CLI tool for ckanext-feedback plugin.""" + '''CLI tool for ckanext-feedback plugin.''' def get_connection(host, port, dbname, user, password): try: connector = psycopg2.connect( - "postgresql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}".format( + 'postgresql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}'.format( db_user=user, db_password=password, db_host=host, @@ -120,52 +120,52 @@ def get_connection(host, port, dbname, user, password): @feedback.command( - name="init", short_help="create tables in ckan db to activate modules." + name='init', short_help='create tables in ckan db to activate modules.' ) @click.option( - "-m", - "--modules", + '-m', + '--modules', multiple=True, - type=click.Choice(["utilization", "resource", "download"]), - help="specify the module you want to use from "utilization", "resource", "download"", + type=click.Choice(['utilization', 'resource', 'download']), + help='specify the module you want to use from utilization, resource, download', ) @click.option( - "-h", "--host", envvar="POSTGRES_HOST", default="db", help="specify the host name of postgresql" + '-h', '--host', envvar='POSTGRES_HOST', default='db', help='specify the host name of postgresql' ) @click.option( - "-p", "--port", envvar="POSTGRES_PORT", default="5432", help="specify the port number of postgresql" + '-p', '--port', envvar='POSTGRES_PORT', default='5432', help='specify the port number of postgresql' ) -@click.option("-d", "--dbname", envvar="POSTGRES_DB", default="ckan", help="specify the name of postgresql") +@click.option('-d', '--dbname', envvar='POSTGRES_DB', default='ckan', help='specify the name of postgresql') @click.option( - "-u", "--user", envvar="POSTGRES_USER", default="ckan", help="specify the user name of postgresql" + '-u', '--user', envvar='POSTGRES_USER', default='ckan', help='specify the user name of postgresql' ) @click.option( - "-P", - "--password", - envvar="POSTGRES_PASSWORD", - default="ckan", - help="specify the password to connect postgresql", + '-P', + '--password', + envvar='POSTGRES_PASSWORD', + default='ckan', + help='specify the password to connect postgresql', ) def init(modules, host, port, dbname, user, password): with get_connection(host, port, dbname, user, password) as connection: with connection.cursor() as cursor: try: cursor.execute(CLEAN) - click.secho("Clean all modules: SUCCESS", fg="green", bold=True) + click.secho('Clean all modules: SUCCESS', fg='green', bold=True) if not modules: cursor.execute(UTILIZATION) cursor.execute(RESOURCE) cursor.execute(DOWNLOAD) - click.secho("Initialize all modules: SUCCESS", fg="green", bold=True) - elif "utilization" in modules: + click.secho('Initialize all modules: SUCCESS', fg='green', bold=True) + elif 'utilization' in modules: cursor.execute(UTILIZATION) - click.secho("Initialize utilization: SUCCESS", fg="green", bold=True) - elif "resource" in modules: + click.secho('Initialize utilization: SUCCESS', fg='green', bold=True) + elif 'resource' in modules: cursor.execute(RESOURCE) - click.secho("Initialize resource: SUCCESS", fg="green", bold=True) - elif "download" in modules: + click.secho('Initialize resource: SUCCESS', fg='green', bold=True) + elif 'download' in modules: cursor.execute(DOWNLOAD) - click.secho("Initialize download: SUCCESS", fg="green", bold=True) + click.secho('Initialize download: SUCCESS', fg='green', bold=True) except Exception as e: tk.error_shout(e) sys.exit(1) From 844b9f142e3fd9fc3d452d02339f24715d4e6e1a Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 11:00:14 +0900 Subject: [PATCH 36/58] add explanation about config file --- development/docs/README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/development/docs/README.md b/development/docs/README.md index 6059951b..ac950f36 100644 --- a/development/docs/README.md +++ b/development/docs/README.md @@ -41,6 +41,8 @@ ckan --config=/etc/ckan/production.ini feedback init -m download ckan --config=/etc/ckan/production.ini feedback init -m resource -m download ``` +※ ckanコマンドを実行する際は```--config=/etc/ckan/production.ini```としてconfigファイルを指定する必要がある + #### -h, --host **任意項目** From 46967786b29bd7424498246689877fdf7fe5f55a Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 11:01:28 +0900 Subject: [PATCH 37/58] modify explanation about config file --- development/docs/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/development/docs/README.md b/development/docs/README.md index ac950f36..5ef6c2f0 100644 --- a/development/docs/README.md +++ b/development/docs/README.md @@ -41,7 +41,7 @@ ckan --config=/etc/ckan/production.ini feedback init -m download ckan --config=/etc/ckan/production.ini feedback init -m resource -m download ``` -※ ckanコマンドを実行する際は```--config=/etc/ckan/production.ini```としてconfigファイルを指定する必要がある +※ ckanコマンドを実行する際は```--config=/etc/ckan/production.ini```と記述して、configファイルを指定する必要がある #### -h, --host From 69ecccefd05c2515f101663c08ff46c6eacd7ee9 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 11:21:12 +0900 Subject: [PATCH 38/58] create function of drop tables and delete sql sentences --- ckanext/feedback/feedback.py | 38 ++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index 8c3e25c7..d5c8719d 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -5,17 +5,6 @@ import ckan.plugins.toolkit as tk -CLEAN = ''' - DROP TABLE IF EXISTS utilization CASCADE; - DROP TABLE IF EXISTS utilization_feedback CASCADE; - DROP TABLE IF EXISTS utilization_feedback_reply CASCADE; - DROP TABLE IF EXISTS utilization_summary CASCADE; - DROP TABLE IF EXISTS resource_feedback CASCADE; - DROP TABLE IF EXISTS resource_feedback_reply CASCADE; - DROP TYPE IF EXISTS genre1; - DROP TYPE IF EXISTS genre2; - ''' - UTILIZATION = ''' CREATE TABLE utilization ( id TEXT NOT NULL, @@ -150,7 +139,9 @@ def init(modules, host, port, dbname, user, password): with get_connection(host, port, dbname, user, password) as connection: with connection.cursor() as cursor: try: - cursor.execute(CLEAN) + _drop_utilization_tables(cursor) + _drop_resource_tables(cursor) + _drop_download_tables(cursor) click.secho('Clean all modules: SUCCESS', fg='green', bold=True) if not modules: cursor.execute(UTILIZATION) @@ -170,4 +161,27 @@ def init(modules, host, port, dbname, user, password): tk.error_shout(e) sys.exit(1) + def _drop_utilization_tables(cursor): + cursor.execute(""" + DROP TABLE IF EXISTS utilization CASCADE; + DROP TABLE IF EXISTS issue_resolution_summary CASCADE; + DROP TABLE IF EXISTS issue_resolution CASCADE; + DROP TABLE IF EXISTS utilization_comment CASCADE; + DROP TABLE IF EXISTS utilization_summary CASCADE; + DROP TYPE IF EXISTS genre1; + """) + + def _drop_resource_tables(cursor): + cursor.execute(""" + DROP TABLE IF EXISTS resource_comment CASCADE; + DROP TABLE IF EXISTS resource_comment_reply CASCADE; + DROP TABLE IF EXISTS resource_comment_summary CASCADE; + DROP TYPE IF EXISTS genre2; + """) + + def _drop_download_tables(cursor): + cursor.execute(""" + DROP TABLE IF EXISTS download_summary CASCADE; + """) + connection.commit() From 926250cc6c675be9fc6fd47fb4cbb3fdab7cde87 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 11:39:49 +0900 Subject: [PATCH 39/58] create function of creating utilization tables --- ckanext/feedback/feedback.py | 68 ++++++++++++++++++++++++++++++++++-- 1 file changed, 66 insertions(+), 2 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index d5c8719d..055a2cf3 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -144,12 +144,12 @@ def init(modules, host, port, dbname, user, password): _drop_download_tables(cursor) click.secho('Clean all modules: SUCCESS', fg='green', bold=True) if not modules: - cursor.execute(UTILIZATION) + _create_utilization_tables(cursor) cursor.execute(RESOURCE) cursor.execute(DOWNLOAD) click.secho('Initialize all modules: SUCCESS', fg='green', bold=True) elif 'utilization' in modules: - cursor.execute(UTILIZATION) + _create_utilization_tables(cursor) click.secho('Initialize utilization: SUCCESS', fg='green', bold=True) elif 'resource' in modules: cursor.execute(RESOURCE) @@ -184,4 +184,68 @@ def _drop_download_tables(cursor): DROP TABLE IF EXISTS download_summary CASCADE; """) + def _create_utilization_tables(cursor): + cursor.execute(""" + CREATE TABLE utilization ( + id TEXT NOT NULL, + resource_id TEXT NOT NULL, + title TEXT, + description TEXT, + created TIMESTAMP, + approval BOOLEAN DEFAULT false, + approved TIMESTAMP, + approval_user_id TEXT, + PRIMARY KEY (id), + FOREIGN KEY (resource_id) REFERENCES resource (id), + FOREIGN KEY (approval_user_id) REFERENCES user (id) + ); + + CREATE TABLE issue_resolution_summary ( + id TEXT NOT NULL, + utilization_id TEXT NOT NULL, + issue_resolution INTEGER, + created TIMESTAMP, + updated TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (utilization_id) REFERENCES utilization (id) + ); + + CREATE TABLE issue_resolution ( + id TEXT NOT NULL, + utilization_id TEXT NOT NULL, + description TEXT, + created TIMESTAMP, + creator_user_id TEXT, + PRIMARY KEY (id), + FOREIGN KEY (utilization_id) REFERENCES utilization (id), + FOREIGN KEY (creator_user_id) REFERENCES user (id) + ); + + CREATE TYPE genre1 AS ENUM ('1', '2'); + CREATE TABLE utilization_comment ( + id TEXT NOT NULL, + utilization_id TEXT NOT NULL, + category genre1 NOT NULL, + content TEXT, + created TIMESTAMP, + approval BOOLEAN DEFAULT false, + approved TIMESTAMP, + approval_user_id TEXT, + PRIMARY KEY (id), + FOREIGN KEY (utilization_id) REFERENCES utilization (id), + FOREIGN KEY (approval_user_id) REFERENCES user (id) + ); + + CREATE TABLE utilization_summary ( + id TEXT NOT NULL, + resource_id TEXT NOT NULL, + utilization INTEGER, + comment INTEGER, + created TIMESTAMP, + updated TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (resource_id) REFERENCES resource (id) + ); + """) + connection.commit() From fe4c4442cb3d2f413225b7fabd9f14eb3c2c07ef Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 11:49:40 +0900 Subject: [PATCH 40/58] create function of creating resource tables --- ckanext/feedback/feedback.py | 106 ++++++++++++++--------------------- 1 file changed, 41 insertions(+), 65 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index 055a2cf3..a4b92a2b 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -5,71 +5,6 @@ import ckan.plugins.toolkit as tk -UTILIZATION = ''' - CREATE TABLE utilization ( - id TEXT NOT NULL, - resource_id TEXT NOT NULL, - title TEXT, - url TEXT, - description TEXT, - created TIMESTAMP, - approval BOOLEAN DEFAULT false, - approved TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY (resource_id) REFERENCES resource (id) - ); - - CREATE TYPE genre1 AS ENUM ('1', '2'); - CREATE TABLE utilization_feedback ( - id TEXT NOT NULL, - utilization_id TEXT NOT NULL, - type genre1 NOT NULL, - description TEXT, - created TIMESTAMP, - approval BOOLEAN DEFAULT false, - approved TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY (utilization_id) REFERENCES utilization (id) - ); - - CREATE TABLE utilization_feedback_reply ( - id TEXT NOT NULL, - utilization_feedback_id TEXT NOT NULL, - description TEXT, - created TIMESTAMP, - creator_user_id TEXT, - PRIMARY KEY (id), - FOREIGN KEY (utilization_feedback_id) REFERENCES utilization_feedback (id) - ); - ''' - -RESOURCE = ''' - CREATE TYPE genre2 AS ENUM ('1', '2'); - CREATE TABLE resource_feedback ( - id TEXT NOT NULL, - resource_id TEXT NOT NULL, - type genre2 NOT NULL, - description TEXT, - rating INTEGER, - created TIMESTAMP, - approval BOOLEAN DEFAULT false, - approved TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY (resource_id) REFERENCES resource (id) - ); - - CREATE TABLE resource_feedback_reply ( - id TEXT NOT NULL, - resource_feedback_id TEXT NOT NULL, - description TEXT, - created TIMESTAMP, - creator_user_id TEXT, - PRIMARY KEY (id), - FOREIGN KEY (resource_feedback_id) REFERENCES resource_feedback (id) - - ); - ''' - DOWNLOAD = ''' CREATE TABLE utilization_summary ( id TEXT NOT NULL, @@ -248,4 +183,45 @@ def _create_utilization_tables(cursor): ); """) + def _create_resource_tabels(cursor): + cursor.execute(""" + CREATE TYPE genre2 AS ENUM ('1', '2'); + CREATE TABLE resource_comment ( + id TEXT NOT NULL, + resource_id TEXT NOT NULL, + category genre2 NOT NULL, + content TEXT, + rating INTEGER, + created TIMESTAMP, + approval BOOLEAN DEFAULT false, + approved TIMESTAMP, + approval_user_id TEXT, + PRIMARY KEY (id), + FOREIGN KEY (resource_id) REFERENCES resource (id), + FOREIGN KEY (approval_user_id) REFERENCES user (id) + ); + + CREATE TABLE resource_comment_reply ( + id TEXT NOT NULL, + resource_comment_id TEXT NOT NULL, + content TEXT, + created TIMESTAMP, + creator_user_id TEXT, + PRIMARY KEY (id), + FOREIGN KEY (resource_comment_id) REFERENCES resource_comment (id), + FOREIGN KEY (creator_user_id) REFERENCES user (id) + ); + + CREATE TABLE reource_comment_summary ( + id TEXT NOT NULL, + resource_id TEXT NOT NULL, + comment INTEGER, + rating NUMERIC, + created TIMESTAMP, + updated TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (resource_id) REFERENCES resource (id) + ); + """) + connection.commit() From 049c92664016c4874cf0b8d2177e1e07cc1266fb Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 11:53:39 +0900 Subject: [PATCH 41/58] create function of creating download tables --- ckanext/feedback/feedback.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index a4b92a2b..6088c8f4 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -5,21 +5,6 @@ import ckan.plugins.toolkit as tk -DOWNLOAD = ''' - CREATE TABLE utilization_summary ( - id TEXT NOT NULL, - resource_id TEXT NOT NULL, - utilization INTEGER, - download INTEGER, - issue_resolution INTEGER, - created TIMESTAMP, - updated TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY (resource_id) REFERENCES resource (id) - ); - ''' - - @click.group() def feedback(): '''CLI tool for ckanext-feedback plugin.''' @@ -224,4 +209,17 @@ def _create_resource_tabels(cursor): ); """) + def _create_download_tables(cursor): + cursor.execute(""" + CREATE TABLE download_summary ( + id TEXT NOT NULL, + resource_id TEXT NOT NULL, + download INTEGER, + created TIMESTAMP, + updated TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (resource_id) REFERENCES resource (id) + ); + """) + connection.commit() From e5addfe1531411bbc512d53804bed7597deaa034 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 11:54:25 +0900 Subject: [PATCH 42/58] change double-quart to single-quart of sql sentences --- ckanext/feedback/feedback.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index 6088c8f4..515fb08e 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -82,30 +82,30 @@ def init(modules, host, port, dbname, user, password): sys.exit(1) def _drop_utilization_tables(cursor): - cursor.execute(""" + cursor.execute(''' DROP TABLE IF EXISTS utilization CASCADE; DROP TABLE IF EXISTS issue_resolution_summary CASCADE; DROP TABLE IF EXISTS issue_resolution CASCADE; DROP TABLE IF EXISTS utilization_comment CASCADE; DROP TABLE IF EXISTS utilization_summary CASCADE; DROP TYPE IF EXISTS genre1; - """) + ''') def _drop_resource_tables(cursor): - cursor.execute(""" + cursor.execute(''' DROP TABLE IF EXISTS resource_comment CASCADE; DROP TABLE IF EXISTS resource_comment_reply CASCADE; DROP TABLE IF EXISTS resource_comment_summary CASCADE; DROP TYPE IF EXISTS genre2; - """) + ''') def _drop_download_tables(cursor): - cursor.execute(""" + cursor.execute(''' DROP TABLE IF EXISTS download_summary CASCADE; - """) + ''') def _create_utilization_tables(cursor): - cursor.execute(""" + cursor.execute(''' CREATE TABLE utilization ( id TEXT NOT NULL, resource_id TEXT NOT NULL, @@ -166,10 +166,10 @@ def _create_utilization_tables(cursor): PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - """) + ''') def _create_resource_tabels(cursor): - cursor.execute(""" + cursor.execute(''' CREATE TYPE genre2 AS ENUM ('1', '2'); CREATE TABLE resource_comment ( id TEXT NOT NULL, @@ -207,10 +207,10 @@ def _create_resource_tabels(cursor): PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - """) + ''') def _create_download_tables(cursor): - cursor.execute(""" + cursor.execute(''' CREATE TABLE download_summary ( id TEXT NOT NULL, resource_id TEXT NOT NULL, @@ -220,6 +220,6 @@ def _create_download_tables(cursor): PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - """) + ''') connection.commit() From c65ceb22c172ec16a1b0a985e3b3417c680cf251 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 12:03:44 +0900 Subject: [PATCH 43/58] use linter and formatter --- ckanext/feedback/feedback.py | 86 +++++++++++++++++++++++++----------- 1 file changed, 60 insertions(+), 26 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index 515fb08e..e1f3c920 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -1,10 +1,10 @@ -import os import sys import psycopg2 import click import ckan.plugins.toolkit as tk + @click.group() def feedback(): '''CLI tool for ckanext-feedback plugin.''' @@ -18,7 +18,7 @@ def get_connection(host, port, dbname, user, password): db_password=password, db_host=host, db_port=port, - db_name=name, + db_name=dbname, ) ) except Exception as e: @@ -39,14 +39,32 @@ def get_connection(host, port, dbname, user, password): help='specify the module you want to use from utilization, resource, download', ) @click.option( - '-h', '--host', envvar='POSTGRES_HOST', default='db', help='specify the host name of postgresql' + '-h', + '--host', + envvar='POSTGRES_HOST', + default='db', + help='specify the host name of postgresql', +) +@click.option( + '-p', + '--port', + envvar='POSTGRES_PORT', + default='5432', + help='specify the port number of postgresql', ) @click.option( - '-p', '--port', envvar='POSTGRES_PORT', default='5432', help='specify the port number of postgresql' + '-d', + '--dbname', + envvar='POSTGRES_DB', + default='ckan', + help='specify the name of postgresql', ) -@click.option('-d', '--dbname', envvar='POSTGRES_DB', default='ckan', help='specify the name of postgresql') @click.option( - '-u', '--user', envvar='POSTGRES_USER', default='ckan', help='specify the user name of postgresql' + '-u', + '--user', + envvar='POSTGRES_USER', + default='ckan', + help='specify the user name of postgresql', ) @click.option( '-P', @@ -65,47 +83,60 @@ def init(modules, host, port, dbname, user, password): click.secho('Clean all modules: SUCCESS', fg='green', bold=True) if not modules: _create_utilization_tables(cursor) - cursor.execute(RESOURCE) - cursor.execute(DOWNLOAD) - click.secho('Initialize all modules: SUCCESS', fg='green', bold=True) + _create_resource_tabels(cursor) + _create_download_tables(cursor) + click.secho( + 'Initialize all modules: SUCCESS', fg='green', bold=True + ) elif 'utilization' in modules: _create_utilization_tables(cursor) - click.secho('Initialize utilization: SUCCESS', fg='green', bold=True) + click.secho( + 'Initialize utilization: SUCCESS', fg='green', bold=True + ) elif 'resource' in modules: - cursor.execute(RESOURCE) + _create_resource_tabels(cursor) click.secho('Initialize resource: SUCCESS', fg='green', bold=True) elif 'download' in modules: - cursor.execute(DOWNLOAD) + _create_download_tables(cursor) click.secho('Initialize download: SUCCESS', fg='green', bold=True) except Exception as e: tk.error_shout(e) sys.exit(1) + connection.commit() + def _drop_utilization_tables(cursor): - cursor.execute(''' + cursor.execute( + ''' DROP TABLE IF EXISTS utilization CASCADE; DROP TABLE IF EXISTS issue_resolution_summary CASCADE; DROP TABLE IF EXISTS issue_resolution CASCADE; DROP TABLE IF EXISTS utilization_comment CASCADE; DROP TABLE IF EXISTS utilization_summary CASCADE; DROP TYPE IF EXISTS genre1; - ''') + ''' + ) def _drop_resource_tables(cursor): - cursor.execute(''' + cursor.execute( + ''' DROP TABLE IF EXISTS resource_comment CASCADE; DROP TABLE IF EXISTS resource_comment_reply CASCADE; DROP TABLE IF EXISTS resource_comment_summary CASCADE; DROP TYPE IF EXISTS genre2; - ''') + ''' + ) def _drop_download_tables(cursor): - cursor.execute(''' + cursor.execute( + ''' DROP TABLE IF EXISTS download_summary CASCADE; - ''') + ''' + ) def _create_utilization_tables(cursor): - cursor.execute(''' + cursor.execute( + ''' CREATE TABLE utilization ( id TEXT NOT NULL, resource_id TEXT NOT NULL, @@ -166,10 +197,12 @@ def _create_utilization_tables(cursor): PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - ''') + ''' + ) def _create_resource_tabels(cursor): - cursor.execute(''' + cursor.execute( + ''' CREATE TYPE genre2 AS ENUM ('1', '2'); CREATE TABLE resource_comment ( id TEXT NOT NULL, @@ -207,10 +240,12 @@ def _create_resource_tabels(cursor): PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - ''') + ''' + ) def _create_download_tables(cursor): - cursor.execute(''' + cursor.execute( + ''' CREATE TABLE download_summary ( id TEXT NOT NULL, resource_id TEXT NOT NULL, @@ -220,6 +255,5 @@ def _create_download_tables(cursor): PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - ''') - - connection.commit() + ''' + ) From 9cd96ead1406fc11d5b7093bbce5314e6d8b6461 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 14:39:41 +0900 Subject: [PATCH 44/58] test in container and fix some bugs --- ckanext/feedback/feedback.py | 232 ++++++++++++++++++----------------- 1 file changed, 119 insertions(+), 113 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index e1f3c920..4185fa3c 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -105,72 +105,76 @@ def init(modules, host, port, dbname, user, password): connection.commit() - def _drop_utilization_tables(cursor): - cursor.execute( - ''' - DROP TABLE IF EXISTS utilization CASCADE; - DROP TABLE IF EXISTS issue_resolution_summary CASCADE; - DROP TABLE IF EXISTS issue_resolution CASCADE; - DROP TABLE IF EXISTS utilization_comment CASCADE; - DROP TABLE IF EXISTS utilization_summary CASCADE; - DROP TYPE IF EXISTS genre1; + +def _drop_utilization_tables(cursor): + cursor.execute( ''' - ) + DROP TABLE IF EXISTS utilization CASCADE; + DROP TABLE IF EXISTS issue_resolution_summary CASCADE; + DROP TABLE IF EXISTS issue_resolution CASCADE; + DROP TABLE IF EXISTS utilization_comment CASCADE; + DROP TABLE IF EXISTS utilization_summary CASCADE; + DROP TYPE IF EXISTS genre1; + ''' + ) - def _drop_resource_tables(cursor): - cursor.execute( - ''' - DROP TABLE IF EXISTS resource_comment CASCADE; - DROP TABLE IF EXISTS resource_comment_reply CASCADE; - DROP TABLE IF EXISTS resource_comment_summary CASCADE; - DROP TYPE IF EXISTS genre2; + +def _drop_resource_tables(cursor): + cursor.execute( ''' - ) + DROP TABLE IF EXISTS resource_comment CASCADE; + DROP TABLE IF EXISTS resource_comment_reply CASCADE; + DROP TABLE IF EXISTS resource_comment_summary CASCADE; + DROP TYPE IF EXISTS genre2; + ''' + ) - def _drop_download_tables(cursor): - cursor.execute( - ''' - DROP TABLE IF EXISTS download_summary CASCADE; + +def _drop_download_tables(cursor): + cursor.execute( ''' - ) + DROP TABLE IF EXISTS download_summary CASCADE; + ''' + ) - def _create_utilization_tables(cursor): - cursor.execute( - ''' - CREATE TABLE utilization ( - id TEXT NOT NULL, - resource_id TEXT NOT NULL, - title TEXT, - description TEXT, - created TIMESTAMP, - approval BOOLEAN DEFAULT false, - approved TIMESTAMP, - approval_user_id TEXT, - PRIMARY KEY (id), - FOREIGN KEY (resource_id) REFERENCES resource (id), - FOREIGN KEY (approval_user_id) REFERENCES user (id) - ); - CREATE TABLE issue_resolution_summary ( - id TEXT NOT NULL, - utilization_id TEXT NOT NULL, - issue_resolution INTEGER, - created TIMESTAMP, - updated TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY (utilization_id) REFERENCES utilization (id) - ); +def _create_utilization_tables(cursor): + cursor.execute( + ''' + CREATE TABLE utilization ( + id TEXT NOT NULL, + resource_id TEXT NOT NULL, + title TEXT, + description TEXT, + created TIMESTAMP, + approval BOOLEAN DEFAULT false, + approved TIMESTAMP, + approval_user_id TEXT, + PRIMARY KEY (id), + FOREIGN KEY (resource_id) REFERENCES resource (id), + FOREIGN KEY (approval_user_id) REFERENCES public.user (id) + ); - CREATE TABLE issue_resolution ( - id TEXT NOT NULL, - utilization_id TEXT NOT NULL, - description TEXT, - created TIMESTAMP, - creator_user_id TEXT, - PRIMARY KEY (id), - FOREIGN KEY (utilization_id) REFERENCES utilization (id), - FOREIGN KEY (creator_user_id) REFERENCES user (id) - ); + CREATE TABLE issue_resolution_summary ( + id TEXT NOT NULL, + utilization_id TEXT NOT NULL, + issue_resolution INTEGER, + created TIMESTAMP, + updated TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (utilization_id) REFERENCES utilization (id) + ); + + CREATE TABLE issue_resolution ( + id TEXT NOT NULL, + utilization_id TEXT NOT NULL, + description TEXT, + created TIMESTAMP, + creator_user_id TEXT, + PRIMARY KEY (id), + FOREIGN KEY (utilization_id) REFERENCES utilization (id), + FOREIGN KEY (creator_user_id) REFERENCES public.user (id) + ); CREATE TYPE genre1 AS ENUM ('1', '2'); CREATE TABLE utilization_comment ( @@ -184,7 +188,7 @@ def _create_utilization_tables(cursor): approval_user_id TEXT, PRIMARY KEY (id), FOREIGN KEY (utilization_id) REFERENCES utilization (id), - FOREIGN KEY (approval_user_id) REFERENCES user (id) + FOREIGN KEY (approval_user_id) REFERENCES public.user (id) ); CREATE TABLE utilization_summary ( @@ -198,62 +202,64 @@ def _create_utilization_tables(cursor): FOREIGN KEY (resource_id) REFERENCES resource (id) ); ''' - ) - - def _create_resource_tabels(cursor): - cursor.execute( - ''' - CREATE TYPE genre2 AS ENUM ('1', '2'); - CREATE TABLE resource_comment ( - id TEXT NOT NULL, - resource_id TEXT NOT NULL, - category genre2 NOT NULL, - content TEXT, - rating INTEGER, - created TIMESTAMP, - approval BOOLEAN DEFAULT false, - approved TIMESTAMP, - approval_user_id TEXT, - PRIMARY KEY (id), - FOREIGN KEY (resource_id) REFERENCES resource (id), - FOREIGN KEY (approval_user_id) REFERENCES user (id) - ); + ) - CREATE TABLE resource_comment_reply ( - id TEXT NOT NULL, - resource_comment_id TEXT NOT NULL, - content TEXT, - created TIMESTAMP, - creator_user_id TEXT, - PRIMARY KEY (id), - FOREIGN KEY (resource_comment_id) REFERENCES resource_comment (id), - FOREIGN KEY (creator_user_id) REFERENCES user (id) - ); - CREATE TABLE reource_comment_summary ( - id TEXT NOT NULL, - resource_id TEXT NOT NULL, - comment INTEGER, - rating NUMERIC, - created TIMESTAMP, - updated TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY (resource_id) REFERENCES resource (id) - ); +def _create_resource_tabels(cursor): + cursor.execute( ''' - ) + CREATE TYPE genre2 AS ENUM ('1', '2'); + CREATE TABLE resource_comment ( + id TEXT NOT NULL, + resource_id TEXT NOT NULL, + category genre2 NOT NULL, + content TEXT, + rating INTEGER, + created TIMESTAMP, + approval BOOLEAN DEFAULT false, + approved TIMESTAMP, + approval_user_id TEXT, + PRIMARY KEY (id), + FOREIGN KEY (resource_id) REFERENCES resource (id), + FOREIGN KEY (approval_user_id) REFERENCES public.user (id) + ); - def _create_download_tables(cursor): - cursor.execute( - ''' - CREATE TABLE download_summary ( - id TEXT NOT NULL, - resource_id TEXT NOT NULL, - download INTEGER, - created TIMESTAMP, - updated TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY (resource_id) REFERENCES resource (id) - ); + CREATE TABLE resource_comment_reply ( + id TEXT NOT NULL, + resource_comment_id TEXT NOT NULL, + content TEXT, + created TIMESTAMP, + creator_user_id TEXT, + PRIMARY KEY (id), + FOREIGN KEY (resource_comment_id) REFERENCES resource_comment (id), + FOREIGN KEY (creator_user_id) REFERENCES public.user (id) + ); + + CREATE TABLE reource_comment_summary ( + id TEXT NOT NULL, + resource_id TEXT NOT NULL, + comment INTEGER, + rating NUMERIC, + created TIMESTAMP, + updated TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (resource_id) REFERENCES resource (id) + ); + ''' + ) + + +def _create_download_tables(cursor): + cursor.execute( ''' - ) + CREATE TABLE download_summary ( + id TEXT NOT NULL, + resource_id TEXT NOT NULL, + download INTEGER, + created TIMESTAMP, + updated TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (resource_id) REFERENCES resource (id) + ); + ''' + ) From d52b1c1e0bf9cbb503640e8771892810aff61fb4 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 14:45:42 +0900 Subject: [PATCH 45/58] change single-quart to double-quart at docstring --- ckanext/feedback/feedback.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index 4185fa3c..2d3f3a34 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -7,7 +7,7 @@ @click.group() def feedback(): - '''CLI tool for ckanext-feedback plugin.''' + """CLI tool for ckanext-feedback plugin.""" def get_connection(host, port, dbname, user, password): @@ -108,39 +108,39 @@ def init(modules, host, port, dbname, user, password): def _drop_utilization_tables(cursor): cursor.execute( - ''' + """ DROP TABLE IF EXISTS utilization CASCADE; DROP TABLE IF EXISTS issue_resolution_summary CASCADE; DROP TABLE IF EXISTS issue_resolution CASCADE; DROP TABLE IF EXISTS utilization_comment CASCADE; DROP TABLE IF EXISTS utilization_summary CASCADE; DROP TYPE IF EXISTS genre1; - ''' + """ ) def _drop_resource_tables(cursor): cursor.execute( - ''' + """ DROP TABLE IF EXISTS resource_comment CASCADE; DROP TABLE IF EXISTS resource_comment_reply CASCADE; DROP TABLE IF EXISTS resource_comment_summary CASCADE; DROP TYPE IF EXISTS genre2; - ''' + """ ) def _drop_download_tables(cursor): cursor.execute( - ''' + """ DROP TABLE IF EXISTS download_summary CASCADE; - ''' + """ ) def _create_utilization_tables(cursor): cursor.execute( - ''' + """ CREATE TABLE utilization ( id TEXT NOT NULL, resource_id TEXT NOT NULL, @@ -201,13 +201,13 @@ def _create_utilization_tables(cursor): PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - ''' + """ ) def _create_resource_tabels(cursor): cursor.execute( - ''' + """ CREATE TYPE genre2 AS ENUM ('1', '2'); CREATE TABLE resource_comment ( id TEXT NOT NULL, @@ -245,13 +245,13 @@ def _create_resource_tabels(cursor): PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - ''' + """ ) def _create_download_tables(cursor): cursor.execute( - ''' + """ CREATE TABLE download_summary ( id TEXT NOT NULL, resource_id TEXT NOT NULL, @@ -261,5 +261,5 @@ def _create_download_tables(cursor): PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - ''' + """ ) From ba9a52f00f0156b145c93c66760700576432f396 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Mon, 13 Feb 2023 17:56:35 +0900 Subject: [PATCH 46/58] change the location of clean action --- ckanext/feedback/feedback.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index 2d3f3a34..5377c663 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -77,11 +77,10 @@ def init(modules, host, port, dbname, user, password): with get_connection(host, port, dbname, user, password) as connection: with connection.cursor() as cursor: try: - _drop_utilization_tables(cursor) - _drop_resource_tables(cursor) - _drop_download_tables(cursor) - click.secho('Clean all modules: SUCCESS', fg='green', bold=True) if not modules: + _drop_utilization_tables(cursor) + _drop_resource_tables(cursor) + _drop_download_tables(cursor) _create_utilization_tables(cursor) _create_resource_tabels(cursor) _create_download_tables(cursor) @@ -89,14 +88,17 @@ def init(modules, host, port, dbname, user, password): 'Initialize all modules: SUCCESS', fg='green', bold=True ) elif 'utilization' in modules: + _drop_utilization_tables(cursor) _create_utilization_tables(cursor) click.secho( 'Initialize utilization: SUCCESS', fg='green', bold=True ) elif 'resource' in modules: + _drop_resource_tables(cursor) _create_resource_tabels(cursor) click.secho('Initialize resource: SUCCESS', fg='green', bold=True) elif 'download' in modules: + _drop_download_tables(cursor) _create_download_tables(cursor) click.secho('Initialize download: SUCCESS', fg='green', bold=True) except Exception as e: From d600197873c416567b2000f11d2c769bf23987af Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 14 Feb 2023 10:25:29 +0900 Subject: [PATCH 47/58] fix the omitted word --- development/docs/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/development/docs/README.md b/development/docs/README.md index 5ef6c2f0..40103e8f 100644 --- a/development/docs/README.md +++ b/development/docs/README.md @@ -47,7 +47,7 @@ ckan --config=/etc/ckan/production.ini feedback init -m resource -m download **任意項目** -PosgreSQLコンテナのホスト名を指定する。 +PostgreSQLコンテナのホスト名を指定する。 指定しない場合、以下の順で参照された値を使用する。 1. 環境変数 ```POSTGRES_HOST``` 2. CKANのデフォルト値 ```db``` @@ -56,7 +56,7 @@ PosgreSQLコンテナのホスト名を指定する。 **任意項目** -PosgreSQLコンテナのポート番号を指定する。 +PostgreSQLコンテナのポート番号を指定する。 指定しない場合、以下の順で参照された値を使用する。 1. 環境変数 ```POSTGRES_PORT``` 2. CKANのデフォルト値 ```5432``` @@ -65,7 +65,7 @@ PosgreSQLコンテナのポート番号を指定する。 **任意項目** -PosgreSQLのデータベース名を指定する。 +PostgreSQLのデータベース名を指定する。 指定しない場合、以下の順で参照された値を使用する。 1. 環境変数 ```POSTGRES_DB``` 2. CKANのデフォルト値 ```ckan``` @@ -74,7 +74,7 @@ PosgreSQLのデータベース名を指定する。 **任意項目** -PosgreSQLに接続するためのユーザ名を指定する。 +PostgreSQLに接続するためのユーザ名を指定する。 指定しない場合、以下の順で参照された値を使用する。 1. 環境変数 ```POSTGRES_USER``` 2. CKANのデフォルト値 ```ckan``` @@ -83,7 +83,7 @@ PosgreSQLに接続するためのユーザ名を指定する。 **任意項目** -PosgreSQLに接続するためのパスワードを指定する。 +PostgreSQLに接続するためのパスワードを指定する。 指定しない場合、以下の順で参照された値を使用する。 1. 環境変数 ```POSTGRES_PASSWORD``` 2. CKANのデフォルト値 ```ckan``` From 682bf885baefd8bf66a97d2299549b3e9fd5437b Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 14 Feb 2023 11:06:36 +0900 Subject: [PATCH 48/58] use f-string instead of format-function --- ckanext/feedback/feedback.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index 5377c663..d3e57c8b 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -13,13 +13,7 @@ def feedback(): def get_connection(host, port, dbname, user, password): try: connector = psycopg2.connect( - 'postgresql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}'.format( - db_user=user, - db_password=password, - db_host=host, - db_port=port, - db_name=dbname, - ) + f'postgresql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}' ) except Exception as e: tk.error_shout(e) From c0b483a0d7d1a10831f3a9f758651797285154e9 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 14 Feb 2023 11:07:53 +0900 Subject: [PATCH 49/58] change type of POSTGRES_PORT from string to integer --- ckanext/feedback/feedback.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index d3e57c8b..a26ef6a3 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -43,7 +43,7 @@ def get_connection(host, port, dbname, user, password): '-p', '--port', envvar='POSTGRES_PORT', - default='5432', + default=5432, help='specify the port number of postgresql', ) @click.option( From 51e85534ef70110d1fbc85aea09f95a5ac9585ca Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 14 Feb 2023 12:07:13 +0900 Subject: [PATCH 50/58] rename genre1/genre2 to utilization_comment_category/resource_comment_category --- ckanext/feedback/feedback.py | 54 ++++++++++++++++++------------------ 1 file changed, 27 insertions(+), 27 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index a26ef6a3..ad8b6c2b 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -13,7 +13,7 @@ def feedback(): def get_connection(host, port, dbname, user, password): try: connector = psycopg2.connect( - f'postgresql://{db_user}:{db_password}@{db_host}:{db_port}/{db_name}' + f'postgresql://{user}:{password}@{host}:{port}/{dbname}' ) except Exception as e: tk.error_shout(e) @@ -172,31 +172,31 @@ def _create_utilization_tables(cursor): FOREIGN KEY (creator_user_id) REFERENCES public.user (id) ); - CREATE TYPE genre1 AS ENUM ('1', '2'); - CREATE TABLE utilization_comment ( - id TEXT NOT NULL, - utilization_id TEXT NOT NULL, - category genre1 NOT NULL, - content TEXT, - created TIMESTAMP, - approval BOOLEAN DEFAULT false, - approved TIMESTAMP, - approval_user_id TEXT, - PRIMARY KEY (id), - FOREIGN KEY (utilization_id) REFERENCES utilization (id), - FOREIGN KEY (approval_user_id) REFERENCES public.user (id) - ); + CREATE TYPE utilization_comment_category AS ENUM ('Request', 'Question', 'Advertise', 'Thank'); + CREATE TABLE utilization_comment ( + id TEXT NOT NULL, + utilization_id TEXT NOT NULL, + category utilization_comment_category NOT NULL, + content TEXT, + created TIMESTAMP, + approval BOOLEAN DEFAULT false, + approved TIMESTAMP, + approval_user_id TEXT, + PRIMARY KEY (id), + FOREIGN KEY (utilization_id) REFERENCES utilization (id), + FOREIGN KEY (approval_user_id) REFERENCES public.user (id) + ); - CREATE TABLE utilization_summary ( - id TEXT NOT NULL, - resource_id TEXT NOT NULL, - utilization INTEGER, - comment INTEGER, - created TIMESTAMP, - updated TIMESTAMP, - PRIMARY KEY (id), - FOREIGN KEY (resource_id) REFERENCES resource (id) - ); + CREATE TABLE utilization_summary ( + id TEXT NOT NULL, + resource_id TEXT NOT NULL, + utilization INTEGER, + comment INTEGER, + created TIMESTAMP, + updated TIMESTAMP, + PRIMARY KEY (id), + FOREIGN KEY (resource_id) REFERENCES resource (id) + ); """ ) @@ -204,11 +204,11 @@ def _create_utilization_tables(cursor): def _create_resource_tabels(cursor): cursor.execute( """ - CREATE TYPE genre2 AS ENUM ('1', '2'); + CREATE TYPE resource_comment_category AS ENUM ('Request', 'Question', 'Advertise', 'Thank'); CREATE TABLE resource_comment ( id TEXT NOT NULL, resource_id TEXT NOT NULL, - category genre2 NOT NULL, + category resource_comment_category NOT NULL, content TEXT, rating INTEGER, created TIMESTAMP, From f8ed9c99a005b9950866f94cee2f4877d77d6c81 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 14 Feb 2023 12:12:47 +0900 Subject: [PATCH 51/58] use formatter/linter --- ckanext/feedback/feedback.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index ad8b6c2b..12b28e0b 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -172,7 +172,9 @@ def _create_utilization_tables(cursor): FOREIGN KEY (creator_user_id) REFERENCES public.user (id) ); - CREATE TYPE utilization_comment_category AS ENUM ('Request', 'Question', 'Advertise', 'Thank'); + CREATE TYPE utilization_comment_category AS ENUM ( + 'Request', 'Question', 'Advertise', 'Thank' + ); CREATE TABLE utilization_comment ( id TEXT NOT NULL, utilization_id TEXT NOT NULL, @@ -204,7 +206,9 @@ def _create_utilization_tables(cursor): def _create_resource_tabels(cursor): cursor.execute( """ - CREATE TYPE resource_comment_category AS ENUM ('Request', 'Question', 'Advertise', 'Thank'); + CREATE TYPE resource_comment_category AS ENUM ( + 'Request', 'Question', 'Advertise', 'Thank' + ); CREATE TABLE resource_comment ( id TEXT NOT NULL, resource_id TEXT NOT NULL, From be7f6e5f718c86bf1f13c93dee1da7383eb85b5e Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 14 Feb 2023 12:51:43 +0900 Subject: [PATCH 52/58] rename genre1/genre2 in the function of drop table --- ckanext/feedback/feedback.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/feedback.py index 12b28e0b..ed3920b9 100644 --- a/ckanext/feedback/feedback.py +++ b/ckanext/feedback/feedback.py @@ -110,7 +110,7 @@ def _drop_utilization_tables(cursor): DROP TABLE IF EXISTS issue_resolution CASCADE; DROP TABLE IF EXISTS utilization_comment CASCADE; DROP TABLE IF EXISTS utilization_summary CASCADE; - DROP TYPE IF EXISTS genre1; + DROP TYPE IF EXISTS utilization_comment_category; """ ) @@ -121,7 +121,7 @@ def _drop_resource_tables(cursor): DROP TABLE IF EXISTS resource_comment CASCADE; DROP TABLE IF EXISTS resource_comment_reply CASCADE; DROP TABLE IF EXISTS resource_comment_summary CASCADE; - DROP TYPE IF EXISTS genre2; + DROP TYPE IF EXISTS resource_comment_category; """ ) @@ -235,7 +235,7 @@ def _create_resource_tabels(cursor): FOREIGN KEY (creator_user_id) REFERENCES public.user (id) ); - CREATE TABLE reource_comment_summary ( + CREATE TABLE resource_comment_summary ( id TEXT NOT NULL, resource_id TEXT NOT NULL, comment INTEGER, From ddc946529e59643a7ce20e391eeef34da0a8d01e Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 14 Feb 2023 14:22:56 +0900 Subject: [PATCH 53/58] move feedback.py to ckanext/feedback/commnad --- ckanext/feedback/{ => command}/feedback.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ckanext/feedback/{ => command}/feedback.py (100%) diff --git a/ckanext/feedback/feedback.py b/ckanext/feedback/command/feedback.py similarity index 100% rename from ckanext/feedback/feedback.py rename to ckanext/feedback/command/feedback.py From c5c3bdaa621d494d807a67cf1c439ac72cc1aa34 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 14 Feb 2023 14:29:08 +0900 Subject: [PATCH 54/58] add IClick to install feedback command --- ckanext/feedback/plugin.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ckanext/feedback/plugin.py b/ckanext/feedback/plugin.py index cbd9af3e..00332f2c 100644 --- a/ckanext/feedback/plugin.py +++ b/ckanext/feedback/plugin.py @@ -1,9 +1,11 @@ import ckan.plugins as plugins import ckan.plugins.toolkit as toolkit +from ckanext.feedback.command import feedback class FeedbackPlugin(plugins.SingletonPlugin): plugins.implements(plugins.IConfigurer) + plugins.implements(plugins.IClick) # IConfigurer @@ -12,3 +14,6 @@ def update_config(self, config_): toolkit.add_public_directory(config_, 'public') toolkit.add_resource('fanstatic', 'feedback') + + def get_commands(self): + return [feedback.feedback] \ No newline at end of file From 2b86c3d91eec7fda084a4b69a5412a6897027b12 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 14 Feb 2023 14:45:35 +0900 Subject: [PATCH 55/58] change double-quart to single-quart --- ckanext/feedback/command/feedback.py | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/ckanext/feedback/command/feedback.py b/ckanext/feedback/command/feedback.py index ed3920b9..3f1c58c9 100644 --- a/ckanext/feedback/command/feedback.py +++ b/ckanext/feedback/command/feedback.py @@ -7,7 +7,7 @@ @click.group() def feedback(): - """CLI tool for ckanext-feedback plugin.""" + '''CLI tool for ckanext-feedback plugin.''' def get_connection(host, port, dbname, user, password): @@ -104,39 +104,39 @@ def init(modules, host, port, dbname, user, password): def _drop_utilization_tables(cursor): cursor.execute( - """ + ''' DROP TABLE IF EXISTS utilization CASCADE; DROP TABLE IF EXISTS issue_resolution_summary CASCADE; DROP TABLE IF EXISTS issue_resolution CASCADE; DROP TABLE IF EXISTS utilization_comment CASCADE; DROP TABLE IF EXISTS utilization_summary CASCADE; DROP TYPE IF EXISTS utilization_comment_category; - """ + ''' ) def _drop_resource_tables(cursor): cursor.execute( - """ + ''' DROP TABLE IF EXISTS resource_comment CASCADE; DROP TABLE IF EXISTS resource_comment_reply CASCADE; DROP TABLE IF EXISTS resource_comment_summary CASCADE; DROP TYPE IF EXISTS resource_comment_category; - """ + ''' ) def _drop_download_tables(cursor): cursor.execute( - """ + ''' DROP TABLE IF EXISTS download_summary CASCADE; - """ + ''' ) def _create_utilization_tables(cursor): cursor.execute( - """ + ''' CREATE TABLE utilization ( id TEXT NOT NULL, resource_id TEXT NOT NULL, @@ -199,13 +199,13 @@ def _create_utilization_tables(cursor): PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - """ + ''' ) def _create_resource_tabels(cursor): cursor.execute( - """ + ''' CREATE TYPE resource_comment_category AS ENUM ( 'Request', 'Question', 'Advertise', 'Thank' ); @@ -245,13 +245,13 @@ def _create_resource_tabels(cursor): PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - """ + ''' ) def _create_download_tables(cursor): cursor.execute( - """ + ''' CREATE TABLE download_summary ( id TEXT NOT NULL, resource_id TEXT NOT NULL, @@ -261,5 +261,5 @@ def _create_download_tables(cursor): PRIMARY KEY (id), FOREIGN KEY (resource_id) REFERENCES resource (id) ); - """ + ''' ) From 40e715c7467693f4e39e423b20802b3843cfc281 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 14 Feb 2023 14:51:27 +0900 Subject: [PATCH 56/58] add tool.black to skip string normalization --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index 3b4fac70..d979024a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -47,6 +47,9 @@ build-backend = "poetry.core.masonry.api" max-line-length = 88 extend-ignore = "E203,W503,W504" +[tool.black] +skip-string-normalization = true + [tool.isort] include_trailing_comma = true line_length = 88 From 44b5c131b2d8d15dd3a303d0f77ee9a0c33cb6e9 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 14 Feb 2023 18:32:34 +0900 Subject: [PATCH 57/58] add flake8-quotes setting to use single quotes --- pyproject.toml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/pyproject.toml b/pyproject.toml index d979024a..693be11c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -46,6 +46,9 @@ build-backend = "poetry.core.masonry.api" [tool.flake8] max-line-length = 88 extend-ignore = "E203,W503,W504" +inline-quotes = "single" +multiline-quotes = "single" +docstring-quotes = "single" [tool.black] skip-string-normalization = true From f0e054a50b81cfe514daeb9d45aca8fda1071214 Mon Sep 17 00:00:00 2001 From: TokioMiyaoka Date: Tue, 14 Feb 2023 18:42:02 +0900 Subject: [PATCH 58/58] install flake8-quotes in pyproject.toml --- pyproject.toml | 1 + 1 file changed, 1 insertion(+) diff --git a/pyproject.toml b/pyproject.toml index 693be11c..561c8207 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -33,6 +33,7 @@ python = "3.8.16" [tool.poetry.group.dev.dependencies] pyproject-flake8 = "^6.0.0.post1" +flake8-quotes = "^3.3.2" black = "^22.12.0" isort = "^5.11.4" pytest = "^7.2.1"