3 # Copyright 2007 Google Inc.
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 """An interactive python shell that uses remote_api.
21 remote_api_shell.py [-s HOSTNAME] APPID [PATH]
25 from google
.appengine
.tools
import os_compat
39 from google
.appengine
.ext
.remote_api
import remote_api_stub
41 from google
.appengine
.api
import datastore
42 from google
.appengine
.api
import memcache
43 from google
.appengine
.api
import urlfetch
44 from google
.appengine
.api
import users
45 from google
.appengine
.ext
import db
46 from google
.appengine
.ext
import search
49 HISTORY_PATH
= os
.path
.expanduser('~/.remote_api_shell_history')
50 DEFAULT_PATH
= '/remote_api'
51 BANNER
= """App Engine remote_api shell
53 The db, users, urlfetch, and memcache modules are imported.""" % sys
.version
57 return (raw_input('Email: '), getpass
.getpass('Password: '))
61 parser
= optparse
.OptionParser()
62 parser
.add_option('-s', '--server', dest
='server',
63 help='The hostname your app is deployed on. '
64 'Defaults to <app_id>.appspot.com.')
65 parser
.add_option('--secure', dest
='secure', action
="store_true",
66 default
=False, help='Use HTTPS when communicating '
68 (options
, args
) = parser
.parse_args()
70 if not args
or len(args
) > 2:
71 print >> sys
.stderr
, __doc__
73 print >> sys
.stderr
, 'Unexpected arguments: %s' % args
[2:]
82 remote_api_stub
.ConfigureRemoteApi(appid
, path
, auth_func
,
83 servername
=options
.server
,
84 save_cookies
=True, secure
=options
.secure
)
85 remote_api_stub
.MaybeInvokeAuthentication()
87 os
.environ
['SERVER_SOFTWARE'] = 'Development (remote_api_shell)/1.0'
89 sys
.ps1
= '%s> ' % appid
90 if readline
is not None:
91 readline
.parse_and_bind('tab: complete')
92 atexit
.register(lambda: readline
.write_history_file(HISTORY_PATH
))
93 if os
.path
.exists(HISTORY_PATH
):
94 readline
.read_history_file(HISTORY_PATH
)
96 code
.interact(banner
=BANNER
, local
=globals())
99 if __name__
== '__main__':