Find out version of app in remote API shell?

74 views
Skip to first unread message

Felix E. Klee

unread,
Sep 6, 2011, 6:40:55 AM9/6/11
to google-a...@googlegroups.com
Suppose I run the remote API shell as follows:

$ python some_path/remote_api_shell.py -s 1-5-3.example.appspot.com

How do I find out the version number of the app from within the shell?

(in this case: 1-5-3)

Felix E. Klee

unread,
Sep 6, 2011, 6:54:55 AM9/6/11
to google-a...@googlegroups.com
I reposted this question now on:

google-appe...@googlegroups.com

Seems to be more appropriate.

JH

unread,
Sep 6, 2011, 7:52:56 AM9/6/11
to Google App Engine
import os
os.environ['CURRENT_VERSION_ID']

Felix E. Klee

unread,
Sep 6, 2011, 9:06:17 AM9/6/11
to google-a...@googlegroups.com
On Tue, Sep 6, 2011 at 1:52 PM, JH <ja...@mhztech.com> wrote:
> import os
> os.environ['CURRENT_VERSION_ID']

The key "CURRENT_VERSION_ID" is *not* available in the remote API shell:

s~example> import os
s~example> os.environ['CURRENT_VERSION_ID']
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "C:\Programme\Python25\lib\os.py", line 433, in __getitem__
return self.data[key.upper()]
KeyError: 'CURRENT_VERSION_ID'

Ronoaldo José de Lana Pereira

unread,
Sep 6, 2011, 9:24:32 AM9/6/11
to google-a...@googlegroups.com
I usualy have a handler on the server that does show the current running version. I'm more used to write Java code, but this handler may help you:

class CurrentVersion(webapp.RequestHandler):
    def get(self):
        self.response.headers["Content-Type"] = "text/plain"
        self.response.out.write(os.environ["CURRENT_VERSION_ID"])

If you map it "/version" you can then access it with urllib on a client-side code:

version = urllib2.urlopen("http://example.appspot.com/version").read()

I'm not sure if the remote api environment provides such funcionality, but they may do ... 

Hope this help,

-Ronoaldo

Felix E. Klee

unread,
Sep 6, 2011, 9:28:10 AM9/6/11
to google-a...@googlegroups.com
2011/9/6 Ronoaldo José de Lana Pereira <rper...@beneficiofacil.com.br>:

> version = urllib2.urlopen("http://example.appspot.com/version").read()

If I had the URL, then I would already be all set. It includes the
version!

Remember:

$ python some_path/remote_api_shell.py -s 1-5-3.example.appspot.com

The question is: How do I get the URL that was entered on the command
line when starting the remote shell?

Ernesto Oltra

unread,
Sep 6, 2011, 9:50:22 AM9/6/11
to google-a...@googlegroups.com
Hi,

You could try to iterate through the sys.argv list, and find the argument next to the "-s" one.

Ernesto

Ronoaldo José de Lana Pereira

unread,
Sep 6, 2011, 10:14:24 AM9/6/11
to google-a...@googlegroups.com
Oops, sorry, I misunderstood your question :) .. Ernesto's answer may be the only one available to you then: explore sys.argv to check if a version was specified. But this won't work if you start with a custom domain instead of a version-based domain.

Best Regards,

-Ronoaldo

Ernesto Oltra

unread,
Sep 6, 2011, 11:05:02 AM9/6/11
to google-a...@googlegroups.com
Good point! Try this too (I won't have access to appengine until the night):

from google.appengine.api import app_identity
app_identity.get_application_id()

2011/9/6 Ronoaldo José de Lana Pereira <rper...@beneficiofacil.com.br>
Oops, sorry, I misunderstood your question :) .. Ernesto's answer may be the only one available to you then: explore sys.argv to check if a version was specified. But this won't work if you start with a custom domain instead of a version-based domain.

Best Regards,

-Ronoaldo

--
You received this message because you are subscribed to the Google Groups "Google App Engine" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-appengine/-/6p7xB0dqOa4J.

To post to this group, send email to google-a...@googlegroups.com.
To unsubscribe from this group, send email to google-appengi...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-appengine?hl=en.

Felix E. Klee

unread,
Sep 6, 2011, 12:13:43 PM9/6/11
to google-a...@googlegroups.com
On Tue, Sep 6, 2011 at 5:05 PM, Ernesto Oltra <ernest...@gmail.com>
wrote:

> from google.appengine.api import app_identity
> app_identity.get_application_id()

Reports the app ID, not the version. For "1-5-3.example.appspot.com"
that's:

example

Felix E. Klee

unread,
Sep 6, 2011, 12:14:37 PM9/6/11
to google-a...@googlegroups.com
On Tue, Sep 6, 2011 at 3:50 PM, Ernesto Oltra <ernest...@gmail.com>
wrote:

> You could try to iterate through the sys.argv list, and find the
> argument next to the "-s" one.

Thanks for the suggestion! Had that already in mind as a fall-back
solution. However, was hoping for something simpler and more reliable.

Felix E. Klee

unread,
Sep 6, 2011, 4:11:15 PM9/6/11
to google-a...@googlegroups.com
On Tue, Sep 6, 2011 at 12:40 PM, Felix E. Klee <felix...@inka.de>
wrote:

> How do I find out the version number of the app from within the shell?

Finally, I found a solution:

parser = optparse.OptionParser()
parser.add_option('-s', '--server', dest='server')
(options, args) = parser.parse_args()
options.server.split('.')[0]

Reply all
Reply to author
Forward
0 new messages