summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore5
-rw-r--r--LICENSE25
-rw-r--r--README.md1
-rw-r--r--jstate/__init__.py1
-rw-r--r--jstate/jstate.py21
-rw-r--r--setup.cfg23
6 files changed, 76 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..25a6a71
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,5 @@
+.idea
+build/
+dist/
+jstate.egg-info
+venv/ \ No newline at end of file
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..3d4446b
--- /dev/null
+++ b/LICENSE
@@ -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. \ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..1bbb78a
--- /dev/null
+++ b/README.md
@@ -0,0 +1 @@
+# jstate \ No newline at end of file
diff --git a/jstate/__init__.py b/jstate/__init__.py
new file mode 100644
index 0000000..8254a30
--- /dev/null
+++ b/jstate/__init__.py
@@ -0,0 +1 @@
+from .jstate import JState \ No newline at end of file
diff --git a/jstate/jstate.py b/jstate/jstate.py
new file mode 100644
index 0000000..799f924
--- /dev/null
+++ b/jstate/jstate.py
@@ -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)) \ No newline at end of file
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..9cb9358
--- /dev/null
+++ b/setup.cfg
@@ -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
+