def execute(self, args=None): prevCwd = os.getcwd() noseroot = join(join(join(alePath('recipes_installed'), 'test'), 'pkgs'), 'nose-0.11.0') coverageroot = join(join(join(alePath('recipes_installed'), 'test'), 'pkgs'), 'coverage-3.2b3') command = join(join(noseroot, 'bin/'), 'nosetests') args = [] if not args else args args += [ '--nologcapture', '-m', 'test', '-e', 'lib.*', '-e', ".*\.ale.*", ] fullcommandwithargs = [command] + args relcommandwithargs = [relpath(command)] + args logging.info('Executing %s' % relcommandwithargs) pythonpath = ':'.join([noseroot] + getGaeLibs()) p = Popen(fullcommandwithargs, env={'PYTHONPATH': pythonpath, 'PATH': os.environ['PATH']}) # todo: just yield a generator or get all .py files sts = os.waitpid(p.pid, 0)[1] return sts
def execute(self, args=None): prevCwd = os.getcwd() noseroot = join(join(join(alePath('recipes_installed'), 'test'), 'pkgs'), 'nose-0.11.0') coverageroot = join(join(join(alePath('recipes_installed'), 'test'), 'pkgs'), 'coverage-3.2b3') command = join(join(noseroot, 'bin/'), 'nosetests') args = [] if not args else args args += [ '--with-coverage', '--cover-erase', '--cover-inclusive', '--cover-exclude-package', 'pickle,mimetypes,quopri,weakref,facebook,appengine_utilities,django,email,encodings,xml,yaml,ctypes,json,lib,codeop,hmac,sha,sgmllib,uuid,mockito,simplejson,subprocess,smtplib,uu,md5,markupbase,icalendar,hashlib,gzip,getpass,_strptime,nose,webob,urllib,google,ssl,wsgiref,urlparse,rfc822,mimetools,httplib,dummy_thread,cgi,calendar,base64,Cookie' , '-m', 'test', '-e', 'lib.*', '-e', ".*\.ale.*", ] fullcommandwithargs = [command] + args relcommandwithargs = [relpath(command)] + args logging.info('Executing %s' % relcommandwithargs) pythonpath = ':'.join([noseroot, coverageroot] + getGaeLibs()) p = Popen(fullcommandwithargs, env={'PYTHONPATH': pythonpath, 'PATH': os.environ['PATH']}) sts = os.waitpid(p.pid, 0)[1] return sts
def install(self, args=None): download('http://www.lacusveris.com/PythonTidy/PythonTidy-1.16.python', 'pythontidy.py') mkdir(finalTidyDir) shutil.move(join(alePath('tmp'), 'pythontidy.py'), finalTidyPath) os.system('chmod +x %s' % finalTidyPath) logging.info('Patching tidy to wrap at 120 columns instead of 80 ...') os.system('patch %s %s' % (finalTidyPath, join(alePath('recipes_all/tidy/'), 'tidy80col.patch')))
def install(self, args=None): extractPath = os.path.join(os.path.join(alePath('recipes_installed'), 'pyflakes'), 'pkgs') downloadAndExtract('http://pypi.python.org/packages/source/p/pyflakes/pyflakes-0.3.0.tar.gz', extractPath) pyflakesPyPath = join(alePath('recipes_installed/pyflakes/pkgs/pyflakes-0.3.0/pyflakes/scripts'), 'pyflakes.py') patch1Path = join(alePath('recipes_all/pyflakes/'), 'pyflakeignore.patch') logging.info('Patching pyflakes to allow the pyflakes:ignore directive ...') os.system('patch %s %s' % (pyflakesPyPath, patch1Path))
def install(self, args=None): extractPath = os.path.join(os.path.join(alePath('recipes_installed'), 'test'), 'pkgs') downloadAndExtract('http://python-nose.googlecode.com/files/nose-0.11.0.tar.gz', extractPath) downloadAndExtract('http://pypi.python.org/packages/source/c/coverage/coverage-3.2b3.tar.gz', extractPath) coverPyPath = join(alePath('recipes_installed/test/pkgs/nose-0.11.0/nose/plugins'), 'cover.py') patch1Path = join(alePath('recipes_all/test/'), 'excludecoveragepatch.patch') patch2Path = join(alePath('recipes_all/test/'), 'excludenosepatch.patch') logging.info('Patching coverage plugin...') os.system('patch %s %s' % (coverPyPath, patch1Path)) os.system('patch %s %s' % (coverPyPath, patch2Path)) logging.info('Adding to .gitignore...') gitignore('.coverage')
def tidy(file): tmpFile = join(alePath('tmp'), os.path.split(file)[1] + '_tmp') command = finalTidyPath + ' ' + file + ' ' + tmpFile logging.info('Tidying %s' % file) returnCode = os.system(command) if returnCode == 0: shutil.move(tmpFile, file) return returnCode
def download(remotePath, localFileNameInTmpDir=None): mkdir(alePath('tmp')) if not localFileNameInTmpDir: (head, tail) = os.path.split(remotePath) localDlPath = os.path.join(alePath('tmp'), tail) else: localDlPath = os.path.join(alePath('tmp'), localFileNameInTmpDir) if not os.path.exists(localDlPath): logging.info('Downloading %s' % remotePath) curlCmd = 'curl -L -o %s %s' % (localDlPath, remotePath) os.system(curlCmd) else: logging.info('Using cached file %s' % relpath(localDlPath)) pass # we should do an MD5 check here return localDlPath
def getGaeLibs(): from ale.core import isCommandInstalled if isCommandInstalled('gae'): return [os.path.join(alePath('recipes_installed/gae/pkgs/google_appengine_1.3.1/google_appengine/'), d) for d in ('.', 'lib/django', 'lib/webob', 'lib/yaml/lib', 'lib/antlr3')] if os.path.exists('/usr/local/google_appine'): return [os.path.join('/usr/local/google_appine', d) for d in ('.', 'lib/django', 'lib/webob', 'lib/yaml/lib', 'lib/antlr3')] return []
def execute(self, args=None): pyflakesroot = join(join(join(alePath('recipes_installed'), 'pyflakes'), 'pkgs'), 'pyflakes-0.3.0') command = join(pyflakesroot, 'bin/pyflakes') allSuccess = True def check(file): p = Popen([command, file], env={'PYTHONPATH': pyflakesroot}) # todo: just yield a generator or get all .py files sts = os.waitpid(p.pid, 0)[1] return sts return recurse(check, 'py', *args)
def execute(self, args=None): modipydroot = join(join(join(alePath('recipes_installed'), 'pyautotest'), 'pkgs'), 'ishikawa-modipyd-1516eeb') arg = '.' if not args else args[0] command = join(modipydroot, 'bin/pyautotest') logging.info('Executing %s %s' % (relpath(command), arg)) print 'Modify a source file to trigger any dependent tests to re-execute' commandwithargs = [command, arg] if arg else [command] pythonpath = ':'.join([modipydroot] + ['.'] + ['lib'] + getGaeLibs()) p = Popen(commandwithargs, env={'PATH':os.environ['PATH'], 'PYTHONPATH': pythonpath}) # todo: just yield a generator or get all .py files sts = os.waitpid(p.pid, 0)[1] return sts
def execute(self, args=None): ipythonroot = join(join(join(alePath('recipes_installed'), 'shell'), 'pkgs'), 'ipython-0.10') command = join(ipythonroot, 'ipython.py') logging.info('%s' % command) logging.info('Executing %s %s' % (relpath(command), args)) commandwithargs = [command] + args if args else [command] commandwithargs += ['-ipythondir', join(ipythonroot, 'UserConfig')] commandwithargs += ['-color_info'] pythonpath = ':'.join(['.'] + ['lib'] + getGaeLibs()) p = Popen(commandwithargs, env={'PATH':os.environ['PATH'], 'PYTHONPATH': pythonpath, 'HOME': os.environ['HOME']}) sts = os.waitpid(p.pid, 0)[1] return sts
#!/usr/bin/python # -*- coding: utf-8 -*- import os import logging from os.path import join as join from aleconfig import alePath from utils import extract, download, relpath, getGaeLibs from ale.base import Command from subprocess import Popen extractPath = os.path.join(os.path.join(alePath('recipes_installed'), 'pyautotest'), 'pkgs') class PyautotestCommand(Command): name = 'pyautotest' shorthelp = 'run pyautotest (continuous test runner) against the project or pyautotest [dir]' tags = 'experimental' def execute(self, args=None): modipydroot = join(join(join(alePath('recipes_installed'), 'pyautotest'), 'pkgs'), 'ishikawa-modipyd-1516eeb') arg = '.' if not args else args[0] command = join(modipydroot, 'bin/pyautotest') logging.info('Executing %s %s' % (relpath(command), arg)) print 'Modify a source file to trigger any dependent tests to re-execute' commandwithargs = [command, arg] if arg else [command]
def install(self, args=None): download("http://github.com/jcrocholl/pep8/raw/49fb01f94e27242c5604bbc3cb04ab7e8a593e34/pep8.py", "pep8.py") mkdir(pep8root) shutil.move(join(alePath("tmp"), "pep8.py"), finalPep8Path) os.system("chmod +x %s" % finalPep8Path)
#!/usr/bin/python # -*- coding: utf-8 -*- import os from os.path import join as join from aleconfig import alePath from utils import download, recurse, mkdir from ale.base import Command from subprocess import Popen import shutil pep8root = join(os.path.join(alePath("recipes_installed"), "pep8"), "pkgs") finalPep8Path = join(pep8root, "pep8.py") class Pep8Command(Command): name = "pep8" shorthelp = "run PEP8 against the project" def execute(self, args=None): command = join(pep8root, "pep8.py") allSuccess = True def check(file): # print 'Checking %s' % file commandWithArgs = [command, "--show-source", "--statistics", "--count", "--show-pep8", file] p = Popen(commandWithArgs, env={"PYTHONPATH": pep8root}) sts = os.waitpid(p.pid, 0)[1] return sts
def execute(self, args=None): validTemplateNames = ['helloworld', 'helloworldwebapp', 'pale'] + customStarterApps if not args: print self.shorthelp print 'available app templates:' print 'helloworld -- simple helloworld app' print 'helloworldwebapp -- simple helloworld app using webapp fmk' print 'xmppsendandreply -- simple xmpp (instant message) send and reply' print 'emailreceive -- simple e-mail receive example' print 'emailsendui -- simple e-mail send example' print 'deferredemail -- simple deferred lib queued e-mail send example' print 'starter_pale -- a basic project layout with buckets for most things you could want and an import fix built in' else: templateName = args[0].lower() if templateName not in validTemplateNames: print 'Unknown app name %s' % args[0] return if templateName in customStarterApps: tarballurl = 'http://github.com/mpstx/appengine_py_%s/tarball/master' % templateName tmpPath = join(join(alePath('tmp'), templateName + '.tar.gz')) download(tarballurl, '%s.tar.gz' % templateName) logging.info("Extracting %s here" % templateName) os.system('tar xzf %s --strip 1 -C .' % tmpPath) elif templateName == 'helloworld': logging.info('creating ./helloworld.py') FILE = open('./helloworld.py', 'w') FILE.write(""" print 'Content-Type: text/plain' print '' print 'Hello, world! This is a bare bones app engine application' """) FILE.close() logging.info('creating ./app.yaml') FILE = open('./app.yaml', 'w') FILE.write(""" application: helloworld version: 1 runtime: python api_version: 1 handlers: - url: /.* script: helloworld.py """) FILE.close() elif templateName == 'helloworldwebapp': logging.info('creating ./helloworld.py') FILE = open('./helloworld.py', 'w') FILE.write(""" from google.appengine.ext import webapp from google.appengine.ext.webapp.util import run_wsgi_app class MainPage(webapp.RequestHandler): def get(self): self.response.headers['Content-Type'] = 'text/plain' self.response.out.write('Hello, webapp World!') application = webapp.WSGIApplication( [('/', MainPage)], debug=True) def main(): run_wsgi_app(application) if __name__ == "__main__": main() """) FILE.close() logging.info('creating ./app.yaml') FILE = open('./app.yaml', 'w') FILE.write(""" application: helloworldwebapp version: 1 runtime: python api_version: 1 handlers: - url: /.* script: helloworld.py """) FILE.close() else: pkgPath = join(join(alePath('recipes_installed'), 'createapp'), 'pkgs') templateZipPath = join(pkgPath, '%s.zip' % templateName) if os.path.exists(templateZipPath): extract(templateZipPath, '.') gitignore('tmp') else: logging.error('Could not find template: %s' % templateName) return return 0
#!/usr/bin/python # -*- coding: utf-8 -*- import os import logging from os.path import join as join from ale.base import Command from aleconfig import alePath from utils import extract, download, relpath, getGaeLibs from subprocess import Popen extractPath = os.path.join(os.path.join(alePath('recipes_installed'), 'shell'), 'pkgs') class ShellCommand(Command): name = 'shell' shorthelp = 'Launch iPython (local) shell with the proper python path' def execute(self, args=None): ipythonroot = join(join(join(alePath('recipes_installed'), 'shell'), 'pkgs'), 'ipython-0.10') command = join(ipythonroot, 'ipython.py') logging.info('%s' % command) logging.info('Executing %s %s' % (relpath(command), args)) commandwithargs = [command] + args if args else [command] commandwithargs += ['-ipythondir', join(ipythonroot, 'UserConfig')] commandwithargs += ['-color_info'] pythonpath = ':'.join(['.'] + ['lib'] + getGaeLibs())
#!/usr/bin/python # -*- coding: utf-8 -*- import os import logging from os.path import join as join from aleconfig import alePath from utils import download, mkdir, recurse from ale.base import Command import shutil finalTidyDir = join(os.path.join(alePath('recipes_installed'), 'tidy'), 'pkgs') finalTidyPath = join(finalTidyDir, 'pythontidy.py') class PythonTidyCommand(Command): name = 'tidy' shorthelp = 'run PythonTidy to beautify the python source files' tags = 'experimental' def execute(self, args=None): def tidy(file): tmpFile = join(alePath('tmp'), os.path.split(file)[1] + '_tmp') command = finalTidyPath + ' ' + file + ' ' + tmpFile logging.info('Tidying %s' % file) returnCode = os.system(command) if returnCode == 0: shutil.move(tmpFile, file) return returnCode