forked from platformio/platformio-core
Implement ApplicationState Manager
This commit is contained in:
1 parent
e41226fcbc
commit
257f751dfa
5 files changed
+181
-78
No files matched your search
@@ -1,7 +1,6 @@
|
||||
# Copyright (C) Ivan Kravets <me@ikravets.com>
|
||||
# See LICENSE for details.
|
||||
|
||||
import json
|
||||
from os import name as os_name
|
||||
from os import getcwd, getenv, makedirs, utime
|
||||
from os.path import dirname, expanduser, isdir, isfile, join, realpath
|
||||
@@ -22,28 +21,6 @@ except ImportError:
|
||||
from ConfigParser import ConfigParser
|
||||
|
||||
|
||||
class AppState(object):
|
||||
|
||||
def __init__(self, path=None):
|
||||
self.path = path
|
||||
if not self.path:
|
||||
self.path = join(get_home_dir(), "appstate.json")
|
||||
self._state = {}
|
||||
|
||||
def __enter__(self):
|
||||
try:
|
||||
if isfile(self.path):
|
||||
with open(self.path, "r") as fp:
|
||||
self._state = json.load(fp)
|
||||
except ValueError:
|
||||
self._state = {}
|
||||
return self._state
|
||||
|
||||
def __exit__(self, type_, value, traceback):
|
||||
with open(self.path, "w") as fp:
|
||||
json.dump(self._state, fp, indent=4)
|
||||
|
||||
|
||||
def get_systype():
|
||||
if system() == "Windows":
|
||||
return "windows"
|
||||
|
||||
Reference in new issue
Block a user