Page MenuHomePhabricator
Paste P534

add_banana_checker.py
ActivePublic

Authored by Legoktm on Apr 19 2015, 6:33 AM.
Tags
None
Referenced Files
F122166: add_banana_checker.py
Apr 20 2015, 11:36 PM
F117017: add_banana_checker.py
Apr 19 2015, 6:36 AM
F117016: add_banana_checker.py
Apr 19 2015, 6:33 AM
Subscribers
None
#!/usr/bin/env python3
import json
import os
import subprocess
import sys
if os.path.exists('package.json'):
print('package.json already exists')
sys.exit(1)
ext = os.getcwd().split('/')[-1]
print('Configuring banana checker for %s extension...' % ext)
grunt_file = """/*!
* Grunt file
*
* @package %s
*/
/*jshint node:true */
module.exports = function ( grunt ) {
grunt.loadNpmTasks( 'grunt-banana-checker' );
grunt.initConfig( {
banana: {
all: %s
}
} );
grunt.registerTask( 'test', [ 'banana' ] );
grunt.registerTask( 'default', 'test' );
};
"""
if os.path.exists('extension.json'):
with open('extension.json') as f:
ext_info = json.load(f)
dirs = set()
for name, values in ext_info['MessagesDirs'].items():
dirs = dirs.union(set(values))
else:
print('No extension.json, assuming files are in i18n directory')
dirs = {'i18n'}
dirs = {x + '/' for x in dirs}
with open('Gruntfile.js', 'w') as f:
f.write(grunt_file % (ext, json.dumps(sorted(list(dirs)))))
package_json = """{
"name": "%s",
"version": "0.0.0",
"private": true,
"description": "Build tools for the %s extension.",
"scripts": {
"test": "grunt test"
},
"devDependencies": {
"grunt": "0.4.5",
"grunt-cli": "0.1.13",
"grunt-banana-checker": "0.2.1"
}
}
""" % (ext.lower(), ext)
with open('package.json', 'w') as f:
f.write(package_json)
subprocess.call(['npm', 'install'])
res = subprocess.call(['npm', 'test'])
if res != 0:
print('Error: npm test failed.')
sys.exit(1)
else:
print('Yay, npm test passed!')
# Add node_modules to gitignore...
if os.path.exists('.gitignore'):
add = True
with open('.gitignore') as f:
for line in f.read().splitlines():
if line.strip().startswith('node_modules'):
add = False
break
if add:
with open('.gitignore', 'a') as f:
f.write('node_modules/\n')
print('Added "node_modules/" to .gitignore')
else:
with open('.gitignore', 'w') as f:
f.write('node_modules/\n')
print('Created .gitignore with "node_modules/"')
subprocess.call(['git', 'add', 'package.json', 'Gruntfile.js', '.gitignore'])
msg = 'test: Configuring banana-checker for i18n messages'
subprocess.call(['git', 'commit', '-m', msg])
sha1 = subprocess.check_output(['git', 'log', '--oneline', '-n', '1']).decode().split(' ', 1)[0]
subprocess.call(['git', 'push', 'gerrit', 'HEAD:refs/for/master'])
subprocess.call(['ssh', '-p' , '29418', 'gerrit.wikimedia.org', 'gerrit', 'review', '-m', '"check experimental"', sha1])

Event Timeline

Legoktm changed the title of this paste from untitled to add_banana_checker.py.
Legoktm updated the paste's language from autodetect to python.