Skip to content

Commit

Permalink
Rewrite build_app_engine_package using python
Browse files Browse the repository at this point in the history
  • Loading branch information
jiayliu committed Feb 6, 2015
1 parent e89ee89 commit f5e4829
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 40 deletions.
13 changes: 3 additions & 10 deletions Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,8 @@ module.exports = function(grunt) {
runPythonTests: {
command: './build/run_python_tests.sh'
},
buildVersion: {
command: './build/build_version_file.sh',
options: {
stdout: true,
stderr: true
}
},
buildAppEnginePackage: {
command: './build/build_app_engine_package.sh',
command: 'python ./build/build_app_engine_package.py src out/app_engine',
options: {
stdout: true,
stderr: true
Expand Down Expand Up @@ -170,10 +163,10 @@ module.exports = function(grunt) {

// set default tasks to run when grunt is called without parameters
grunt.registerTask('default', ['csslint', 'htmlhint', 'jscs', 'jshint',
'shell:buildVersion', 'runPythonTests', 'jstests']);
'runPythonTests', 'jstests']);
grunt.registerTask('runPythonTests', ['shell:buildAppEnginePackage', 'shell:runPythonTests']);
grunt.registerTask('jstests', ['closurecompiler:debug', 'jstdPhantom']);
grunt.registerTask('build', ['closurecompiler:debug', 'shell:buildVersion', 'shell:buildAppEnginePackage', 'grunt-chrome-build']);
grunt.registerTask('build', ['closurecompiler:debug', 'shell:buildAppEnginePackage', 'grunt-chrome-build']);
// also possible to call JavaScript directly in registerTask()
// or to call external tasks with grunt.loadTasks()
};
62 changes: 62 additions & 0 deletions build/build_app_engine_package.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#!/usr/bin/python

import os
import optparse
import shutil
import sys

USAGE = """%prog SRC_PATH DEST_PATH
Build the GAE source code package.
SRC_PATH Path to the source code root directory.
DEST_PATH Path to the root directory to push/deploy GAE from."""


def main(src_path, dest_path):
if os.path.exists(dest_path):
shutil.rmtree(dest_path)
os.makedirs(dest_path)

simply_copy_subdirs = ['bigquery', 'css', 'images', 'third_party']

for dirpath, dirnames, files in os.walk(src_path):
for subdir in simply_copy_subdirs:
if dirpath.endswith(subdir):
shutil.copytree(dirpath, os.path.join(dest_path, subdir))

if dirpath.endswith('html'):
dest_html_path = os.path.join(dest_path, 'html')
os.makedirs(dest_html_path)
for name in files:
# Template files must be in the root directory.
if name.endswith('_template.html'):
shutil.copy(os.path.join(dirpath, name), dest_path)
else:
shutil.copy(os.path.join(dirpath, name), dest_html_path)
elif dirpath.endswith('app_engine'):
for name in files:
if name.endswith('.py') and name.find('test') == -1 \
or name.endswith('.yaml'):
shutil.copy(os.path.join(dirpath, name), dest_path)
elif dirpath.endswith('js'):
for name in files:
# loopback.js is not compiled by Closure and needs to be copied
# separately.
if name == 'loopback.js':
dest_js_path = os.path.join(dest_path, 'js')
os.makedirs(dest_js_path)
shutil.copy(os.path.join(dirpath, name), dest_js_path)
break

os.system('build/build_version_file.sh')

if __name__ == '__main__':
parser = optparse.OptionParser(USAGE)
options, args = parser.parse_args()
if len(args) != 2:
print 'Error: Exactly 2 arguments required.'
parser.print_help()
sys.exit(1)
SRC_PATH = args[0]
DEST_PATH = args[1]
main(SRC_PATH, DEST_PATH)
30 changes: 0 additions & 30 deletions build/build_app_engine_package.sh

This file was deleted.

0 comments on commit f5e4829

Please sign in to comment.