initial
This commit is contained in:
commit
2822361b3b
5
.gitignore
vendored
Normal file
5
.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
||||
.idea
|
||||
build/
|
||||
dist/
|
||||
jstate.egg-info
|
||||
venv/
|
25
LICENSE
Normal file
25
LICENSE
Normal file
@ -0,0 +1,25 @@
|
||||
BSD 2-Clause License
|
||||
|
||||
Copyright (c) 2021, Evgeny Zinoviev
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1
jstate/__init__.py
Normal file
1
jstate/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from .jstate import JState
|
21
jstate/jstate.py
Normal file
21
jstate/jstate.py
Normal file
@ -0,0 +1,21 @@
|
||||
import os, json
|
||||
|
||||
|
||||
class JState:
|
||||
def __init__(self, file: str, default=None):
|
||||
if default is None:
|
||||
default = {}
|
||||
self.file = file
|
||||
self.default = default
|
||||
|
||||
def read(self) -> dict:
|
||||
if not os.path.exists(self.file):
|
||||
self.write(self.default)
|
||||
return self.default
|
||||
|
||||
with open(self.file, 'r') as f:
|
||||
return json.loads(f.read())
|
||||
|
||||
def write(self, state: dict):
|
||||
with open(self.file, 'w') as f:
|
||||
f.write(json.dumps(state))
|
23
setup.cfg
Normal file
23
setup.cfg
Normal file
@ -0,0 +1,23 @@
|
||||
[metadata]
|
||||
name = jstate
|
||||
version = 0.0.4
|
||||
author = Evgeny S.
|
||||
author_email = me@ch1p.io
|
||||
description =
|
||||
long_description = file: README.md
|
||||
license = BSD
|
||||
license_file = LICENSE
|
||||
long_description_content_type = text/markdown
|
||||
url = https://github.com/gch1p/jstate.git
|
||||
project_urls =
|
||||
Bug Tracker = https://github.com/gch1p/jstate/issues
|
||||
classifiers =
|
||||
Programming Language :: Python :: 3
|
||||
License :: OSI Approved :: BSD License
|
||||
Operating System :: OS Independent
|
||||
|
||||
[options]
|
||||
packages = jstate
|
||||
python_requires = >=3.6
|
||||
include_package_data = True
|
||||
|
Loading…
x
Reference in New Issue
Block a user