From e0bd1e22ac29cfbadd75feb7c19f2cc3d2164b2c Mon Sep 17 00:00:00 2001 From: Julio Biason Date: Fri, 29 Mar 2019 10:08:16 -0300 Subject: [PATCH] New random stuff --- dojo.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ telinet.py | 19 +++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 dojo.py create mode 100644 telinet.py diff --git a/dojo.py b/dojo.py new file mode 100644 index 0000000..97ab298 --- /dev/null +++ b/dojo.py @@ -0,0 +1,49 @@ +def test(): + _input = [100, 101, 102, 103, 104, 105, 110, 111, 112, 113, 114, 115, 150] + assert [[100, 105], [110, 115], [150]] == interval(_input) + +def test_1(): + _input = [100, 101, 102, 103, 104, 105, 110, 111, 112, 113, 114, 115] + assert [[100, 105], [110, 115]] == interval(_input) + +def test_2(): + _input = [100, 110, 111, 112, 113, 114, 115, 150] + assert [[100], [110, 115], [150]] == interval(_input) + +def test_3(): + _input = [100, 101, 102, 103, 104, 105, 107, 110, 111, 112, 113, 114, 115, 150] + assert [[100, 105], [107], [110, 115], [150]] == interval(_input) + +def test_4(): + assert [[100]] == interval([100]) + +def test_5(): + assert [[1], [3], [5]] == interval([1, 3, 5]) + +def test_6(): + assert [[1, 2]] == interval([1, 2]) + +def failure(): + assert [[1]] == interval([1, 2]) + +def interval(data): + diffs = [(data[x] - data[x-1]) != 1 + for x + in range(len(data))] + result = [] + for value, _new in zip(data, diffs): + if _new: + result.append([value]) + else: + result[-1] = [result[-1][0], value] + return result + +if __name__ == "__main__": + test() + test_1() + test_2() + test_3() + test_4() + test_5() + test_6() + failure() diff --git a/telinet.py b/telinet.py new file mode 100644 index 0000000..38041fd --- /dev/null +++ b/telinet.py @@ -0,0 +1,19 @@ +import os, glob, telnetlib, time + +CAMINHO = "/home/admin/deploy" +HOST = "127.0.0.1" # conecta no osgi do idempiere via localhost +PORT = 12612 # porta do osgi +TIMEOUT = 2 + + +tn = telnetlib.Telnet(HOST, PORT, TIMEOUT) + +# print("Open") +# tn.open(HOST, PORT) +print("ls") +tn.write("ls") +print("exit") +tn.write("exit") + +tn.close() +print('Concluido')