Skip to content

Commit

Permalink
Version 0.0.9
Browse files Browse the repository at this point in the history
  • Loading branch information
ohidurbappy committed Apr 4, 2021
1 parent 9c01148 commit 0d12cd0
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 140 deletions.
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,22 @@
Changelog
=========
Version 0.0.9
------------
* Removed Namespace class and related code
* Added chunks() function
* Improved Config class
* Added JsonCache alias for Config class

Version 0.0.8
------------
* Added slugify() function
* Added float_range() function

Version 0.0.7
------------
* Added get_datadir() function
* Added get_windows_appdata_dir() function

Version 0.0.6
------------
* Fixed configuration format in json
Expand Down
8 changes: 4 additions & 4 deletions reusable/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
A python package with reusable functions and utility classes.
"""
__author__="Ohidur Rahman Bappy"
__version__="0.0.8"
__version__="0.0.9"
__license__ = "MIT"
__status__ = "Production"

__all__=[
'AppConfig','Config','Namespace'
'AppConfig','Config','JsonCache'
]

from .config import AppConfig,Config
from .namespace import Namespace
from .config import AppConfig,Config,JsonCache

21 changes: 15 additions & 6 deletions reusable/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, config_file_name="config.json"):
setattr(self, key, value)


class Config(object):
class Config:
r"""Config utility class to load a json file
Usage::
Expand All @@ -62,14 +62,18 @@ def __init__(self, config_file_name="config.json"):

def _open_config_file(self):
"""Load the config file"""

with open(self.config_file_name) as json_data_file:
conf = json.load(json_data_file)
return conf
try:
with open(self.config_file_name,encoding='utf-8') as json_data_file:
conf = json.load(json_data_file)
return conf
except FileNotFoundError:
with open(self.config_file_name, 'w',encoding='utf-8') as json_data_file:
json.dump({},json_data_file,indent=2)
return {}

def save_config_file(self):
"""Saves the config file"""
with open(self.config_file_name, 'w') as outfile:
with open(self.config_file_name, 'w',encoding='utf-8') as outfile:
json.dump(self._config, outfile,indent=2)

def get(self, key, default_val=None):
Expand All @@ -87,7 +91,12 @@ def get(self, key, default_val=None):

def put(self, key, value):
self._config[key] = value
return self

def update(self):
"""Update the config file"""
self.save_config_file()


class JsonCache(Config):
pass
16 changes: 15 additions & 1 deletion reusable/iterable_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,18 @@ def key(o): return o
for k in force_keys:
counter[k] += 0

return counter.items()
return counter.items()


def chunks(lst, n):
"""Yield successive n-sized chunks from lst.
Usage::
>>> from reusable.functions import chunks
>>> li=[1,3,5,6,8]
>>> for g in chunks(li,2):
... print(g)
"""
for i in range(0, len(lst), n):
yield lst[i:i + n]
129 changes: 0 additions & 129 deletions reusable/namespace.py

This file was deleted.

0 comments on commit 0d12cd0

Please sign in to comment.