You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ts...@apache.org on 2012/10/27 12:02:26 UTC

[12/49] git commit: cloud-setup-databases: modify try-except-finally for < python 2.4

cloud-setup-databases: modify try-except-finally for < python 2.4

Make cloud-setup-databases compatible to python 2.4 and before.

Add code Prasanna Santhanam <ts...@apache.org>
Partially revert a6dcd7af4962a584f46d9b7271e2c225618624ed which removed
the fix for CLOUDSTACK-199: Fix how cloud-setup-databases parses
  Patch splits by right most @ in supplied argument to get
  user:password and host substrings.

Less than python <2.4 the following is unsupported and produces a
SyntaxError.
    try:
        ...code ...
    except ValueError:
        ...code ...
    finally:
        ...code ...

Workaround is the following
    try:
        try:
            ...code ...
        except ValueError:
            ...code ...
    finally:

Credits to Prasanna Santhanam <ts...@apache.org>

Signed-off-by: Rohit Yadav <bh...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/3663af14
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/3663af14
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/3663af14

Branch: refs/heads/marvin-parallel
Commit: 3663af14347738c6dc0978ecddb0d984e89ba60d
Parents: 7d15dc1
Author: Rohit Yadav <bh...@apache.org>
Authored: Fri Oct 26 14:17:13 2012 +0530
Committer: Rohit Yadav <bh...@apache.org>
Committed: Fri Oct 26 14:20:37 2012 +0530

----------------------------------------------------------------------
 setup/bindir/cloud-setup-databases.in |   12 ++++++++++--
 1 files changed, 10 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3663af14/setup/bindir/cloud-setup-databases.in
----------------------------------------------------------------------
diff --git a/setup/bindir/cloud-setup-databases.in b/setup/bindir/cloud-setup-databases.in
index 3368fa0..bd5a0ba 100755
--- a/setup/bindir/cloud-setup-databases.in
+++ b/setup/bindir/cloud-setup-databases.in
@@ -500,8 +500,16 @@ for example:
                 self.errorAndExit("There are more than one parameters for user:password@hostname (%s)"%self.args)
 
             arg = self.args[0]
-            stuff = arg.split("@", 1)
-            if len(stuff) == 1: stuff.append("localhost")
+            try:
+                try:
+                    splitIndex = arg.rindex('@')
+                except ValueError:
+                    # If it failed to find @, use host=localhost
+                    splitIndex = len(arg)
+                    arg += "@localhost"
+            finally:
+                stuff = [arg[:splitIndex], arg[splitIndex+1:]]
+
             self.user,self.password = parseUserAndPassword(stuff[0])
             self.host,self.port = parseHostInfo(stuff[1])