Merge branch 'treenodes'
This commit is contained in:
commit
0300da9ec1
@ -1,5 +1,7 @@
|
|||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
|
from tree import TreeNode
|
||||||
|
|
||||||
|
|
||||||
class BaseCommand(object):
|
class BaseCommand(object):
|
||||||
"""Commands can be used to chain the execution of multiple programs
|
"""Commands can be used to chain the execution of multiple programs
|
||||||
|
|||||||
@ -1,5 +1,7 @@
|
|||||||
from psh.commands import BaseCommand, register_cmd
|
from psh.commands import BaseCommand, register_cmd
|
||||||
|
|
||||||
|
from tree import TreeNode
|
||||||
|
|
||||||
|
|
||||||
@register_cmd("example")
|
@register_cmd("example")
|
||||||
class Example(BaseCommand):
|
class Example(BaseCommand):
|
||||||
@ -8,8 +10,8 @@ class Example(BaseCommand):
|
|||||||
|
|
||||||
def call(self, *args, **kwargs):
|
def call(self, *args, **kwargs):
|
||||||
def output_generator():
|
def output_generator():
|
||||||
yield b'example'
|
yield TreeNode(b'example')
|
||||||
yield b'command'
|
yield TreeNode(b'command')
|
||||||
return output_generator
|
return output_generator
|
||||||
|
|
||||||
|
|
||||||
@ -26,7 +28,8 @@ class Echo(BaseCommand):
|
|||||||
input_generator = self.get_input_generator()
|
input_generator = self.get_input_generator()
|
||||||
def output_generator():
|
def output_generator():
|
||||||
for args in self.args:
|
for args in self.args:
|
||||||
yield args.encode("utf-8")
|
yield TreeNode(args.encode("utf-8"))
|
||||||
for line in input_generator:
|
for node in input_generator:
|
||||||
yield line
|
line = node.data
|
||||||
|
yield TreeNode(line)
|
||||||
return output_generator
|
return output_generator
|
||||||
|
|||||||
@ -7,6 +7,7 @@ class Printer(BaseCommand):
|
|||||||
|
|
||||||
def call(self):
|
def call(self):
|
||||||
input_generator = self.get_input_generator()
|
input_generator = self.get_input_generator()
|
||||||
for line in input_generator:
|
for node in input_generator:
|
||||||
|
line = node.data
|
||||||
print(str(line.decode('utf-8')))
|
print(str(line.decode('utf-8')))
|
||||||
return None
|
return None
|
||||||
|
|||||||
@ -3,6 +3,8 @@ import shlex
|
|||||||
from psh.formatters import Printer
|
from psh.formatters import Printer
|
||||||
from psh.commands import BaseCommand
|
from psh.commands import BaseCommand
|
||||||
|
|
||||||
|
from tree import TreeNode
|
||||||
|
|
||||||
|
|
||||||
class RawCommand(BaseCommand):
|
class RawCommand(BaseCommand):
|
||||||
"""Fallback raw command that just invokes an existing Unix utility program
|
"""Fallback raw command that just invokes an existing Unix utility program
|
||||||
@ -20,11 +22,12 @@ class RawCommand(BaseCommand):
|
|||||||
p = subprocess.Popen(shlex.split(self.cmd), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
p = subprocess.Popen(shlex.split(self.cmd), stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
def make_output_generator():
|
def make_output_generator():
|
||||||
input_str = b""
|
input_str = b""
|
||||||
for line in input_generator:
|
for node in input_generator:
|
||||||
|
line = node.data
|
||||||
input_str += line + b'\n'
|
input_str += line + b'\n'
|
||||||
outs, errs = p.communicate(input_str)
|
outs, errs = p.communicate(input_str)
|
||||||
if outs:
|
if outs:
|
||||||
yield outs
|
yield TreeNode(outs)
|
||||||
|
|
||||||
return make_output_generator
|
return make_output_generator
|
||||||
except:
|
except:
|
||||||
|
|||||||
Reference in New Issue
Block a user