Skip to content

Commit

Permalink
fixed default_session_data issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonak-Adipta-Kalita committed Jul 23, 2024
1 parent f10ef72 commit db5d194
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 15 deletions.
10 changes: 7 additions & 3 deletions flomo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,23 @@ def init():
conf.create_config()


# TODO: default_session_data from Config.
default_session_data = config.Config(get_default_session_data=True).get_config(
"default_session_data"
)


@flomo.command(aliases=["s"])
@click.option(
"-t",
"--tag",
help="Session tag name.",
# default=default_session_data["tag"],
default=default_session_data["tag"],
)
@click.option(
"-n",
"--name",
help="Session Name",
# default=default_session_data["name"],
default=default_session_data["name"],
)
def start(tag: str, name: str):
"""
Expand Down
29 changes: 20 additions & 9 deletions flomo/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,31 @@
import flomo.errors as errors
import flomo.helpers as helpers

default_session_data = {
"tag": "Work",
"name": "Working",
}

tag_colors = {"Work": "red", "Study": "blue", "Exercise": "green"}


class Config:
def __init__(self, initializing: bool = False):
def __init__(
self, initializing: bool = False, get_default_session_data: bool = False
):
self.path = helpers.get_path("config.json", in_data=True)

if not initializing and not self._config_file_exists():
if (
not initializing
and not get_default_session_data
and not self._config_data_check()
):
raise errors.NoConfigError()

def _config_file_exists(self):
return os.path.exists(self.path) and self._config_data_check()

def _config_data_check(self):
# TODO: Fix: if config file is improper, it overrides changes made by the user.
with open(self.path, "r") as f:
data = json.load(f)

Expand All @@ -35,21 +47,20 @@ def create_config(self):

with open(self.path, "w") as f:
data = {
"default_session_data": {
"tag": "Work",
"name": "Working",
},
"default_session_data": default_session_data,
"notification_priority": "normal",
"tag_colors": {"Work": "blue", "Study": "red", "Exercise": "green"},
"tag_colors": tag_colors,
}

json.dump(data, f, indent=4)

def get_config(self, key: str):
if key == "default_session_data" and not self._config_file_exists():
return default_session_data

try:
with open(self.path, "r") as f:
data = json.load(f)

return data[key]
except KeyError:
raise errors.InvalidConfigKeyError(key)
2 changes: 1 addition & 1 deletion flomo/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def play_sound():
path = get_path("beep.mp3")
conf = config.Config()

notification_priority: str = conf.get_config("notification_priority")
notification_priority = str(conf.get_config("notification_priority"))

if notification_priority.lower() == "off":
return
Expand Down
12 changes: 10 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@
SHORT_DESCRIPTION = "A Flowmodoro CLI for producitivity enthusiasts."
AUTHOR_EMAIL = "<[email protected]>"
URL = "https://github.com/moiSentineL/flomo"
INSTALL_REQUIRES = ["click", "blessed", "rich", "playsound==1.2.2", "click-aliases"]
INSTALL_REQUIRES = [
"click",
"blessed",
"rich",
"playsound==1.2.2",
"click-aliases",
"pandas",
"tabulate",
]
PROJECT_URLS = {
"Documentation": "https://github.com/moiSentineL/flomo#flomo",
"Issue tracker": "https://github.com/moiSentineL/flomo/issues",
Expand All @@ -20,7 +28,7 @@
"Programming Language :: Python :: 3",
]

with open("README.md", "r") as fh:
with open("docs/README.md", "r") as fh:
LONG_DESCRIPTION = fh.read()

if __name__ == "__main__":
Expand Down

0 comments on commit db5d194

Please sign in to comment.