Commits

Tarashish Mishra  committed 41b4d4b

gae / support code archive creation - rewrite as python, fixes issue #332

  • Participants
  • Parent commits a53c04d
  • Branches gae

Comments (0)

Files changed (2)

 
 # Automate creation of the support archive from a virtualenv site-packages directory
 support:
-	@# do NOT name it "site-packages", but "support":
-	@cp -a env/lib/python2.7/site-packages support
-	@# remove compiled code files:
-	@find support -name "*.pyc" -exec rm {} \;
-	@find support -name "*.pyo" -exec rm {} \;
-	@# documentation generation support not needed on GAE:
-	@rm -rf support/sphinx
-	@# package installers not needed/supported on GAE:
-	@rm -rf support/distribute support/pip
-	@# test support and suites not needed in production:
-	@rm -rf support/_pytest support/pytest*.py support/py.test*
-	@rm -rf support/py support/execnet support/pep8.py support/selenium
-	@rm -rf support/flask/testsuite support/werkzeug/testsuite
-	@# misc. egg and path stuff, not needed:
-	@rm -rf support/*.egg support/*.egg-info support/*.egg-link support/*.pth
-	@# we need to add a __init__.py to the namespace packages:
-	@touch support/flaskext/__init__.py support/xstatic/__init__.py support/xstatic/pkg/__init__.py
+	@python contrib/mksupport/mksupport.py --support
 
 # Create Dist archive with support
 supportdist:
-	@python setup.py sdist
-	@find dist -name 'moin-*.tar.gz' -exec tar -xzf {} -C dist/ \;
-	@find dist -mindepth 1 -maxdepth 1 -name "moin-*" -type d -exec cp -r support/ {} \;
-	@find dist -mindepth 1 -maxdepth 1 -name "moin-*" -type d -exec cp moin.py {} \;
-	@find dist -mindepth 1 -maxdepth 1 -name "moin-*" -type d -exec cp app.yaml {} \;
-	@find dist -mindepth 1 -maxdepth 1 -name "moin-*" -type d -exec cp wikiconfig_gae.py {} \;
-	@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" \;
-	@find dist -mindepth 1 -maxdepth 1 -name "moin-*" -type d -exec bash -c 'tar czf dist/`basename {}`_with_support.tar.gz -C dist/ `basename {}`' \;
-	@find dist -mindepth 1 -maxdepth 1 -name "moin-*" -type d -exec rm -rf {} \;
+	@python contrib/mksupport/mksupport.py --supportdist
 
 supporttgz:
 	@# create the support archive:
-	@tar czf moin2-support.tgz support
+	@python contrib/mksupport/mksupport.py --supporttgz
 
 # Run local appengine development server 
 gaeserver:

File contrib/mksupport/mksupport.py

+# Copyright: 2013 MoinMoin:Tarashish Mishra
+# License: GNU GPL v2 (or any later version), see LICENSE.txt for details.
+"""
+    Generate a directory containing all the necessary modules and files to run the application.
+    This directory can be compressed and distributed. The user can just unpack the compressed file and run the application
+"""
+
+
+import argparse
+import glob
+import os
+import shutil
+import tarfile
+from distutils.sysconfig import get_python_lib
+
+# The path to the directory where packages are currently installed
+LIB_PATH = get_python_lib()
+
+# The path of the directory where the modules from the the current python env need to be copied
+SUPPORT_PATH = 'support'
+
+# List of files and directories generally ignored when copying from python env
+GENERAL_IGNORED_FILES = ['*.pyc', '*.pyo', '*.egg', '*.egg-info', '*.egg-link', '*.pth']
+
+# List of files and directories to be ignored specific to the project
+SPECIFIC_IGNORED_FILES = ['sphinx', 'py.test*', 'pytest*.py', '_pytest', 'py', 'execnet', 'pep8.py', 'selenium', 'werkzeug/testsuite', 'flask/testsuite', 'distribute', 'pip']
+
+# Path to the tar file generated by setup.py sdist
+DIST_PATH = "dist/moin-2.0.0a0.tar.gz"
+
+# Directory to extract the tar file generated by setup.py sdist
+EXTRACTION_PATH = 'dist'
+
+# Name of the tar file containing all the modules and files needed for the app
+SUPPORT_TAR_NAME = 'moin-2.0.0a0_with_support.tar.gz'
+
+# Additional files to be added into the distribution package
+SUPPORT_FILES = ['moin.py', 'app.yaml', 'wikiconfig.py']
+
+# Files to be deleted from the distributing package
+DELETED_FILES = ['moin.egg-info', 'PKG-INFO', 'MANIFEST.in', 'setup.*', 'quickinstall*', 'Makefile']
+
+# Name of the tar archive to be created
+SUPPORT_FILE_NAME = 'moin2-support.tgz'
+
+DIST_DIR = DIST_PATH.replace('.tar.gz', '')
+CURRENT_DIR = os.getcwd()
+
+
+def delete_file_or_dir(path):
+    try:
+        if os.path.isdir(path):
+            shutil.rmtree(path)
+        else:
+            os.remove(path)
+    except OSError as err:
+        print str(err)
+
+
+def make_support():
+    shutil.copytree(LIB_PATH, SUPPORT_PATH)
+    for name in GENERAL_IGNORED_FILES + SPECIFIC_IGNORED_FILES:
+        for path in glob.glob(os.path.join(SUPPORT_PATH, name)):
+            delete_file_or_dir(path)
+
+
+def make_supportdist():
+    os.system('python setup.py sdist')
+    tar = tarfile.open(DIST_PATH)
+    tar.extractall(path=EXTRACTION_PATH)
+    tar.close()
+    shutil.copytree(SUPPORT_PATH, os.path.join(DIST_DIR, SUPPORT_PATH))
+
+    for filepath in SUPPORT_FILES:
+        shutil.copy(filepath, DIST_DIR)
+
+    for name in DELETED_FILES:
+        for path in glob.glob(os.path.join(DIST_DIR, name)):
+            delete_file_or_dir(path)
+    os.chdir(EXTRACTION_PATH)
+    tar = tarfile.open(SUPPORT_TAR_NAME, "w:gz")
+    tar.add(os.path.basename(os.path.normpath(DIST_DIR)))
+    tar.close()
+    os.chdir(CURRENT_DIR)
+    shutil.rmtree(DIST_DIR)
+
+
+def make_supporttgz():
+    tar = tarfile.open(SUPPORT_FILE_NAME, "w:gz")
+    tar.add(SUPPORT_PATH)
+    tar.close()
+
+parser = argparse.ArgumentParser()
+parser.add_argument("--support", help="create support directory which contains all the modules and files needed by the application to run", action="store_true")
+parser.add_argument("--supportdist", help="create distribution archive which the user can just extract and run ", action="store_true")
+parser.add_argument("--supporttgz", help="create support archive containing all the modules and files needed for the application", action="store_true")
+args = parser.parse_args()
+if args.support:
+    make_support()
+if args.supportdist:
+    make_supportdist()
+if args.supporttgz:
+    make_supporttgz()