Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
78 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Command: | ||
""" | ||
Object for calling an IBM i CL command. | ||
""" | ||
def __init__(self, command, screen_output=False): | ||
self.command = command | ||
self.screen_output = screen_output | ||
self.payload = { | ||
"cmd": {} | ||
} | ||
|
||
def get_payload(self): | ||
if self.screen_output: | ||
self.payload["cmd"]["qsh"] = self.command | ||
elif any(x in self.command for x in ["&", "?"]): | ||
self.payload["cmd"]["rexx"] = self.command | ||
else: | ||
self.payload["cmd"]["exec"] = self.command | ||
|
||
return self.payload |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
__version__ = "0.1.0" | ||
from .Command import Command |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import unittest | ||
import os | ||
from pykit.transport.http import connect | ||
from pykit import Command | ||
|
||
|
||
class TestCommand(unittest.TestCase): | ||
def setUp(self): | ||
self.connection = connect( | ||
os.environ['PK_DB2SOCK_URL'], | ||
db2sock_auth=( | ||
os.environ['PK_DB2SOCK_USER'], os.environ['PK_DB2SOCK_PASS'])) | ||
|
||
def test_execute_qsh_command(self): | ||
cmd = Command("ls -1 /QOpenSys", True) | ||
toolkit = self.connection.toolkit() | ||
toolkit.add(cmd) | ||
response = toolkit.execute() | ||
self.assertTrue(response) | ||
|
||
def test_execute_rexx_command(self): | ||
cmd = Command("RTVJOBA CCSID(?N) USRLIBL(?) SYSLIBL(?)") | ||
toolkit = self.connection.toolkit() | ||
toolkit.add(cmd) | ||
response = toolkit.execute() | ||
self.assertTrue(response) | ||
|
||
def test_execute_exec_command(self): | ||
cmd = Command("CHGLIBL LIBL(DB2JSON QTEMP) CURLIB(DB2JSON)") | ||
toolkit = self.connection.toolkit() | ||
toolkit.add(cmd) | ||
response = toolkit.execute() | ||
self.assertTrue(response) | ||
|
||
|
||
self.assertTrue(response) | ||
if __name__ == '__main__': | ||
unittest.main() |