Permalink
Browse files

add escape(); fix tests

  • Loading branch information...
1 parent 5578028 commit 1e4d08bb1ea9ef83fdb3317a3b10f406ca31b8a8 @gawel committed Jan 13, 2013
View
16 chut/__init__.py
@@ -26,6 +26,7 @@
'virtualenv', 'pip',
'ssh', 'sudo',
'path', 'pwd', # path is posixpath, pwd return os.getcwd()
+ 'escape', 'e', # e is escape()
]
__not_piped__ = ['chmod', 'cp', 'mkdir', 'mv', 'rm', 'rmdir', 'touch']
@@ -55,6 +56,17 @@ def check_sudo():
raise OSError('Not able to run sudo.')
+def escape(value):
+ chars = "'[]() "
+ esc = '\\'
+ if isinstance(value, six.binary_type):
+ chars = chars.encode('ascii')
+ esc = esc.encode('ascii')
+ for c in chars:
+ value = value.replace(c, esc + c)
+ return value
+
+
class Environ(dict):
"""Manage os.environ"""
@@ -580,7 +592,8 @@ class SSH(Base):
"""A ssh server"""
def join(self, *args):
- return '%s%s' % (self, posixpath.join(*args))
+ p = posixpath.join(*args)
+ return '%s"%s"' % (self, escape(p))
@property
def host(self):
@@ -631,6 +644,7 @@ def __getattr__(self, attr):
sh = Chut('sh')
sudo = Chut('sudo', '-s')
test = Command('test')
+e = escape
def wraps_module(mod):
View
4 chut/recipe.py
@@ -13,10 +13,10 @@ def __init__(self, buildout, name, options):
self.options['destination'] = dest
def scripts(self):
- import chut as sh
+ from chut.scripts import chutify
args = ['--destination', self.options.get('destination')]
for line in self.options.get('locations', '.').split():
- sh.chutify(args + [line])
+ chutify(args + [line])
def run(self, update=False):
import chut as sh
View
775 docs/_static/binaries/chutify
7 additions, 768 deletions not shown because the diff is too large. Please use a local Git client to view these changes.
View
2 docs/_static/binaries/chutify-examples
1 addition, 1 deletion not shown because the diff is too large. Please use a local Git client to view these changes.
View
2 docs/_static/binaries/ssh-copy-id
1 addition, 1 deletion not shown because the diff is too large. Please use a local Git client to view these changes.
View
2 docs/_static/binaries/translate
1 addition, 1 deletion not shown because the diff is too large. Please use a local Git client to view these changes.
View
2 docs/ssh.rst
@@ -24,6 +24,6 @@ Or on another server::
You can use your ssh instance to get some remote file::
>>> sh.rsync(srv1.join('~/p0rn'), '.', pipe=True)
- 'rsync gawel@srv:~/p0rn .'
+ 'rsync gawel@srv:"~/p0rn" .'
View
5 tests.py
@@ -137,10 +137,11 @@ def test_chutify(self):
def test_recipe(self):
r = Recipe({'buildout': {'directory': os.getcwd()}},
- 'chut', {'run': 'ls\nls .\n '})
+ 'chut', {'destination': 'dist/scripts',
+ 'run': 'ls\nls .\n '})
self.assertEqual(r.install(), ())
r = Recipe({'buildout': {'directory': os.getcwd()}},
- 'chut', {})
+ 'chut', {'destination': 'dist/scripts'})
self.assertEqual(r.update(), ())
def test_map(self):
View
18 translate-QMd5.js
@@ -0,0 +1,18 @@
+
+system = require('system')
+require('casper').create()
+ .start('http://translate.google.com/#' + system.env['TR_PAIR'], function(){
+ this.fill('form#gt-form', {text: system.env['TR_TEXT']}, false)})
+ .waitForSelector('span.hps', function() {
+ this.echo(this.fetchText('#result_box'))
+ results = this.evaluate(function() {
+ results = document.querySelectorAll('table.gt-baf-table tr')
+ return Array.prototype.map.call(results, function(e) {
+ if (!/colspan/.exec(e.innerHTML))
+ return e.innerText.replace(/\n/,': ')
+ else
+ return ''
+ })
+ })
+ this.echo(results.join(''))
+}).run()
View
18 translate-erWF.js
@@ -0,0 +1,18 @@
+
+system = require('system')
+require('casper').create()
+ .start('http://translate.google.com/#' + system.env['TR_PAIR'], function(){
+ this.fill('form#gt-form', {text: system.env['TR_TEXT']}, false)})
+ .waitForSelector('span.hps', function() {
+ this.echo(this.fetchText('#result_box'))
+ results = this.evaluate(function() {
+ results = document.querySelectorAll('table.gt-baf-table tr')
+ return Array.prototype.map.call(results, function(e) {
+ if (!/colspan/.exec(e.innerHTML))
+ return e.innerText.replace(/\n/,': ')
+ else
+ return ''
+ })
+ })
+ this.echo(results.join(''))
+}).run()
View
18 translate-kFLc.js
@@ -0,0 +1,18 @@
+
+system = require('system')
+require('casper').create()
+ .start('http://translate.google.com/#' + system.env['TR_PAIR'], function(){
+ this.fill('form#gt-form', {text: system.env['TR_TEXT']}, false)})
+ .waitForSelector('span.hps', function() {
+ this.echo(this.fetchText('#result_box'))
+ results = this.evaluate(function() {
+ results = document.querySelectorAll('table.gt-baf-table tr')
+ return Array.prototype.map.call(results, function(e) {
+ if (!/colspan/.exec(e.innerHTML))
+ return e.innerText.replace(/\n/,': ')
+ else
+ return ''
+ })
+ })
+ this.echo(results.join(''))
+}).run()

0 comments on commit 1e4d08b

Please sign in to comment.