Skip to content
This repository has been archived by the owner on Aug 3, 2023. It is now read-only.

Commit

Permalink
pep8
Browse files Browse the repository at this point in the history
  • Loading branch information
thet committed May 15, 2014
1 parent 8cae8e3 commit ff81d76
Showing 1 changed file with 129 additions and 93 deletions.
222 changes: 129 additions & 93 deletions jqt_checkout_build
Expand Up @@ -9,15 +9,16 @@
# Added to p.a.jqt by Rok Garbas


import StringIO
import datetime
import os
import shlex
import shutil
import urllib2
import subprocess
import tarfile
import tempfile
import StringIO
import subprocess
import datetime
import urllib2


JQ_TOOLS_VERSION = 'v1.2.7'
JQ_TOOLS_DOWNLOAD_URL = 'http://github.com/jquerytools/jquerytools/tarball/'+JQ_TOOLS_VERSION
Expand All @@ -32,13 +33,14 @@ def run_hooks(name, hooks, kw):
kw = hook(**kw)
return kw


def build(name, download_url, hooks=dict(), **kw):

kw['name'] = name
kw['download_url'] = download_url

# create temporary directory
kw['tmp_dir'] = tempfile.mkdtemp(prefix='build--'+name)
kw['tmp_dir'] = tempfile.mkdtemp(prefix='build--{}'.format(name))

# download the archive
archive = urllib2.urlopen(download_url).fp.read()
Expand All @@ -64,15 +66,19 @@ def build(name, download_url, hooks=dict(), **kw):

kw['source_dir_name'] = out[0]
kw['source_dir'] = os.path.join(kw['tmp_dir'], kw['source_dir_name'])
kw['build_dir'] = os.path.join(kw['tmp_dir'], kw['source_dir_name']+'-build')
kw['build_dir'] = os.path.join(
kw['tmp_dir'],
'{}-build'.format(kw['source_dir_name'])
)

# before hooks
kw = run_hooks('before', hooks, kw)

for dirpath, dirnames, filenames in os.walk(kw['build_dir']):
for filename in filenames:
kw['filename'] = os.path.join(dirpath, filename)
kw['short_filename'] = kw['filename'][len(kw['build_dir']) + 1:]
kw['short_filename'] =\
kw['filename'][len(kw['build_dir']) + 1:]

print '-' * 80
print 'FILE: ' + kw['short_filename']
Expand All @@ -91,107 +97,122 @@ def build(name, download_url, hooks=dict(), **kw):

def main():
"""
master plan:
* pull version from http://github.com/jquerytools/jquerytools/tarball/v${VERSION}
* untar and make usual build it like ant is doing it (look build.xml)
* merge files like its is done in README.txt and copy it to plone/app/jquerytools/browser folder
master plan:
* pull version from
http://github.com/jquerytools/jquerytools/tarball/v${VERSION}
* untar and make usual build it like ant is doing it (look build.xml)
* merge files like its is done in README.txt and copy it to
plone/app/jquerytools/browser folder
"""

# TODO: we could make get values bellow bia sys.args (argparse)


PLONE_MAPPING = {
'jquery.tools.js': [
'jquery.tools:overlay/overlay.js',
'jquery.tools:scrollable/scrollable.js',
'jquery.tools:tabs/tabs.js',
'jquery.tools:toolbox/toolbox.history.js',
'jquery.tools:toolbox/toolbox.expose.js',
'jquery.tools:tooltip/tooltip.js',
],
'jquery.tools:overlay/overlay.js',
'jquery.tools:scrollable/scrollable.js',
'jquery.tools:tabs/tabs.js',
'jquery.tools:toolbox/toolbox.history.js',
'jquery.tools:toolbox/toolbox.expose.js',
'jquery.tools:tooltip/tooltip.js',
],
'jquery.tools.plugins.js': [
'jquery.tools:overlay/overlay.apple.js',
'jquery.tools:scrollable/scrollable.autoscroll.js',
'jquery.tools:scrollable/scrollable.navigator.js',
'jquery.tools:tabs/tabs.slideshow.js',
'jquery.tools:toolbox/toolbox.flashembed.js',
'jquery.tools:toolbox/toolbox.mousewheel.js',
'jquery.tools:tooltip/tooltip.dynamic.js',
'jquery.tools:tooltip/tooltip.slide.js',
],
'jquery.tools:overlay/overlay.apple.js',
'jquery.tools:scrollable/scrollable.autoscroll.js',
'jquery.tools:scrollable/scrollable.navigator.js',
'jquery.tools:tabs/tabs.slideshow.js',
'jquery.tools:toolbox/toolbox.flashembed.js',
'jquery.tools:toolbox/toolbox.mousewheel.js',
'jquery.tools:tooltip/tooltip.dynamic.js',
'jquery.tools:tooltip/tooltip.slide.js',
],
# 'jquery.tools.dateinput.css': [
# 'jquery.tools:dateinput/skin1.css',
# 'jquery.tools:dateinput/skin1.css',
# ],
'jquery.tools.dateinput.js': [
'jquery.tools:dateinput/dateinput.js',
],
'jquery.tools:dateinput/dateinput.js',
],
'jquery.tools.rangeinput.js': [
'jquery.tools:rangeinput/rangeinput.js',
],
'jquery.tools:rangeinput/rangeinput.js',
],
'jquery.tools.validator.js': [
'jquery.tools:validator/validator.js',
],
'jquery.tools:validator/validator.js',
],
'jquery.form.js': [
'jquery.form:jquery.form.js',
]
'jquery.form:jquery.form.js',
]
}

#
# run build for all libs
build('jquery.tools', JQ_TOOLS_DOWNLOAD_URL,
version=JQ_TOOLS_VERSION,
plone_mapping=PLONE_MAPPING,
today=datetime.datetime.today().strftime("%Y-%m-%d %H:%M"),
jslint=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'lib', 'jslint.js'),
rhino=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'lib', 'rhino.jar'),
compiler=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'lib', 'compiler.jar'),
plone_dir=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'plone', 'app', 'jquerytools', 'browser'),
hooks = {'before': [
jq_tools_before_hook,
plone_before_hook],
'per_file': [
version_hook,
date_hook,
lint_hook,
minify_hook,
plone_file_hook],
})
build('jquery.form', JQ_FORM_URL,
plone_mapping=PLONE_MAPPING,
today=datetime.datetime.today().strftime("%Y-%m-%d %H:%M"),
jslint=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'lib', 'jslint.js'),
rhino=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'lib', 'rhino.jar'),
compiler=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'lib', 'compiler.jar'),
plone_dir=os.path.join(os.path.abspath(os.path.dirname(__file__)), 'plone', 'app', 'jquerytools', 'browser'),
hooks = {'before': [
jq_form_before_hook,
plone_before_hook],
'per_file': [
lint_hook,
minify_hook,
plone_file_hook],
})
basepath = os.path.abspath(os.path.dirname(__file__))
build(
'jquery.tools',
JQT_DOWNLOAD,
version=JQT_VERSION,
plone_mapping=PLONE_MAPPING,
today=datetime.datetime.today().strftime("%Y-%m-%d %H:%M"),
jslint=os.path.join(basepath, 'lib', 'jslint.js'),
rhino=os.path.join(basepath, 'lib', 'rhino.jar'),
compiler=os.path.join(basepath, 'lib', 'compiler.jar'),
plone_dir=os.path.join(
basepath, 'plone', 'app', 'jquerytools', 'browser'),
hooks={
'before': [
jq_tools_before_hook,
plone_before_hook
],
'per_file': [
version_hook,
date_hook,
lint_hook,
minify_hook,
plone_file_hook
],
})

build(
'jquery.form',
JQ_FORM_URL,
plone_mapping=PLONE_MAPPING,
today=datetime.datetime.today().strftime("%Y-%m-%d %H:%M"),
jslint=os.path.join(basepath, 'lib', 'jslint.js'),
rhino=os.path.join(basepath, 'lib', 'rhino.jar'),
compiler=os.path.join(basepath, 'lib', 'compiler.jar'),
plone_dir=os.path.join(
basepath, 'plone', 'app', 'jquerytools', 'browser'),
hooks={
'before': [
jq_form_before_hook,
plone_before_hook
],
'per_file': [
lint_hook,
minify_hook,
plone_file_hook
],
})


def jq_tools_before_hook(**kw):
shutil.copytree(
os.path.join(kw['source_dir'], 'src'),
kw['build_dir'])
os.path.join(kw['source_dir'], 'src'),
kw['build_dir'])

# FIXME: this should actually copy all *.js files from lib directory
shutil.copy2(
os.path.join(kw['source_dir'], 'lib', 'jslint.js'),
os.path.join(kw['build_dir'], 'jslint.js'))

os.path.join(kw['source_dir'], 'lib', 'jslint.js'),
os.path.join(kw['build_dir'], 'jslint.js'))

return kw


def jq_form_before_hook(**kw):
shutil.copytree(
os.path.join(kw['source_dir']),
kw['build_dir'])
os.path.join(kw['source_dir']),
kw['build_dir'])
return kw


def plone_before_hook(**kw):
for script in kw['plone_mapping']:
if not script.startswith(kw['name']):
Expand All @@ -208,20 +229,24 @@ def plone_before_hook(**kw):
f.close()

# FIXME: probably a better way to do this
if os.path.exists(os.path.join(kw['source_dir'], 'test', 'dateinput', 'skin1.css')):
if os.path.exists(
os.path.join(kw['source_dir'], 'test', 'dateinput', 'skin1.css')):
shutil.copy(
os.path.join(kw['source_dir'], 'test', 'dateinput', 'skin1.css'),
os.path.join(kw['build_dir'], 'dateinput'))
return kw


def version_hook(**kw):
if not kw['filename'].endswith('.js') or \
kw['filename'].endswith('jslint.js'):
return kw
args_ = shlex.split('sed -i -e "s/@VERSION/%(version)s/g" %(filename)s' % kw)
args_ = shlex.split(
'sed -i -e "s/@VERSION/%(version)s/g" %(filename)s' % kw)
subprocess.check_call(args_)
return kw


def date_hook(**kw):
if not kw['filename'].endswith('.js') or \
kw['filename'].endswith('jslint.js'):
Expand All @@ -231,21 +256,24 @@ def date_hook(**kw):
subprocess.check_call(args_)
return kw


def lint_hook(**kw):
if not kw['filename'].endswith('.js') or \
kw['filename'].endswith('jslint.js'):
return kw
# lint (http://www.jslint.com/lint.html)
output = subprocess.Popen(
shlex.split('java -jar %(rhino)s %(jslint)s %(filename)s ' % kw),
stdout=subprocess.PIPE).communicate()
shlex.split('java -jar %(rhino)s %(jslint)s %(filename)s ' % kw),
stdout=subprocess.PIPE
).communicate()
if output[0].startswith('jslint: No problems found in'):
print ' |-> jslint status: OK'
else:
print ' |-> jslint status: ERROR'
print '\n'.join([(' '*6)+i for i in output[0].split('\n')])
print '\n'.join([(' ' * 6) + i for i in output[0].split('\n')])
return kw


def minify_hook(**kw):
if not kw['filename'].endswith('.js') or \
kw['filename'].endswith('jslint.js'):
Expand All @@ -260,21 +288,26 @@ def minify_hook(**kw):
print ' |-> minified to: ' + kw['short_filename'][:-3] + '.min.js'
return kw


def plone_file_hook(**kw):
if (not kw['filename'].endswith('.js') and \
not kw['filename'].endswith('.css')) or \
kw['filename'].endswith('jslint.js'):
if (
not kw['filename'].endswith('.js') and
not kw['filename'].endswith('.css')
) or kw['filename'].endswith('jslint.js'):
return kw
for script in kw['plone_mapping']:
if kw['name'] + ':' + kw['short_filename'] in kw['plone_mapping'][script]:
if kw['name'] + ':' + kw['short_filename']\
in kw['plone_mapping'][script]:
build_filename = os.path.join(kw['plone_dir'], script)
if kw['filename'].endswith('.js'):
source_filename = os.path.join(kw['build_dir'], kw['short_filename'][:-3] + '.js')
source_filename = os.path.join(
kw['build_dir'], kw['short_filename'][:-3] + '.js')
else:
source_filename = os.path.join(kw['build_dir'], kw['short_filename'])
source_filename = os.path.join(
kw['build_dir'], kw['short_filename'])

g = open(source_filename)
content = g.read()+'\n'
content = g.read() + '\n'
g.close()

f = open(build_filename, 'a+')
Expand All @@ -285,18 +318,21 @@ def plone_file_hook(**kw):

if kw['filename'].endswith('.js'):
# also do .min.js
source_filename = os.path.join(kw['build_dir'], kw['short_filename'][:-3] + '.min.js')
source_filename = os.path.join(
kw['build_dir'], kw['short_filename'][:-3] + '.min.js')

g = open(source_filename)
content = g.read()+'\n'
content = g.read() + '\n'
g.close()

build_filename = build_filename[:-3] + '.min.js'
f = open(build_filename, 'a+')
f.write(content)
f.close()

print ' |-> plone: ' + build_filename[len(kw['plone_dir']) + 1:]
print ' |-> plone: {}'.format(
build_filename[len(kw['plone_dir']) + 1:]
)
return kw


Expand Down

1 comment on commit ff81d76

@mister-roboto
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TESTS FAILED
Mr.Roboto url : http://jenkins.plone.org/roboto/get_info?push=c4398885becd464283fc24ae9fa6fce6
[FAILURE] kgs-plone.app.jquerytools-plone-4.3-python-2.6 kgs
[FAILURE] kgs-plone.app.jquerytools-plone-4.3-python-2.7 kgs
[SUCCESS] kgs-plone.app.jquerytools-plone-5.0-python-2.7 kgs

Please sign in to comment.