diff --git a/dist/pyutl-2.1.tar.gz b/dist/pyutl-2.1.tar.gz new file mode 100644 index 0000000..a851ab0 Binary files /dev/null and b/dist/pyutl-2.1.tar.gz differ diff --git a/dist/pyutl-2.5.tar.gz b/dist/pyutl-2.5.tar.gz new file mode 100644 index 0000000..37a60d7 Binary files /dev/null and b/dist/pyutl-2.5.tar.gz differ diff --git a/pyutl.egg-info/PKG-INFO b/pyutl.egg-info/PKG-INFO new file mode 100644 index 0000000..777c804 --- /dev/null +++ b/pyutl.egg-info/PKG-INFO @@ -0,0 +1,15 @@ +Metadata-Version: 2.1 +Name: pyutl +Version: 2.5 +Summary: functions and utilities to recycle code +Home-page: https://git.binkfe.com/jesrat/pyutl +Author: Josue Gomez +Author-email: jgomez@binkfe.com +License: UNKNOWN +Description: pyutils + +Platform: UNKNOWN +Classifier: Programming Language :: Python :: 3 +Classifier: License :: OSI Approved :: MIT License +Classifier: Operating System :: OS Independent +Description-Content-Type: text/markdown diff --git a/pyutl.egg-info/SOURCES.txt b/pyutl.egg-info/SOURCES.txt new file mode 100644 index 0000000..57fab54 --- /dev/null +++ b/pyutl.egg-info/SOURCES.txt @@ -0,0 +1,12 @@ +README.md +setup.cfg +setup.py +pyutl/__init__.py +pyutl/localenv.py +pyutl/oracle.py +pyutl/remote.py +pyutl/sendmail.py +pyutl.egg-info/PKG-INFO +pyutl.egg-info/SOURCES.txt +pyutl.egg-info/dependency_links.txt +pyutl.egg-info/top_level.txt \ No newline at end of file diff --git a/pyutl.egg-info/dependency_links.txt b/pyutl.egg-info/dependency_links.txt new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/pyutl.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/pyutl.egg-info/top_level.txt b/pyutl.egg-info/top_level.txt new file mode 100644 index 0000000..8fc81e7 --- /dev/null +++ b/pyutl.egg-info/top_level.txt @@ -0,0 +1 @@ +pyutl diff --git a/pyutl/__init__.py b/pyutl/__init__.py index a81cf2b..ee0d56c 100644 --- a/pyutl/__init__.py +++ b/pyutl/__init__.py @@ -1,5 +1,3 @@ -# functions to recycle code - r""" To use, simply 'import pyutils' @@ -10,14 +8,18 @@ shellExecute can receive a cmd as str or arr example (b"'hello world'\n", b'') """ +__title__ = 'pyutl' +__description__ = 'functions and utilities to recycle code' +__url__ = 'https://git.binkfe.com/jesrat/pyutl' +__version__ = '2.5' __author__ = 'Josue Gomez ' -__maintainer__ = "Josue Gomez" __email__ = "jgomez@binkfe.com" +__maintainer__ = "Josue Gomez" __license__ = "MIT" -__version__ = '2.0' __all__ = ['', ] __status__ = "production" __date__ = "30 January 2019" +__copyright__ = 'Copyright 2019 Josue Gomez' import sys @@ -43,3 +45,25 @@ def progress_bar(progress, total, status=''): bar = '■' * fill_len + '-' * (bar_len - fill_len) sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percent, '%', status)) sys.stdout.flush() + + +def read_streamed_file(file, chunk_size=10): + """ + Reads a hugh file by chunks (10 lines default) + :param file + :param chunk_size (10 lines default) + :return: chunk by chunk + """ + counter = 0 + ret_lines = [] + with open(file) as f: + while True: + counter += 1 + line = f.readline() + if line: + ret_lines.append((counter, line)) + if (counter/chunk_size).is_integer() or not line: + yield ret_lines + ret_lines = [] + if not line: + break diff --git a/pyutl/localenv.py b/pyutl/localenv.py index b5be2c9..6f8e517 100644 --- a/pyutl/localenv.py +++ b/pyutl/localenv.py @@ -1,14 +1,22 @@ import os import sys +import json class NoEnvironmentFile(Exception): pass +class KeyNotFound(Exception): + pass + + +DEFAULT = object() + + class LocalEnv: def __init__(self): - self.file = None + self.files = [] self.data = {} def load(self, file=None): @@ -17,29 +25,35 @@ class LocalEnv: in invoker module's directory """ if file is not None: - self.file = file + self.files.append({'file': file, 'exists': '', 'loaded': False}) else: - self.file = self._invoker() + self.files.append({'file': self._invoker(), 'exists': '', 'loaded': False}) - if not os.path.isfile(self.file): - raise NoEnvironmentFile(f'for file {self.file}') + # search all files given and load them + for file_dict in self.files: + file_dict['exists'] = os.path.isfile(file_dict['file']) + if file_dict['exists'] and not file_dict['loaded']: + with open(file_dict['file']) as f: + for line in f: + line = line.strip() + if not line or line.startswith('#') or '=' not in line: + continue + key, value = line.split('=', 1) + key = key.replace('export', '') + key = key.strip() + value = value.strip().strip('\'"') + self.data[key] = value + file_dict['loaded'] = True - with open(self.file) as f: - for line in f: - line = line.strip() - if not line or line.startswith('#') or '=' not in line: - continue - key, value = line.split('=', 1) - key = key.replace('export', '') - key = key.strip() - value = value.strip().strip('\'"') - self.data[key] = value - - def get(self, key, cast=None): - if cast is None: - return self.data[key] - - return cast(self.data[key]) + def get(self, key, default=DEFAULT, cast=None): + try: + ret_val = self.data[key] if cast is None else cast(self.data[key]) + except KeyError: + if default != DEFAULT: + ret_val = default if cast is None else cast(default) + else: + raise KeyNotFound(f'value not found in files: \n{json.dumps(self.files, indent=4)}') + return ret_val @staticmethod def _invoker(): @@ -53,3 +67,4 @@ class LocalEnv: localenv = LocalEnv() +localenv.load() diff --git a/pyutl/sendmail.py b/pyutl/sendmail.py index bbd2086..f3154ea 100644 --- a/pyutl/sendmail.py +++ b/pyutl/sendmail.py @@ -33,13 +33,19 @@ class SendMail: self.conn.starttls() self.conn.login(self.user, self.pssw) - def content(self, from_address, to_address, subject, msg): + def content(self, from_address, to_address, subject, msg, cc=None): if not isinstance(to_address, list): raise AssertionError('destination address should be a list []') + if cc: + if not isinstance(cc, list): + raise AssertionError('cc address should be a list []') + self.msg = MIMEMultipart() self.msg['Subject'] = subject self.msg['From'] = from_address self.msg['To'] = COMMASPACE.join(to_address) + if cc: + self.msg['Cc'] = COMMASPACE.join(cc) self.msg.attach(MIMEText(msg, 'html')) def attach(self, files): diff --git a/setup.py b/setup.py index d299112..7205000 100644 --- a/setup.py +++ b/setup.py @@ -1,18 +1,19 @@ -import setuptools +import pyutl as pkg +from setuptools import setup, find_packages with open("README.md", "r") as fh: long_description = fh.read() -setuptools.setup( - name="pyutl", - version="2.1", - author="Josue Gomez", - author_email="jgomez@binkfe.com", - description="A package of utilities for python", +setup( + name=pkg.__title__, + version=pkg.__version__, + author=pkg.__author__, + author_email=pkg.__email__, + description=pkg.__description__, long_description=long_description, long_description_content_type="text/markdown", - url="https://git.binkfe.com/jesrat/pyutils", - packages=['pyutl'], + url=pkg.__url__, + packages=find_packages(), classifiers=[ "Programming Language :: Python :: 3", "License :: OSI Approved :: MIT License",