From c2461a987d71451f4140f636ba93478c4714d37c Mon Sep 17 00:00:00 2001 From: Louis Ye Date: Thu, 24 Oct 2019 16:32:47 -0400 Subject: [PATCH 1/5] Add quickstart sample app for cloud debugger --- .../standard_python37/cloud_debugger/app.yaml | 1 + .../standard_python37/cloud_debugger/main.py | 94 +++++++++++++++++++ .../cloud_debugger/requirements.txt | 2 + 3 files changed, 97 insertions(+) create mode 100644 appengine/standard_python37/cloud_debugger/app.yaml create mode 100644 appengine/standard_python37/cloud_debugger/main.py create mode 100644 appengine/standard_python37/cloud_debugger/requirements.txt diff --git a/appengine/standard_python37/cloud_debugger/app.yaml b/appengine/standard_python37/cloud_debugger/app.yaml new file mode 100644 index 00000000000..6ae7e5ade33 --- /dev/null +++ b/appengine/standard_python37/cloud_debugger/app.yaml @@ -0,0 +1 @@ +runtime: python37 \ No newline at end of file diff --git a/appengine/standard_python37/cloud_debugger/main.py b/appengine/standard_python37/cloud_debugger/main.py new file mode 100644 index 00000000000..ede3ca63c96 --- /dev/null +++ b/appengine/standard_python37/cloud_debugger/main.py @@ -0,0 +1,94 @@ +# Copyright 2019 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +# [START gae_python37_app] +from flask import Flask, request + + +# Enable cloud debugger +# Adjust logging level to INFO +try: + import googleclouddebugger + googleclouddebugger.enable() + import logging + logging.basicConfig(level=logging.INFO) +except ImportError: + pass + +# If `entrypoint` is not defined in app.yaml, App Engine will look for an app +# called `app` in `main.py`. +app = Flask(__name__) + + +# There is a bug in the code. +class StringProcessor(): + def __init__(self, string): + self._string = string + + def Reverse(self): + if self._string is '': + return '' + + chars = [c for c in self._string] + left = 0 + right = len(chars) - 1 + while True: + tmp = chars[left] + chars[left] = chars[right] + chars[right] = tmp + if left >= right: + break + left += 1 + right -= 1 + + return ''.join(chars) + + +@app.route('/reverse_string', methods=['GET']) +def ReverseString(): + try: + s = str(request.args.get('string')) + except Exception as e: + print(e) + return 'Not a valid string!' + + current = StringProcessor(s).Reverse() + expected = s[::-1] + return ''' + + + +
Current:{}
Expected:{}
+ '''.format(current, expected) + + + +@app.route('/') +def Hello(): + """Return a friendly HTTP greeting.""" + return ''' + Hello! Enter a string to reverse it. +
+

+

+

+ ''' + + +if __name__ == '__main__': + # This is used when running locally only. When deploying to Google App + # Engine, a webserver process such as Gunicorn will serve the app. This + # can be configured by adding an `entrypoint` to app.yaml. + app.run(host='127.0.0.1', port=8080, debug=True) +# [END gae_python37_app] diff --git a/appengine/standard_python37/cloud_debugger/requirements.txt b/appengine/standard_python37/cloud_debugger/requirements.txt new file mode 100644 index 00000000000..323aa492d4e --- /dev/null +++ b/appengine/standard_python37/cloud_debugger/requirements.txt @@ -0,0 +1,2 @@ +Flask==1.1.1 +google-python-cloud-debugger From ebfd8c5eeb4a949e7648c607d8997ea039bcd308 Mon Sep 17 00:00:00 2001 From: Louis Ye Date: Wed, 30 Oct 2019 17:18:46 -0400 Subject: [PATCH 2/5] Update cloud_debugger sampe app text --- appengine/standard_python37/cloud_debugger/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/appengine/standard_python37/cloud_debugger/main.py b/appengine/standard_python37/cloud_debugger/main.py index ede3ca63c96..0144f809fda 100644 --- a/appengine/standard_python37/cloud_debugger/main.py +++ b/appengine/standard_python37/cloud_debugger/main.py @@ -67,8 +67,8 @@ def ReverseString(): expected = s[::-1] return ''' - - + +
Current:{}
Expected:{}
Program Output:{}
Correct Output:{}
'''.format(current, expected) From 973756c43a8b16f61dcd8bb4cdcdf226061fc913 Mon Sep 17 00:00:00 2001 From: Charles Engelke Date: Tue, 5 Nov 2019 12:37:01 -0800 Subject: [PATCH 3/5] Missed trailing newline --- appengine/standard_python37/cloud_debugger/app.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appengine/standard_python37/cloud_debugger/app.yaml b/appengine/standard_python37/cloud_debugger/app.yaml index 6ae7e5ade33..a0b719d6dd4 100644 --- a/appengine/standard_python37/cloud_debugger/app.yaml +++ b/appengine/standard_python37/cloud_debugger/app.yaml @@ -1 +1 @@ -runtime: python37 \ No newline at end of file +runtime: python37 From 948fd59cf48ccbb36e96bfd260e3680254744b06 Mon Sep 17 00:00:00 2001 From: Louis Ye Date: Thu, 7 Nov 2019 13:26:12 -0500 Subject: [PATCH 4/5] Take out logging level from the try/catch block --- appengine/standard_python37/cloud_debugger/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/appengine/standard_python37/cloud_debugger/main.py b/appengine/standard_python37/cloud_debugger/main.py index 0144f809fda..b400a3e0a6b 100644 --- a/appengine/standard_python37/cloud_debugger/main.py +++ b/appengine/standard_python37/cloud_debugger/main.py @@ -15,17 +15,17 @@ # [START gae_python37_app] from flask import Flask, request - # Enable cloud debugger # Adjust logging level to INFO try: import googleclouddebugger googleclouddebugger.enable() - import logging - logging.basicConfig(level=logging.INFO) except ImportError: pass +import logging +logging.basicConfig(level=logging.INFO) + # If `entrypoint` is not defined in app.yaml, App Engine will look for an app # called `app` in `main.py`. app = Flask(__name__) From 34c35eebefd6882e794841ccb569f4a5a9045bc9 Mon Sep 17 00:00:00 2001 From: Louis Ye Date: Thu, 7 Nov 2019 13:27:24 -0500 Subject: [PATCH 5/5] Update comment --- appengine/standard_python37/cloud_debugger/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/appengine/standard_python37/cloud_debugger/main.py b/appengine/standard_python37/cloud_debugger/main.py index b400a3e0a6b..346873b9064 100644 --- a/appengine/standard_python37/cloud_debugger/main.py +++ b/appengine/standard_python37/cloud_debugger/main.py @@ -16,13 +16,13 @@ from flask import Flask, request # Enable cloud debugger -# Adjust logging level to INFO try: import googleclouddebugger googleclouddebugger.enable() except ImportError: pass +# Adjust logging level to INFO import logging logging.basicConfig(level=logging.INFO)