allow to read stdin from different handle than sys.stdin in emulator
Signed-off-by: Nico Schottelius <nico@brief.schottelius.org>
This commit is contained in:
		
					parent
					
						
							
								e785092935
							
						
					
				
			
			
				commit
				
					
						7b51e22922
					
				
			
		
					 1 changed files with 4 additions and 3 deletions
				
			
		| 
						 | 
					@ -29,8 +29,9 @@ import cdist
 | 
				
			||||||
from cdist import core
 | 
					from cdist import core
 | 
				
			||||||
 | 
					
 | 
				
			||||||
class Emulator(object):
 | 
					class Emulator(object):
 | 
				
			||||||
    def __init__(self, argv):
 | 
					    def __init__(self, argv, stdin=sys.stdin):
 | 
				
			||||||
        self.argv           = argv
 | 
					        self.argv           = argv
 | 
				
			||||||
 | 
					        self.stdin          = stdin
 | 
				
			||||||
        self.object_id      = False
 | 
					        self.object_id      = False
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.global_path    = os.environ['__global']
 | 
					        self.global_path    = os.environ['__global']
 | 
				
			||||||
| 
						 | 
					@ -148,13 +149,13 @@ class Emulator(object):
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    chunk_size = 8192
 | 
					    chunk_size = 8192
 | 
				
			||||||
    def _read_stdin(self):
 | 
					    def _read_stdin(self):
 | 
				
			||||||
        return sys.stdin.buffer.read(self.chunk_size)
 | 
					        return self.stdin.buffer.read(self.chunk_size)
 | 
				
			||||||
    def save_stdin(self):
 | 
					    def save_stdin(self):
 | 
				
			||||||
        """If something is written to stdin, save it in the object as
 | 
					        """If something is written to stdin, save it in the object as
 | 
				
			||||||
        $__object/stdin so it can be accessed in manifest and gencode-*
 | 
					        $__object/stdin so it can be accessed in manifest and gencode-*
 | 
				
			||||||
        scripts.
 | 
					        scripts.
 | 
				
			||||||
        """
 | 
					        """
 | 
				
			||||||
        if not sys.stdin.isatty():
 | 
					        if not self.stdin.isatty():
 | 
				
			||||||
            try:
 | 
					            try:
 | 
				
			||||||
                # go directly to file instead of using CdistObject's api
 | 
					                # go directly to file instead of using CdistObject's api
 | 
				
			||||||
                # as that does not support streaming
 | 
					                # as that does not support streaming
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue