Esempio n. 1
0
 def __init__(self):
     super(WriteBuiltin,
           self).__init__('write',
                          input=InputStreamSchema('any', optional=False),
                          argspec=MultiArgSpec('paths', min=1),
                          options=[['-a', '--append'], ['-p', '--pickle'],
                                   ['-n', '--newline']])
Esempio n. 2
0
 def __init__(self):
     super(JsonBuiltin, self).__init__(
         'json',
         output=str,  # 'any'
         input=InputStreamSchema('any'),
         idempotent=True,
         argspec=None)
Esempio n. 3
0
 def __init__(self):
     super(IterBuiltin, self).__init__('iter',
                                       input=InputStreamSchema('any'),
                                       output='any',
                                       argspec=None,
                                       idempotent=True,
                                       threaded=False)
Esempio n. 4
0
 def __init__(self):
     super(UniqBuiltin, self).__init__('uniq',
                                       input=InputStreamSchema('any'),
                                       output='any',
                                       options=[['-c', '--count']],
                                       argspec=(ArgSpec('property',
                                                        opt=True), ))
Esempio n. 5
0
 def __init__(self):
     super(SortBuiltin, self).__init__('sort',
                                       input=InputStreamSchema('any'),
                                       output='identity',
                                       options=[['-r', '--reverse']],
                                       argspec=MultiArgSpec('property',
                                                            min=0))
Esempio n. 6
0
 def __init__(self):
     super(PropBuiltin, self).__init__('prop',
                                       input=InputStreamSchema('any'),
                                       output='any',
                                       idempotent=True,
                                       argspec=(ArgSpec('name'), ),
                                       options=[['-t', '--tuple']],
                                       threaded=True)
Esempio n. 7
0
 def __init__(self):
     super(FilterBuiltin,
           self).__init__('filter',
                          input=InputStreamSchema('any'),
                          output='identity',
                          options=[['-s', '--stringify'],
                                   ['-i', '--ignore-case'],
                                   ['-v', '--invert-match']],
                          argspec=('regexp', ArgSpec('property', opt=True)))
Esempio n. 8
0
 def __init__(self):
     super(RmBuiltin, self).__init__('rm',
                                     aliases=['delete'],
                                     input=InputStreamSchema(File,
                                                             optional=True),
                                     undoable=True,
                                     hasstatus=True,
                                     argspec=MultiArgSpec('path'),
                                     options=[['-u', '--unlink'],
                                              ['-r', '--recursive'],
                                              ['-f', '--force']])
Esempio n. 9
0
 def __init__(self, name='sys'):
     super(SysBuiltin, self).__init__(
         name,
         input=InputStreamSchema(
             str,
             optional=True,
             opt_formats=['x-unix-pipe-file-object/special']),
         output=OutputStreamSchema(str,
                                   opt_formats=[
                                       'x-unix-pipe-file-object/special',
                                       'x-filedescriptor/special',
                                       'bytearray/chunked'
                                   ]),
         hasstatus=True,
         argspec=MultiArgSpec('args'),
         options_passthrough=True)
Esempio n. 10
0
 def __init__(self):
     super(KillBuiltin, self).__init__('kill',
                                       nodisplay=True,
                                       input=InputStreamSchema(Process, optional=True),
                                       options_passthrough=True,
                                       argspec=MultiArgSpec('pid', min=1))
Esempio n. 11
0
 def __init__(self):
     super(StringifyBuiltin, self).__init__('stringify',
                                            input=InputStreamSchema('any'),
                                            output=str,
                                            argspec=None)
Esempio n. 12
0
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
# THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import os, sys, pickle

from hotwire.fs import path_join, open_text_file
from hotwire.builtin import builtin_hotwire, InputStreamSchema


@builtin_hotwire(input=InputStreamSchema('any', optional=True),
                 options_passthrough=True,
                 idempotent=True)
def head(context, *files):
    _("""Return a subset of items from start of input stream.""")
    count = 10
    countidx = -1
    # Create a copy so we can delete from it safely
    files = list(files)
    for i, arg in enumerate(files):
        if arg.startswith('-'):
            count = int(arg[1:])
            countidx = i
            break
    if countidx >= 0:
        del files[countidx]
Esempio n. 13
0
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do so,
# subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
# THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import os
from cStringIO import StringIO

from hotwire.builtin import builtin_hotwire, InputStreamSchema


@builtin_hotwire(input=InputStreamSchema('any'))
def pprint(context):
    _("""Pretty-print input object(s).""")
    iostr = StringIO()
    import pprint  # Import here to avoid name clash...
    printer = pprint.PrettyPrinter(indent=4, stream=iostr)
    printer.pprint(list(context.input))
    return iostr.getvalue()
Esempio n. 14
0
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
# THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import os, sys, os.path, stat, logging, locale

from hotwire.builtin import builtin_hotwire, InputStreamSchema, MultiArgSpec
from hotwire.fs import FilePath
from hotwire.sysdep.fs import Filesystem, File
from hotwire.util import xmap

_logger = logging.getLogger("hotwire.builtins.ls")


@builtin_hotwire(aliases=['dir'],
                 input=InputStreamSchema(str, optional=True),
                 output=File,
                 idempotent=True,
                 argspec=MultiArgSpec('paths'),
                 options=[['-l', '--long'], ['-a', '--all'], ['-i',
                                                              '--input']])
def ls(context, *args):
    _("""List contents of a directory.""")
    show_all = '-a' in context.options
    long_fmt = '-l' in context.options
    process_input = '-i' in context.options
    fs = Filesystem.getInstance()

    if process_input and input is not None:
        args = list(args)
        args.extend(context.input)
Esempio n. 15
0
 def __init__(self):
     super(PyFilterBuiltin,
           self).__init__('py-filter',
                          argspec=(ArgSpec('expression'), ),
                          input=InputStreamSchema('any'),
                          output='identity')
Esempio n. 16
0
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE 
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 
# THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import os,sys,re,subprocess,sha,tempfile
import symbol,parser,code,threading

from hotwire.builtin import builtin_hotwire, InputStreamSchema, OutputStreamSchema

from hotwire.fs import path_join
from hotwire.sysdep.fs import Filesystem
from hotwire.externals.rewrite import rewrite_and_compile

@builtin_hotwire(singlevalue=True,
                 input=InputStreamSchema('any', optional=True),
                 output=OutputStreamSchema('any'),
                 options=[['-f', '--file']])
def py_eval(context, *args):
    _("""Compile and execute Python expression.
Iterable return values (define __iter__) are expanded.  Other values are
expressed as an iterable which yielded a single object.""")
    if len(args) < 1:
        raise ValueError(_("Too few arguments specified"))
    locals = {'hot_context': context}
    if context.current_output_metadata and context.current_output_metadata.type is not None:
        if context.current_output_metadata.single:
            try:
                locals['it'] = context.snapshot_current_output()
            except ValueError as e:
                locals['it'] = None
Esempio n. 17
0
 def __init__(self):
     super(PyMapBuiltin,
           self).__init__('py-map',
                          argspec=(ArgSpec('expression'), ),
                          input=InputStreamSchema('any', optional=True),
                          output=OutputStreamSchema('any'))
Esempio n. 18
0
 def __init__(self):
     super(ReplaceBuiltin, self).__init__('replace',
                                          input=InputStreamSchema('any'),
                                          output='identity',
                                          argspec=(ArgSpec('regexp'),
                                                   ArgSpec('replacement')))
Esempio n. 19
0
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE 
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR 
# THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import os,sys,locale

from hotwire.builtin import builtin_hotwire, InputStreamSchema, MultiArgSpec
from hotwire.command import Pipeline,HotwireContext

@builtin_hotwire(options_passthrough=True,
                 input=InputStreamSchema('any'))
def apply(context, *args):
    _("""Like Unix xargs - take input and convert to arguments.""")

    newargs = list(args)
    for argument in context.input:
        if not isinstance(argument, str):
            argument = str(argument)
        newargs.append(argument)
        
    new_context = HotwireContext(initcwd=context.cwd)
    # TODO - pull in resolver from shell.py?  Should this function expand
    # aliases?        
    pipeline = Pipeline.create(new_context, None, *newargs)
    pipeline.execute_sync(assert_all_threaded=True)
    for result in pipeline.get_output():
Esempio n. 20
0
 def __init__(self):
     super(NewlineBuiltin, self).__init__('newline',
                                          input=InputStreamSchema('any'),
                                          output=str,
                                          argspec=None)
Esempio n. 21
0
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
# INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
# PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE X CONSORTIUM BE
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
# THE USE OR OTHER DEALINGS IN THE SOFTWARE.

import os, sys, locale

from hotwire.builtin import builtin_hotwire, InputStreamSchema, MultiArgSpec
from hotwire.command import Pipeline, HotwireContext


@builtin_hotwire(options_passthrough=True, input=InputStreamSchema('any'))
def apply(context, *args):
    _("""Like Unix xargs - take input and convert to arguments.""")

    newargs = list(args)
    for argument in context.input:
        if not isinstance(argument, basestring):
            argument = unicode(argument)
        newargs.append(argument)

    new_context = HotwireContext(initcwd=context.cwd)
    # TODO - pull in resolver from shell.py?  Should this function expand
    # aliases?
    pipeline = Pipeline.create(new_context, None, *newargs)
    pipeline.execute_sync(assert_all_threaded=True)
    for result in pipeline.get_output():