From 01e4a9ef7bc77f4d2496345985e203421bb47f1f Mon Sep 17 00:00:00 2001 From: Josue Gomez Date: Thu, 31 Jan 2019 11:11:45 -0600 Subject: [PATCH] add files --- __init__.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ pysyspath2 | 8 ++++++++ pysyspath3 | 8 ++++++++ 3 files changed, 66 insertions(+) create mode 100644 __init__.py create mode 100755 pysyspath2 create mode 100755 pysyspath3 diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..b2e2c16 --- /dev/null +++ b/__init__.py @@ -0,0 +1,50 @@ +# functions to recycle code + +r""" +To use, simply 'import pyutils' + +shellExecute can receive a cmd as str or arr example + >>> pyutils.shellExecute('date') + (b'mi\xc3\xa9 ene 30 11:35:00 CST 2019\n', b'') + >>> pyutils.shellExecute(['echo',"'hola mundo'"]) + (b"'hola mundo'\n", b'') +""" + +__author__ = 'Josue Gomez ' +__version__ = '2.0' +__all__ = [ 'resizeTTY', 'shellExecute', 'progressBar', 'getSensible', ] +__status__ = "production" +__date__ = "30 January 2019" + +import os, sys, subprocess +from dotenv import load_dotenv + + +result = os.environ.get('MYENV') +load_dotenv(result) + +def getSensible(key): + return os.environ.get(key) + +def pysyspath(): + print(sys.version) + for pth in sys.path: + print(pth) + +def resizeTTY(rows, cols): + sys.stdout.write("\x1b[8;{rows};{cols}t".format(rows=rows, cols=cols)) + +def shellExecute(cmd,stdin=None): + rpt = subprocess.Popen(cmd, stdin=stdin, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + stdout, stderr = rpt.communicate() + return stdout, stderr + +def progressBar(progress, total, status=''): + ttySize = shellExecute(['stty','size']) + ttySize = ttySize[0].decode().split(' ') + barLen = round(int(ttySize[1])/100*90) + fillLen = int(round(barLen * progress / float(total))) + percent = round(100.0 * progress / float(total), 1) + bar = '■' * fillLen + '-' * (barLen - fillLen) + sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percent, '%', status)) + sys.stdout.flush() \ No newline at end of file diff --git a/pysyspath2 b/pysyspath2 new file mode 100755 index 0000000..3a569df --- /dev/null +++ b/pysyspath2 @@ -0,0 +1,8 @@ +#!/usr/bin/env python2 +import pyutils as utl + +def main(): + utl.pysyspath() + +if __name__ == "__main__": + main() \ No newline at end of file diff --git a/pysyspath3 b/pysyspath3 new file mode 100755 index 0000000..fc3501e --- /dev/null +++ b/pysyspath3 @@ -0,0 +1,8 @@ +#!/usr/bin/env python3 +import pyutils as utl + +def main(): + utl.pysyspath() + +if __name__ == "__main__": + main() \ No newline at end of file