Skip to content

Commit

Permalink
Merge pull request #4319 from google/rc_2020_9
Browse files Browse the repository at this point in the history
Rc 2020 9
  • Loading branch information
Monica Kozbial authored Sep 24, 2020
2 parents 9ab6273 + bdee690 commit 8d5d2be
Show file tree
Hide file tree
Showing 395 changed files with 20,361 additions and 16,685 deletions.
22 changes: 11 additions & 11 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"rules": {
"curly": ["error"],
"eol-last": ["error"],
"_comment": "Blockly/Google use 2-space indents",
"_comment": "Blockly/Google uses +4 space indents for line continuations.",
"_comment": "Ignore default rules for ternary expressions.",
// Blockly/Google use 2-space indents.
// Blockly/Google uses +4 space indents for line continuations.
// Ignore default rules for ternary expressions.
"indent": [
"error", 2,
{
Expand Down Expand Up @@ -42,26 +42,26 @@
"error",
{
"args": "after-used",
"_comment": "Ignore vars starting with an underscore.",
// Ignore vars starting with an underscore.
"varsIgnorePattern": "^_",
"_comment": "Ignore arguments starting with an underscore.",
// Ignore arguments starting with an underscore.
"argsIgnorePattern": "^_"
}
],
"no-use-before-define": ["error"],
"_comment":"Blockly uses for exporting symbols. no-self-assign added in eslint 5.",
// Blockly uses for exporting symbols. no-self-assign added in eslint 5.
"no-self-assign": ["off"],
"_comment": "Blockly uses single quotes except for JSON blobs, which must use double quotes.",
// Blockly uses single quotes except for JSON blobs, which must use double quotes.
"quotes": ["off"],
"semi": ["error", "always"],
"_comment": "Blockly doesn't have space before function paren when defining functions",
// Blockly doesn't have space before function paren when defining functions.
"space-before-function-paren": ["error", "never"],
"_comment": "Blocklydoesn't have space before function paren when calling functions",
// Blockly doesn't have space before function paren when calling functions.
"func-call-spacing": ["error", "never"],
"space-infix-ops": ["error"],
"_comment": "Blockly uses 'use strict' in files",
// Blockly uses 'use strict' in files.
"strict": ["off"],
"_comment": "Closure style allows redeclarations",
// Closure style allows redeclarations.
"no-redeclare": ["off"],
"valid-jsdoc": ["error", {"requireReturn": false}],
"no-console": ["off"],
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ build-debug.log
/nbproject/private/

tests/compile/main_compressed.js
tests/compile/main_compressed.js.map
tests/compile/*compiler*.jar
tests/screenshot/outputs/*
local_build/*compiler*.jar
Expand Down
6 changes: 0 additions & 6 deletions .jshintignore

This file was deleted.

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ language: node_js
os: linux
dist: xenial
node_js:
- 8
- 10
- 12
- 14
addons:
chrome: stable
firefox: latest
Expand Down
5 changes: 2 additions & 3 deletions appengine/.gcloudignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@
/static/demos/plane/soy/*.jar
/static/demos/plane/xlf/
/static/externs/
/static/i18n/
/static/msg/json/
/static/node_modules/
/static/package/
/static/theme_scripts/
/static/scripts/
/static/typings/

/static/build.py
/static/eslintrc.json
/static/gulpfile.js
/static/jsconfig.json
/static/LICENSE
Expand Down
69 changes: 69 additions & 0 deletions appengine/add_timestamps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
"""Blockly Demo: Add timestamps
Copyright 2020 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.
"""

"""A script to get all Xml entries in the datastore for Blockly demos
and reinsert any that do not have a last_accessed time.
This script should only need to be run once, but may take a long time
to complete.
NDB does not provide a way to query for all entities that are missing a
given property, so we have to get all of them and discard any that
already have a last_accessed time.
Auth: `gcloud auth login`
Set the correct project: `gcloud config set project blockly-demo`
See the current project: `gcloud config get-value project`
Start a venv: `python3 -m venv venv && source venv/bin/activate`
Inside your vm run `pip install google-cloud-ndb`
Run the script: `python add_timestamps.py`
"""

__author__ = "[email protected] (Rachel Fenichel)"


from google.cloud import ndb
from storage import Xml
import datetime

PAGE_SIZE = 1000

def handle_results(results):
for x in results:
if (x.last_accessed is None):
x.put()

def run_query():
client = ndb.Client()
with client.context():
query = Xml.query()
print(f'Total entries: {query.count()}')
cursor = None
more = True
page_count = 0
result_count = 0
while more:
results, cursor, more = query.fetch_page(PAGE_SIZE, start_cursor=cursor)
handle_results(results)
page_count = page_count + 1
result_count = result_count + len(results)
print(f'{datetime.datetime.now().strftime("%I:%M:%S %p")} : page {page_count} : {result_count}')

run_query()
51 changes: 51 additions & 0 deletions appengine/expiration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
"""
Copyright 2020 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.
"""

"""Delete expired XML.
"""

__author__ = "[email protected] (Rachel Fenichel)"


import storage
import datetime

from google.cloud import ndb


EXPIRATION_DAYS = 365
# Limit the query to avoid timeouts.
QUERY_LIMIT = 1000

def delete_expired():
"""Deletes entries that have not been accessed in more than a year."""
bestBefore = datetime.datetime.utcnow() - datetime.timedelta(days=EXPIRATION_DAYS)
client = ndb.Client()
with client.context():
query = storage.Xml.query(storage.Xml.last_accessed < bestBefore)
results = query.fetch(limit=QUERY_LIMIT, keys_only=True)
for x in results:
x.delete()


def app(environ, start_response):
out = ""
headers = [
("Content-Type", "text/plain")
]
start_response("200 OK", headers)
delete_expired()
return [out.encode("utf-8")]
3 changes: 3 additions & 0 deletions appengine/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""

import storage
import expiration


# Route to requested handler.
Expand All @@ -23,6 +24,8 @@ def app(environ, start_response):
return redirect(environ, start_response)
if environ["PATH_INFO"] == "/storage":
return storage.app(environ, start_response)
if environ["PATH_INFO"] == "/expiration":
return expiration.app(environ, start_response)
start_response("404 Not Found", [])
return [b"Page not found."]

Expand Down
6 changes: 5 additions & 1 deletion appengine/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class Xml(ndb.Model):
# A row in the database.
xml_hash = ndb.IntegerProperty()
xml_content = ndb.TextProperty()

last_accessed = ndb.DateTimeProperty(auto_now=True)

def keyGen():
# Generate a random string of length KEY_LEN.
Expand Down Expand Up @@ -75,6 +75,10 @@ def keyToXml(key_provided):
if not result:
xml = ""
else:
# Put it back into the datastore immediately, which updates the last
# accessed time.
with client.context():
result.put()
xml = result.xml_content
return xml

Expand Down
Loading

0 comments on commit 8d5d2be

Please sign in to comment.