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"""
|
r"""
|
||||||
To use, simply 'import pyutils'
|
To use, simply 'import pyutils'
|
||||||
|
|
||||||
@ -10,14 +8,18 @@ shellExecute can receive a cmd as str or arr example
|
|||||||
(b"'hello world'\n", b'')
|
(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>'
|
__author__ = 'Josue Gomez <jgomez@jesrat.com>'
|
||||||
__maintainer__ = "Josue Gomez"
|
|
||||||
__email__ = "jgomez@binkfe.com"
|
__email__ = "jgomez@binkfe.com"
|
||||||
|
__maintainer__ = "Josue Gomez"
|
||||||
__license__ = "MIT"
|
__license__ = "MIT"
|
||||||
__version__ = '2.0'
|
|
||||||
__all__ = ['', ]
|
__all__ = ['', ]
|
||||||
__status__ = "production"
|
__status__ = "production"
|
||||||
__date__ = "30 January 2019"
|
__date__ = "30 January 2019"
|
||||||
|
__copyright__ = 'Copyright 2019 Josue Gomez'
|
||||||
|
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
@ -43,3 +45,25 @@ def progress_bar(progress, total, status=''):
|
|||||||
bar = '■' * fill_len + '-' * (bar_len - fill_len)
|
bar = '■' * fill_len + '-' * (bar_len - fill_len)
|
||||||
sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percent, '%', status))
|
sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percent, '%', status))
|
||||||
sys.stdout.flush()
|
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 os
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
|
|
||||||
|
|
||||||
class NoEnvironmentFile(Exception):
|
class NoEnvironmentFile(Exception):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
class KeyNotFound(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
DEFAULT = object()
|
||||||
|
|
||||||
|
|
||||||
class LocalEnv:
|
class LocalEnv:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.file = None
|
self.files = []
|
||||||
self.data = {}
|
self.data = {}
|
||||||
|
|
||||||
def load(self, file=None):
|
def load(self, file=None):
|
||||||
@ -17,14 +25,15 @@ class LocalEnv:
|
|||||||
in invoker module's directory
|
in invoker module's directory
|
||||||
"""
|
"""
|
||||||
if file is not None:
|
if file is not None:
|
||||||
self.file = file
|
self.files.append({'file': file, 'exists': '', 'loaded': False})
|
||||||
else:
|
else:
|
||||||
self.file = self._invoker()
|
self.files.append({'file': self._invoker(), 'exists': '', 'loaded': False})
|
||||||
|
|
||||||
if not os.path.isfile(self.file):
|
# search all files given and load them
|
||||||
raise NoEnvironmentFile(f'for file {self.file}')
|
for file_dict in self.files:
|
||||||
|
file_dict['exists'] = os.path.isfile(file_dict['file'])
|
||||||
with open(self.file) as f:
|
if file_dict['exists'] and not file_dict['loaded']:
|
||||||
|
with open(file_dict['file']) as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if not line or line.startswith('#') or '=' not in line:
|
if not line or line.startswith('#') or '=' not in line:
|
||||||
@ -34,12 +43,17 @@ class LocalEnv:
|
|||||||
key = key.strip()
|
key = key.strip()
|
||||||
value = value.strip().strip('\'"')
|
value = value.strip().strip('\'"')
|
||||||
self.data[key] = value
|
self.data[key] = value
|
||||||
|
file_dict['loaded'] = True
|
||||||
|
|
||||||
def get(self, key, cast=None):
|
def get(self, key, default=DEFAULT, cast=None):
|
||||||
if cast is None:
|
try:
|
||||||
return self.data[key]
|
ret_val = self.data[key] if cast is None else cast(self.data[key])
|
||||||
|
except KeyError:
|
||||||
return cast(self.data[key])
|
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
|
@staticmethod
|
||||||
def _invoker():
|
def _invoker():
|
||||||
@ -53,3 +67,4 @@ class LocalEnv:
|
|||||||
|
|
||||||
|
|
||||||
localenv = LocalEnv()
|
localenv = LocalEnv()
|
||||||
|
localenv.load()
|
||||||
|
|||||||
@ -33,13 +33,19 @@ class SendMail:
|
|||||||
self.conn.starttls()
|
self.conn.starttls()
|
||||||
self.conn.login(self.user, self.pssw)
|
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):
|
if not isinstance(to_address, list):
|
||||||
raise AssertionError('destination address should be a 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 = MIMEMultipart()
|
||||||
self.msg['Subject'] = subject
|
self.msg['Subject'] = subject
|
||||||
self.msg['From'] = from_address
|
self.msg['From'] = from_address
|
||||||
self.msg['To'] = COMMASPACE.join(to_address)
|
self.msg['To'] = COMMASPACE.join(to_address)
|
||||||
|
if cc:
|
||||||
|
self.msg['Cc'] = COMMASPACE.join(cc)
|
||||||
self.msg.attach(MIMEText(msg, 'html'))
|
self.msg.attach(MIMEText(msg, 'html'))
|
||||||
|
|
||||||
def attach(self, files):
|
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:
|
with open("README.md", "r") as fh:
|
||||||
long_description = fh.read()
|
long_description = fh.read()
|
||||||
|
|
||||||
setuptools.setup(
|
setup(
|
||||||
name="pyutl",
|
name=pkg.__title__,
|
||||||
version="2.1",
|
version=pkg.__version__,
|
||||||
author="Josue Gomez",
|
author=pkg.__author__,
|
||||||
author_email="jgomez@binkfe.com",
|
author_email=pkg.__email__,
|
||||||
description="A package of utilities for python",
|
description=pkg.__description__,
|
||||||
long_description=long_description,
|
long_description=long_description,
|
||||||
long_description_content_type="text/markdown",
|
long_description_content_type="text/markdown",
|
||||||
url="https://git.binkfe.com/jesrat/pyutils",
|
url=pkg.__url__,
|
||||||
packages=['pyutl'],
|
packages=find_packages(),
|
||||||
classifiers=[
|
classifiers=[
|
||||||
"Programming Language :: Python :: 3",
|
"Programming Language :: Python :: 3",
|
||||||
"License :: OSI Approved :: MIT License",
|
"License :: OSI Approved :: MIT License",
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user