public inbox for [email protected]
help / color / mirror / Atom feedFeature 6270: Allow for --load-servers to replace current server list
4+ messages / 2 participants
[nested] [flat]
* Feature 6270: Allow for --load-servers to replace current server list
@ 2021-02-25 16:36 Alessandro De Maria <[email protected]>
2021-02-26 09:25 ` Re: Feature 6270: Allow for --load-servers to replace current server list Akshay Joshi <[email protected]>
0 siblings, 1 reply; 4+ messages in thread
From: Alessandro De Maria @ 2021-02-25 16:36 UTC (permalink / raw)
To: [email protected]
Hello,
I have created a patch for the issue I raised earlier:
https://redmine.postgresql.org/issues/6270
I apologise I have never sent git patches before, and I could not find any
specific documentation of how you expect to receive contributions.
Regards
Alessandro
--
Alessandro De Maria
[email protected]
Attachments:
[application/octet-stream] 0001-6270-add-replace-flag.patch (2.8K, 3-0001-6270-add-replace-flag.patch)
download | inline diff:
From 07c5b10b1e178336768dc174fb3bdb0d84779cf3 Mon Sep 17 00:00:00 2001
From: Alessandro De Maria <[email protected]>
Date: Thu, 25 Feb 2021 16:21:25 +0000
Subject: [PATCH] 6270: add --replace flag
---
web/setup.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/web/setup.py b/web/setup.py
index 20ce6563b3..86e61fc77b 100644
--- a/web/setup.py
+++ b/web/setup.py
@@ -397,6 +397,51 @@ def setup_db():
if os.name != 'nt':
os.chmod(config.SQLITE_PATH, 0o600)
+def clear_servers():
+ """Clear groups and servers configurations.
+
+ Args:
+ args (ArgParser): The parsed command line options
+ """
+
+ # What user?
+ load_user = args.user if args.user is not None else config.DESKTOP_USER
+
+ # And the sqlite path
+ if args.sqlite_path is not None:
+ config.SQLITE_PATH = args.sqlite_path
+
+ app = create_app(config.APP_NAME + '-cli')
+ with app.app_context():
+ user = User.query.filter_by(email=load_user).first()
+
+ if user is None:
+ print("The specified user ID (%s) could not be found." %
+ load_user)
+ sys.exit(1)
+
+ user_id = user.id
+
+ # Remove all servers
+ servers = Server.query.filter_by(user_id=user_id)
+ for server in servers:
+ db.session.delete(server)
+
+ # Remove all groups
+ groups = ServerGroup.query.filter_by(user_id=user_id)
+ for group in groups:
+ db.session.delete(group)
+ servers = Server.query.filter_by(user_id=user_id)
+
+ for server in servers:
+ db.session.delete(server)
+
+ try:
+ db.session.commit()
+ except Exception as e:
+ print("Error clearing server configuration")
+
+
if __name__ == '__main__':
# Configuration settings
@@ -415,7 +460,10 @@ if __name__ == '__main__':
imp_group = parser.add_argument_group('Load server config')
imp_group.add_argument('--load-servers', metavar="INPUT_FILE",
help='Load servers into the DB', required=False)
+ imp_group.add_argument('--replace', dest='replace', action='store_true',
+ help='replace server configurations', required=False)
+ imp_group.set_defaults(replace=False)
# Common args
parser.add_argument('--sqlite-path', metavar="PATH",
help='Dump/load with the specified pgAdmin config DB'
@@ -442,6 +490,8 @@ if __name__ == '__main__':
print(str(e))
elif args.load_servers is not None:
try:
+ if args.replace:
+ clear_servers()
load_servers(args)
except Exception as e:
print(str(e))
--
2.24.3 (Apple Git-128)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Feature 6270: Allow for --load-servers to replace current server list
2021-02-25 16:36 Feature 6270: Allow for --load-servers to replace current server list Alessandro De Maria <[email protected]>
@ 2021-02-26 09:25 ` Akshay Joshi <[email protected]>
2021-03-01 11:12 ` Re: Feature 6270: Allow for --load-servers to replace current server list Alessandro De Maria <[email protected]>
0 siblings, 1 reply; 4+ messages in thread
From: Akshay Joshi @ 2021-02-26 09:25 UTC (permalink / raw)
To: Alessandro De Maria <[email protected]>; +Cc: pgadmin-hackers <[email protected]>
Hi Alessandro
Patch looks good to me. Please fix the following issues:
- Fix the PEP8 issue.
- Documentation needs to be updated with this new flag. Please update
"docs-> en_Us -> import_export_servers.rst" file.
On Thu, Feb 25, 2021 at 10:06 PM Alessandro De Maria <
[email protected]> wrote:
> Hello,
>
> I have created a patch for the issue I raised earlier:
>
> https://redmine.postgresql.org/issues/6270
>
> I apologise I have never sent git patches before, and I could not find any
> specific documentation of how you expect to receive contributions.
>
> Regards
> Alessandro
>
> --
> Alessandro De Maria
> [email protected]
>
--
*Thanks & Regards*
*Akshay Joshi*
*pgAdmin Hacker | Principal Software Architect*
*EDB Postgres <http://edbpostgres.com>*
*Mobile: +91 976-788-8246*
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Feature 6270: Allow for --load-servers to replace current server list
2021-02-25 16:36 Feature 6270: Allow for --load-servers to replace current server list Alessandro De Maria <[email protected]>
2021-02-26 09:25 ` Re: Feature 6270: Allow for --load-servers to replace current server list Akshay Joshi <[email protected]>
@ 2021-03-01 11:12 ` Alessandro De Maria <[email protected]>
2021-03-01 12:30 ` Re: Feature 6270: Allow for --load-servers to replace current server list Akshay Joshi <[email protected]>
0 siblings, 1 reply; 4+ messages in thread
From: Alessandro De Maria @ 2021-03-01 11:12 UTC (permalink / raw)
To: Akshay Joshi <[email protected]>; +Cc: pgadmin-hackers <[email protected]>
Hey Akshay,
Thank you for the suggestions, here are the patches.
Regards
Alessandro
On Fri, 26 Feb 2021 at 09:25, Akshay Joshi <[email protected]>
wrote:
> Hi Alessandro
>
> Patch looks good to me. Please fix the following issues:
>
> - Fix the PEP8 issue.
> - Documentation needs to be updated with this new flag. Please update
> "docs-> en_Us -> import_export_servers.rst" file.
>
>
> On Thu, Feb 25, 2021 at 10:06 PM Alessandro De Maria <
> [email protected]> wrote:
>
>> Hello,
>>
>> I have created a patch for the issue I raised earlier:
>>
>> https://redmine.postgresql.org/issues/6270
>>
>> I apologise I have never sent git patches before, and I could not find
>> any specific documentation of how you expect to receive contributions.
>>
>> Regards
>> Alessandro
>>
>> --
>> Alessandro De Maria
>> [email protected]
>>
>
>
> --
> *Thanks & Regards*
> *Akshay Joshi*
> *pgAdmin Hacker | Principal Software Architect*
> *EDB Postgres <http://edbpostgres.com>*
>
> *Mobile: +91 976-788-8246*
>
--
Alessandro De Maria
[email protected]
Attachments:
[application/octet-stream] 0002-Address-comments-on-pep8-and-documentation.patch (2.8K, 3-0002-Address-comments-on-pep8-and-documentation.patch)
download | inline diff:
From d462c833d2f3e664a7480363bae13e33a352cd0c Mon Sep 17 00:00:00 2001
From: Alessandro De Maria <[email protected]>
Date: Mon, 1 Mar 2021 11:09:39 +0000
Subject: [PATCH 2/2] Address comments on pep8 and documentation
---
docs/en_US/import_export_servers.rst | 3 +++
web/setup.py | 11 +++++------
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/docs/en_US/import_export_servers.rst b/docs/en_US/import_export_servers.rst
index 1e05f9617b..175a544cf4 100644
--- a/docs/en_US/import_export_servers.rst
+++ b/docs/en_US/import_export_servers.rst
@@ -57,6 +57,9 @@ path) of the JSON file containing the server definitions. Servers will be owned
by the desktop mode user ([email protected] by default - see the DESKTOP_USER
setting in ``config.py``). This can be overridden with the ``--user`` command
line option. There can be multiple configuations of pgAdmin on the same system.
+The default behaviour is for the imported servers to be added to the existent list,
+which might lead to duplicates. This can be overridden with the ``--replace`` command
+line option, which will replace the list of servers with the newly imported one.
To load the servers into a specific pgAdmin config DB file, ``--sqlite-path`` option
can be used. It is also recommended to use this option when running pgAdmin in
desktop mode. By default SQLITE_PATH setting in ``config.py`` is taken. For example:
diff --git a/web/setup.py b/web/setup.py
index 86e61fc77b..37d8345f4f 100644
--- a/web/setup.py
+++ b/web/setup.py
@@ -10,6 +10,9 @@
"""Perform the initial setup of the application, by creating the auth
and settings database."""
+from pgadmin.model import db, User, Version, ServerGroup, Server, \
+ SCHEMA_VERSION as CURRENT_SCHEMA_VERSION
+from pgadmin import create_app
import argparse
import json
import os
@@ -28,10 +31,6 @@ root = os.path.dirname(os.path.realpath(__file__))
if sys.path[0] != root:
sys.path.insert(0, root)
-from pgadmin import create_app
-from pgadmin.model import db, User, Version, ServerGroup, Server, \
- SCHEMA_VERSION as CURRENT_SCHEMA_VERSION
-
def add_value(attr_dict, key, value):
"""Add a value to the attribute dict if non-empty.
@@ -397,6 +396,7 @@ def setup_db():
if os.name != 'nt':
os.chmod(config.SQLITE_PATH, 0o600)
+
def clear_servers():
"""Clear groups and servers configurations.
@@ -432,7 +432,7 @@ def clear_servers():
for group in groups:
db.session.delete(group)
servers = Server.query.filter_by(user_id=user_id)
-
+
for server in servers:
db.session.delete(server)
@@ -442,7 +442,6 @@ def clear_servers():
print("Error clearing server configuration")
-
if __name__ == '__main__':
# Configuration settings
import config
--
2.24.3 (Apple Git-128)
[application/octet-stream] 0001-6270-add-replace-flag.patch (2.8K, 4-0001-6270-add-replace-flag.patch)
download | inline diff:
From 8f610a8def97f4eeb8299508e168afcf313197f7 Mon Sep 17 00:00:00 2001
From: Alessandro De Maria <[email protected]>
Date: Thu, 25 Feb 2021 16:21:25 +0000
Subject: [PATCH 1/2] 6270: add --replace flag
---
web/setup.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/web/setup.py b/web/setup.py
index 20ce6563b3..86e61fc77b 100644
--- a/web/setup.py
+++ b/web/setup.py
@@ -397,6 +397,51 @@ def setup_db():
if os.name != 'nt':
os.chmod(config.SQLITE_PATH, 0o600)
+def clear_servers():
+ """Clear groups and servers configurations.
+
+ Args:
+ args (ArgParser): The parsed command line options
+ """
+
+ # What user?
+ load_user = args.user if args.user is not None else config.DESKTOP_USER
+
+ # And the sqlite path
+ if args.sqlite_path is not None:
+ config.SQLITE_PATH = args.sqlite_path
+
+ app = create_app(config.APP_NAME + '-cli')
+ with app.app_context():
+ user = User.query.filter_by(email=load_user).first()
+
+ if user is None:
+ print("The specified user ID (%s) could not be found." %
+ load_user)
+ sys.exit(1)
+
+ user_id = user.id
+
+ # Remove all servers
+ servers = Server.query.filter_by(user_id=user_id)
+ for server in servers:
+ db.session.delete(server)
+
+ # Remove all groups
+ groups = ServerGroup.query.filter_by(user_id=user_id)
+ for group in groups:
+ db.session.delete(group)
+ servers = Server.query.filter_by(user_id=user_id)
+
+ for server in servers:
+ db.session.delete(server)
+
+ try:
+ db.session.commit()
+ except Exception as e:
+ print("Error clearing server configuration")
+
+
if __name__ == '__main__':
# Configuration settings
@@ -415,7 +460,10 @@ if __name__ == '__main__':
imp_group = parser.add_argument_group('Load server config')
imp_group.add_argument('--load-servers', metavar="INPUT_FILE",
help='Load servers into the DB', required=False)
+ imp_group.add_argument('--replace', dest='replace', action='store_true',
+ help='replace server configurations', required=False)
+ imp_group.set_defaults(replace=False)
# Common args
parser.add_argument('--sqlite-path', metavar="PATH",
help='Dump/load with the specified pgAdmin config DB'
@@ -442,6 +490,8 @@ if __name__ == '__main__':
print(str(e))
elif args.load_servers is not None:
try:
+ if args.replace:
+ clear_servers()
load_servers(args)
except Exception as e:
print(str(e))
--
2.24.3 (Apple Git-128)
^ permalink raw reply [nested|flat] 4+ messages in thread
* Re: Feature 6270: Allow for --load-servers to replace current server list
2021-02-25 16:36 Feature 6270: Allow for --load-servers to replace current server list Alessandro De Maria <[email protected]>
2021-02-26 09:25 ` Re: Feature 6270: Allow for --load-servers to replace current server list Akshay Joshi <[email protected]>
2021-03-01 11:12 ` Re: Feature 6270: Allow for --load-servers to replace current server list Alessandro De Maria <[email protected]>
@ 2021-03-01 12:30 ` Akshay Joshi <[email protected]>
0 siblings, 0 replies; 4+ messages in thread
From: Akshay Joshi @ 2021-03-01 12:30 UTC (permalink / raw)
To: Alessandro De Maria <[email protected]>; +Cc: pgadmin-hackers <[email protected]>
Thanks, patch applied.
On Mon, Mar 1, 2021 at 4:42 PM Alessandro De Maria <
[email protected]> wrote:
> Hey Akshay,
>
> Thank you for the suggestions, here are the patches.
>
> Regards
> Alessandro
>
> On Fri, 26 Feb 2021 at 09:25, Akshay Joshi <[email protected]>
> wrote:
>
>> Hi Alessandro
>>
>> Patch looks good to me. Please fix the following issues:
>>
>> - Fix the PEP8 issue.
>> - Documentation needs to be updated with this new flag. Please update
>> "docs-> en_Us -> import_export_servers.rst" file.
>>
>>
>> On Thu, Feb 25, 2021 at 10:06 PM Alessandro De Maria <
>> [email protected]> wrote:
>>
>>> Hello,
>>>
>>> I have created a patch for the issue I raised earlier:
>>>
>>> https://redmine.postgresql.org/issues/6270
>>>
>>> I apologise I have never sent git patches before, and I could not find
>>> any specific documentation of how you expect to receive contributions.
>>>
>>> Regards
>>> Alessandro
>>>
>>> --
>>> Alessandro De Maria
>>> [email protected]
>>>
>>
>>
>> --
>> *Thanks & Regards*
>> *Akshay Joshi*
>> *pgAdmin Hacker | Principal Software Architect*
>> *EDB Postgres <http://edbpostgres.com>*
>>
>> *Mobile: +91 976-788-8246*
>>
>
>
> --
> Alessandro De Maria
> [email protected]
>
--
*Thanks & Regards*
*Akshay Joshi*
*pgAdmin Hacker | Principal Software Architect*
*EDB Postgres <http://edbpostgres.com>*
*Mobile: +91 976-788-8246*
^ permalink raw reply [nested|flat] 4+ messages in thread
end of thread, other threads:[~2021-03-01 12:30 UTC | newest]
Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2021-02-25 16:36 Feature 6270: Allow for --load-servers to replace current server list Alessandro De Maria <[email protected]>
2021-02-26 09:25 ` Akshay Joshi <[email protected]>
2021-03-01 11:12 ` Alessandro De Maria <[email protected]>
2021-03-01 12:30 ` Akshay Joshi <[email protected]>
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox