gae / support code archive creation - rewrite as python, fixes issue #332 gae
authorTarashish Mishra <sunu0000@gmail.com>
Wed, 20 Mar 2013 00:54:41 +0530
branchgae
changeset 203641b4d4b74303
parent 1972 a53c04dd16b6
child 2037 9ed8069eea05
gae / support code archive creation - rewrite as python, fixes issue #332
Makefile
contrib/mksupport/mksupport.py
     1.1 --- a/Makefile	Sun Feb 10 20:02:54 2013 +0100
     1.2 +++ b/Makefile	Wed Mar 20 00:54:41 2013 +0530
     1.3 @@ -31,39 +31,15 @@
     1.4  
     1.5  # Automate creation of the support archive from a virtualenv site-packages directory
     1.6  support:
     1.7 -	@# do NOT name it "site-packages", but "support":
     1.8 -	@cp -a env/lib/python2.7/site-packages support
     1.9 -	@# remove compiled code files:
    1.10 -	@find support -name "*.pyc" -exec rm {} \;
    1.11 -	@find support -name "*.pyo" -exec rm {} \;
    1.12 -	@# documentation generation support not needed on GAE:
    1.13 -	@rm -rf support/sphinx
    1.14 -	@# package installers not needed/supported on GAE:
    1.15 -	@rm -rf support/distribute support/pip
    1.16 -	@# test support and suites not needed in production:
    1.17 -	@rm -rf support/_pytest support/pytest*.py support/py.test*
    1.18 -	@rm -rf support/py support/execnet support/pep8.py support/selenium
    1.19 -	@rm -rf support/flask/testsuite support/werkzeug/testsuite
    1.20 -	@# misc. egg and path stuff, not needed:
    1.21 -	@rm -rf support/*.egg support/*.egg-info support/*.egg-link support/*.pth
    1.22 -	@# we need to add a __init__.py to the namespace packages:
    1.23 -	@touch support/flaskext/__init__.py support/xstatic/__init__.py support/xstatic/pkg/__init__.py
    1.24 +	@python contrib/mksupport/mksupport.py --support
    1.25  
    1.26  # Create Dist archive with support
    1.27  supportdist:
    1.28 -	@python setup.py sdist
    1.29 -	@find dist -name 'moin-*.tar.gz' -exec tar -xzf {} -C dist/ \;
    1.30 -	@find dist -mindepth 1 -maxdepth 1 -name "moin-*" -type d -exec cp -r support/ {} \;
    1.31 -	@find dist -mindepth 1 -maxdepth 1 -name "moin-*" -type d -exec cp moin.py {} \;
    1.32 -	@find dist -mindepth 1 -maxdepth 1 -name "moin-*" -type d -exec cp app.yaml {} \;
    1.33 -	@find dist -mindepth 1 -maxdepth 1 -name "moin-*" -type d -exec cp wikiconfig_gae.py {} \;
    1.34 -	@find dist -mindepth 1 -maxdepth 1 -name "moin-*" -type d -exec sh -c "rm -rf {}/moin.egg-info {}/PKG-INFO {}/MANIFEST.in {}/setup.* {}/quickinstall* {}/Makefile" \;
    1.35 -	@find dist -mindepth 1 -maxdepth 1 -name "moin-*" -type d -exec bash -c 'tar czf dist/`basename {}`_with_support.tar.gz -C dist/ `basename {}`' \;
    1.36 -	@find dist -mindepth 1 -maxdepth 1 -name "moin-*" -type d -exec rm -rf {} \;
    1.37 +	@python contrib/mksupport/mksupport.py --supportdist
    1.38  
    1.39  supporttgz:
    1.40  	@# create the support archive:
    1.41 -	@tar czf moin2-support.tgz support
    1.42 +	@python contrib/mksupport/mksupport.py --supporttgz
    1.43  
    1.44  # Run local appengine development server 
    1.45  gaeserver:
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/contrib/mksupport/mksupport.py	Wed Mar 20 00:54:41 2013 +0530
     2.3 @@ -0,0 +1,103 @@
     2.4 +# Copyright: 2013 MoinMoin:Tarashish Mishra
     2.5 +# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
     2.6 +"""
     2.7 +    Generate a directory containing all the necessary modules and files to run the application.
     2.8 +    This directory can be compressed and distributed. The user can just unpack the compressed file and run the application
     2.9 +"""
    2.10 +
    2.11 +
    2.12 +import argparse
    2.13 +import glob
    2.14 +import os
    2.15 +import shutil
    2.16 +import tarfile
    2.17 +from distutils.sysconfig import get_python_lib
    2.18 +
    2.19 +# The path to the directory where packages are currently installed
    2.20 +LIB_PATH = get_python_lib()
    2.21 +
    2.22 +# The path of the directory where the modules from the the current python env need to be copied
    2.23 +SUPPORT_PATH = 'support'
    2.24 +
    2.25 +# List of files and directories generally ignored when copying from python env
    2.26 +GENERAL_IGNORED_FILES = ['*.pyc', '*.pyo', '*.egg', '*.egg-info', '*.egg-link', '*.pth']
    2.27 +
    2.28 +# List of files and directories to be ignored specific to the project
    2.29 +SPECIFIC_IGNORED_FILES = ['sphinx', 'py.test*', 'pytest*.py', '_pytest', 'py', 'execnet', 'pep8.py', 'selenium', 'werkzeug/testsuite', 'flask/testsuite', 'distribute', 'pip']
    2.30 +
    2.31 +# Path to the tar file generated by setup.py sdist
    2.32 +DIST_PATH = "dist/moin-2.0.0a0.tar.gz"
    2.33 +
    2.34 +# Directory to extract the tar file generated by setup.py sdist
    2.35 +EXTRACTION_PATH = 'dist'
    2.36 +
    2.37 +# Name of the tar file containing all the modules and files needed for the app
    2.38 +SUPPORT_TAR_NAME = 'moin-2.0.0a0_with_support.tar.gz'
    2.39 +
    2.40 +# Additional files to be added into the distribution package
    2.41 +SUPPORT_FILES = ['moin.py', 'app.yaml', 'wikiconfig.py']
    2.42 +
    2.43 +# Files to be deleted from the distributing package
    2.44 +DELETED_FILES = ['moin.egg-info', 'PKG-INFO', 'MANIFEST.in', 'setup.*', 'quickinstall*', 'Makefile']
    2.45 +
    2.46 +# Name of the tar archive to be created
    2.47 +SUPPORT_FILE_NAME = 'moin2-support.tgz'
    2.48 +
    2.49 +DIST_DIR = DIST_PATH.replace('.tar.gz', '')
    2.50 +CURRENT_DIR = os.getcwd()
    2.51 +
    2.52 +
    2.53 +def delete_file_or_dir(path):
    2.54 +    try:
    2.55 +        if os.path.isdir(path):
    2.56 +            shutil.rmtree(path)
    2.57 +        else:
    2.58 +            os.remove(path)
    2.59 +    except OSError as err:
    2.60 +        print str(err)
    2.61 +
    2.62 +
    2.63 +def make_support():
    2.64 +    shutil.copytree(LIB_PATH, SUPPORT_PATH)
    2.65 +    for name in GENERAL_IGNORED_FILES + SPECIFIC_IGNORED_FILES:
    2.66 +        for path in glob.glob(os.path.join(SUPPORT_PATH, name)):
    2.67 +            delete_file_or_dir(path)
    2.68 +
    2.69 +
    2.70 +def make_supportdist():
    2.71 +    os.system('python setup.py sdist')
    2.72 +    tar = tarfile.open(DIST_PATH)
    2.73 +    tar.extractall(path=EXTRACTION_PATH)
    2.74 +    tar.close()
    2.75 +    shutil.copytree(SUPPORT_PATH, os.path.join(DIST_DIR, SUPPORT_PATH))
    2.76 +
    2.77 +    for filepath in SUPPORT_FILES:
    2.78 +        shutil.copy(filepath, DIST_DIR)
    2.79 +
    2.80 +    for name in DELETED_FILES:
    2.81 +        for path in glob.glob(os.path.join(DIST_DIR, name)):
    2.82 +            delete_file_or_dir(path)
    2.83 +    os.chdir(EXTRACTION_PATH)
    2.84 +    tar = tarfile.open(SUPPORT_TAR_NAME, "w:gz")
    2.85 +    tar.add(os.path.basename(os.path.normpath(DIST_DIR)))
    2.86 +    tar.close()
    2.87 +    os.chdir(CURRENT_DIR)
    2.88 +    shutil.rmtree(DIST_DIR)
    2.89 +
    2.90 +
    2.91 +def make_supporttgz():
    2.92 +    tar = tarfile.open(SUPPORT_FILE_NAME, "w:gz")
    2.93 +    tar.add(SUPPORT_PATH)
    2.94 +    tar.close()
    2.95 +
    2.96 +parser = argparse.ArgumentParser()
    2.97 +parser.add_argument("--support", help="create support directory which contains all the modules and files needed by the application to run", action="store_true")
    2.98 +parser.add_argument("--supportdist", help="create distribution archive which the user can just extract and run ", action="store_true")
    2.99 +parser.add_argument("--supporttgz", help="create support archive containing all the modules and files needed for the application", action="store_true")
   2.100 +args = parser.parse_args()
   2.101 +if args.support:
   2.102 +    make_support()
   2.103 +if args.supportdist:
   2.104 +    make_supportdist()
   2.105 +if args.supporttgz:
   2.106 +    make_supporttgz()