Skip to content

Commit a671495

Browse files
Hsin Yuan YehHsin Yuan Yeh
Hsin Yuan Yeh
authored and
Hsin Yuan Yeh
committed
updating release repo
1 parent 8849741 commit a671495

7 files changed

+39
-21
lines changed

LICENSE.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2022 Hsin Yuan Yeh
3+
Copyright (c) 2023 Hsin Yuan Yeh
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ SSHScript is a powerful tool for system automation, and it is easy to use, even
8282
Releases
8383
========
8484
85-
The new experimental release is 2.0.2 (2023/10/6). There are lots of changes, but documentation is not available yet.
85+
The new experimental release is 2.0.2 (2023/10/6). There are lots of changes, but documentation is on working.
8686
8787
The last stable version is 1.1.17. (2022/9/22). Relase Notes_
8888

setup.cfg

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[metadata]
2-
description=write automation scripts for ssh and subprocess in python
2+
description=Write Python scripts to automate SSH and subprocess operations.
33
description_file = README.rst
44
version = attr: sshscript.__version__
55
[options]
6-
python_requires = >=3.7.0
6+
python_requires = >=3.8
77
package_dir = =src

src/sshscript/sshscriptchannel.py

+25-9
Original file line numberDiff line numberDiff line change
@@ -189,11 +189,16 @@ def exitcode(self):
189189
@property
190190
def stdout(self):
191191
return self.channel._exitcodePatternForClean.sub(r'\1',self.channel.stdout)
192-
#return self.channel.stdout
193192
@property
194193
def stderr(self):
195194
return self.channel._exitcodePatternForClean.sub(r'\1',self.channel.stderr)
196-
#return self.channel.stderr
195+
@property
196+
def rawstdout(self):
197+
return self.channel.rawstdoutForOwner()
198+
@property
199+
def rawstderr(self):
200+
return self.channel.rawstderrForOwner()
201+
197202
def trim(self,text):
198203
return self.channel.trim(text)
199204

@@ -248,6 +253,8 @@ def __init__(self,owner):
248253
## assign owner's stdout and stderr
249254
self.owner._stdout = self.stdoutForOwner
250255
self.owner._stderr = self.stderrForOwner
256+
self.owner._rawstdout = self.rawstdoutForOwner
257+
self.owner._rawstderr = self.rawstderrForOwner
251258
self.shellToRun = self.owner.shellToRun
252259
self.stdoutDumpBuf = []
253260
self.stderrDumpBuf = []
@@ -517,6 +524,13 @@ def stdoutForOwner(self):
517524
def stderrForOwner(self):
518525
## because we no more setup prompt, to strip out prompt is not necessary
519526
return (self._exitcodePatternForClean.sub(r'\1',self.trim((b''.join(self.allStderrBuf)).decode('utf8','replace'))))
527+
def rawstdoutForOwner(self):
528+
## because we no more setup prompt, to strip out prompt is not necessary
529+
return (b''.join(self.allStdoutBuf))
530+
def rawstderrForOwner(self):
531+
## because we no more setup prompt, to strip out prompt is not necessary
532+
return (b''.join(self.allStderrBuf))
533+
520534
def trimedStdoutForOwner(self):
521535
## because we no more setup prompt, to strip out prompt is not necessary
522536
return self.trim((b''.join(self.allStdoutBuf)).decode('utf8','replace'))
@@ -752,7 +766,6 @@ def sendline(self,line,outputTimeout=None,outputType=None,waitPrompt=None):
752766
if idx > 0 : self.wait(self.waitingInterval,30)
753767
'''
754768
self.send(line+newline)
755-
756769
if idx < len(lines) - 1:
757770
## not the last one
758771
self.waitCommandToComplete(outputTimeout,waitPrompt)
@@ -855,8 +868,9 @@ def addStderrData(self,newbytes):
855868
if lines is not None:
856869
if self.stderrListener:
857870
self.stderrListener(2,[x+bNewline for x in lines])
858-
sys.stderr.buffer.write(bNewline.join([self.stderrPrefix + x for x in lines])+bNewline)
859-
sys.stderr.buffer.flush()
871+
if self.dump2sys:
872+
sys.stderr.buffer.write(bNewline.join([self.stderrPrefix + x for x in lines])+bNewline)
873+
sys.stderr.buffer.flush()
860874
def close(self):
861875
## dump the last content in stdoutDumpBuf and stderrDumpBuf
862876
## No need to call self.updateStdoutStderr()
@@ -927,10 +941,10 @@ def _win32ReadingStdout():
927941
def _reading():
928942
buffer = {
929943
self.masterFd[0]: self.addStdoutData, #stdout
930-
#self.masterFd[1]: self.addStderrData #stderr
944+
self.masterFd[1]: self.addStderrData #stderr
931945
}
932-
if len(self.masterFd) == 2:
933-
buffer[self.masterFd[1]]= self.addStderrData
946+
#if len(self.masterFd) == 2:
947+
# buffer[self.masterFd[1]]= self.addStderrData
934948
#while (not self.closed) and buffer:
935949
while (self.cp.poll() is None):
936950
try:
@@ -976,8 +990,10 @@ def commandTimeout(self):
976990
return self.owner.commandTimeout
977991

978992
def send(self,s):
979-
self.log(DEBUG,f'{threading.current_thread().native_id} send:{[s]}')
993+
## disable, sensitive data might be shown
994+
#self.log(DEBUG,f'{threading.current_thread().native_id} send:{[s]}')
980995
os.write(self.stdin,s.encode('utf-8'))
996+
## this would crashed in linux for pty
981997
#os.fsync(self.stdin)
982998

983999
def close(self):

src/sshscript/sshscriptchannelutils.py

+1-6
Original file line numberDiff line numberDiff line change
@@ -42,30 +42,25 @@ def expect(self,outputTimeout):
4242
timeout = 3
4343
if self.pattern is None:
4444
## failover to channel's default wait() method
45-
logger.debug(f'****** ****** ******1 prompt {self} failover to wait()')
4645
self.channel.wait(outputTimeout)
4746
elif self._type == 1:
4847
try:
4948
m = self.channel.expect(self.pattern,timeout=timeout,stdout=True,stderr=False,position=self.position)
5049
except TimeoutError:
51-
logger.debug(f'****** ****** ****** prompt {self} not matched')
5250
logger.debug(f'stdout={self.channel.stdout}')
5351
raise
5452
else:
5553
self.position += m.end() + 1
56-
logger.debug(f'****** ****** ******2 prompt {self} matched')
5754
## ensure all data has been received
5855
self.channel.wait(0.1)
5956
elif self._type == 2:
6057
try:
6158
m = self.channel.expect(self.pattern,timeout=timeout,stdout=False,stderr=True,position=self.position)
6259
except TimeoutError:
63-
logger.debug(f'****** ****** ****** prompt {self} not matched')
6460
logger.debug(f'stderr={self.channel.stderr}')
6561
raise
6662
else:
6763
self.position += m.end() + 1
68-
logger.debug(f'****** ****** ******3 prompt {self} matched')
6964
## ensure all data has been received
7065
self.channel.wait(0.1)
7166
else:
@@ -77,7 +72,7 @@ def __call__(self,keyword,stdout=False,stderr=False):
7772
self.keyword = keyword
7873
if stdout: self.type = 1
7974
elif stderr: self.type = 2
80-
logger.debug(f'** __call__ set prompt to "{self}" ({stdout},{stderr})')
75+
logger.debug(f'__call__ set prompt to "{self}" ({stdout},{stderr})')
8176
@property
8277
def keyword(self):
8378
return self._keyword

src/sshscript/sshscriptdollar.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ def __init__(self,sshscript,cmd=None,globals=None,locals=None,inWith=False,fr=0)
8888
self.cp = None # got value if run by subprocess and inWith
8989
self._stdout = lambda: ""
9090
self._stderr = lambda: ""
91+
self._rawstdout = lambda: ""
92+
self._rawstderr = lambda: ""
9193
self.stdin = None
9294
self.exitcode = None
9395
self.inWith = inWith
@@ -108,6 +110,13 @@ def stdout(self):
108110
def stderr(self):
109111
return self._stderr()
110112

113+
@property
114+
def rawstdout(self):
115+
return self._rawstdout()
116+
@property
117+
def rawstderr(self):
118+
return self._rawstderr()
119+
111120
@property
112121
def waitingInterval(self):
113122
## v2.0 CMD_INTERVAL and SSH_CMD_INTERVAL renamed to OUTPUT_TIMEOUT and SSH_OUTPUT_TIMEOUT
@@ -436,7 +445,6 @@ def execBySSH(self,isTwodollars):
436445
self.channel.updateStdoutStderr('not self.inWith')
437446
## this would assign value of self.exitcode
438447
self.channel.close()
439-
print('^' * 100,self.exitcode)
440448
error = self.checkExitcode(self.exitcode,self.channel.stderr)
441449
if error: raise error
442450
else:

src/sshscript/sshscriptsession.py

-1
Original file line numberDiff line numberDiff line change
@@ -764,7 +764,6 @@ def _run(script,varLocals,varGlobals,showScript=False):
764764
digits = len(str(len(lines)+1))
765765
for line in lines:
766766
self.lineNumberCount += 1
767-
#print(f'{str(self.lineNumberCount).zfill(digits)}:{line}')
768767
print(f'{line}')
769768
print()
770769
return {}

0 commit comments

Comments
 (0)