Browse Source

v2.5 improvement localenv && added CC to sendmail

master
Josue Gomez 7 months ago
parent
commit
8b150c14ff
10 changed files with 110 additions and 35 deletions
  1. BIN
      dist/pyutl-2.1.tar.gz
  2. BIN
      dist/pyutl-2.5.tar.gz
  3. +15
    -0
      pyutl.egg-info/PKG-INFO
  4. +12
    -0
      pyutl.egg-info/SOURCES.txt
  5. +1
    -0
      pyutl.egg-info/dependency_links.txt
  6. +1
    -0
      pyutl.egg-info/top_level.txt
  7. +28
    -4
      pyutl/__init__.py
  8. +36
    -21
      pyutl/localenv.py
  9. +7
    -1
      pyutl/sendmail.py
  10. +10
    -9
      setup.py

BIN
dist/pyutl-2.1.tar.gz View File


BIN
dist/pyutl-2.5.tar.gz View File


+ 15
- 0
pyutl.egg-info/PKG-INFO View 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
- 0
pyutl.egg-info/SOURCES.txt View 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
- 0
pyutl.egg-info/dependency_links.txt View File

@@ -0,0 +1 @@


+ 1
- 0
pyutl.egg-info/top_level.txt View File

@@ -0,0 +1 @@
pyutl

+ 28
- 4
pyutl/__init__.py View File

@@ -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

+ 36
- 21
pyutl/localenv.py View File

@@ -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()

if not os.path.isfile(self.file):
raise NoEnvironmentFile(f'for file {self.file}')

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
self.files.append({'file': self._invoker(), 'exists': '', 'loaded': False})

def get(self, key, cast=None):
if cast is None:
return self.data[key]
# 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

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()

+ 7
- 1
pyutl/sendmail.py View File

@@ -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):


+ 10
- 9
setup.py View File

@@ -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…
Cancel
Save