v2.5 improvement localenv && added CC to sendmail
This commit is contained in:
parent
5b72255fa7
commit
8b150c14ff
BIN
dist/pyutl-2.1.tar.gz
vendored
Normal file
BIN
dist/pyutl-2.1.tar.gz
vendored
Normal file
Binary file not shown.
BIN
dist/pyutl-2.5.tar.gz
vendored
Normal file
BIN
dist/pyutl-2.5.tar.gz
vendored
Normal file
Binary file not shown.
15
pyutl.egg-info/PKG-INFO
Normal file
15
pyutl.egg-info/PKG-INFO
Normal file
@ -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 <jgomez@jesrat.com>
|
||||
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
|
||||
12
pyutl.egg-info/SOURCES.txt
Normal file
12
pyutl.egg-info/SOURCES.txt
Normal file
@ -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
|
||||
1
pyutl.egg-info/dependency_links.txt
Normal file
1
pyutl.egg-info/dependency_links.txt
Normal file
@ -0,0 +1 @@
|
||||
|
||||
1
pyutl.egg-info/top_level.txt
Normal file
1
pyutl.egg-info/top_level.txt
Normal file
@ -0,0 +1 @@
|
||||
pyutl
|
||||
@ -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 <jgomez@jesrat.com>'
|
||||
__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
|
||||
|
||||
@ -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,14 +25,15 @@ 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}')
|
||||
|
||||
with open(self.file) as f:
|
||||
# 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:
|
||||
@ -34,12 +43,17 @@ class LocalEnv:
|
||||
key = key.strip()
|
||||
value = value.strip().strip('\'"')
|
||||
self.data[key] = value
|
||||
file_dict['loaded'] = True
|
||||
|
||||
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()
|
||||
|
||||
@ -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):
|
||||
|
||||
19
setup.py
19
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",
|
||||
|
||||
Loading…
Reference in New Issue
Block a user