public inbox for [email protected]
help / color / mirror / Atom feedFrom: Alessandro De Maria <[email protected]>
To: [email protected]
Subject: Feature 6270: Allow for --load-servers to replace current server list
Date: Thu, 25 Feb 2021 16:36:03 +0000
Message-ID: <CAAivwfK6LAtYs1WsDBKmRvpzUFo_dPBWHCjNNtQBBAx0w0eSSg@mail.gmail.com> (raw)
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)
view thread (4+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: Feature 6270: Allow for --load-servers to replace current server list
In-Reply-To: <CAAivwfK6LAtYs1WsDBKmRvpzUFo_dPBWHCjNNtQBBAx0w0eSSg@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox