Skip to content

Commit

Permalink
Merge pull request #258 from wasi0013/v0.0.15
Browse files Browse the repository at this point in the history
V0.0.15
  • Loading branch information
wasi0013 committed Nov 8, 2023
2 parents cb6bc62 + 8d1bda4 commit 14e36db
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 11 deletions.
16 changes: 15 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,18 @@ History
* copy logo instead of moving it permanently when configuring invoice.
* fixed f strings quote issue.
* made init command hidden.
* improved doc strings and help texts.
* improved doc strings and help texts.

0.0.15 (2023-11-08)
-------------------

* added new command rename for renaming existing projects.
* added new command rename for renaming existing tasks.
* updated show command to show active task and project when available.
* Simplified project start command.
* New projects can be started without project name.
* Project started without a name will now have a default name which can be renamed later.
* Simplified task start command.
* New tasks can be started without task name.
* Task started without a name will have a default name which can be renamed later at ease.
* Bug fix
2 changes: 1 addition & 1 deletion PyTM/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
__author__ = "Wasi"
__email__ = "wasi0013@gmail.com"
__version__ = "0.0.14"
__version__ = "0.0.15"
8 changes: 8 additions & 0 deletions PyTM/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def show():
- shows list of projects and status
"""
data = data_handler.load_data()
state = data_handler.load_data(settings.state_filepath)
table = Table()
table.add_column("Project Name", style="blue bold")
table.add_column("Created at")
Expand All @@ -114,6 +115,13 @@ def show():
f'{datetime.datetime.fromisoformat(value["created_at"]).strftime("%Y, %B, %d, %H:%M:%S %p")}',
value["status"],
)
message = ""
if state[settings.CURRENT_PROJECT]:
message += f"Active Project: [bold blue]{state[settings.CURRENT_PROJECT]}[/bold blue]\n"
if state[settings.CURRENT_TASK]:
message += f"Active Task: [bold green]{state[settings.CURRENT_TASK]}"
if message:
console.print(message)
console.print(table)


Expand Down
39 changes: 38 additions & 1 deletion PyTM/commands/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,23 @@ def pause():


@project.command()
@click.argument("project_name")
@click.argument("project_name", required=False)
def start(project_name):
"""
- starts an existing project or creates a new project.
"""
data = data_handler.load_data()

if project_name is None:
num = len(data.keys())
while project_name is None or data.get(project_name):
num += 1
project_name = f"UNNAMED_{num}"

data_handler.update(partial(project_handler.create, project_name=project_name))
state = data_handler.load_data(settings.state_filepath)
state[settings.CURRENT_PROJECT] = project_name
state[settings.CURRENT_TASK] = ""
data_handler.save_data(state, settings.state_filepath)
console.print(f"[bold blue]{project_name}[/bold blue] started.")
if project_name not in data.keys():
Expand Down Expand Up @@ -183,3 +191,32 @@ def json(project_name):
console.print_json(
data=project_handler.summary(data_handler.load_data(), project_name)
)


@project.command()
@click.argument("project_name")
@click.argument("new_name")
def rename(project_name, new_name):
"""
- Renames an existing project.
"""
data = data_handler.load_data()
state = data_handler.load_data(settings.state_filepath)

if not data.get(project_name):
console.print(
f"[bold red] {project_name} doesn't exists. Make sure the spelling is correct."
)
return
if data.get(new_name):
console.print(
f"[bold red] {new_name} already exists. Choose a different project name."
)
return
data_handler.update(
partial(project_handler.rename, project_name=project_name, new_name=new_name)
)
console.print(f"The project: {project_name} is renamed to {new_name}.")
if state[settings.CURRENT_PROJECT] == project_name:
state[settings.CURRENT_PROJECT] = new_name
data_handler.save_data(state, settings.state_filepath)
49 changes: 47 additions & 2 deletions PyTM/commands/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,22 @@ def pause():


@task.command()
@click.argument("task_name")
@click.argument("task_name", required=False)
def start(task_name):
"""
- starts a new/existing task in current project.
"""
data = data_handler.load_data()
state = data_handler.load_data(settings.state_filepath)
project_name = state.get(settings.CURRENT_PROJECT)
if project_name:
if project_name and data.get(project_name):
if task_name is None:
num = len(data.get(project_name).get("tasks", {}).keys())
while task_name is None or data.get(project_name).get("tasks", {}).get(
task_name, ""
):
num += 1
task_name = f"UNTITLED_{num}"
data_handler.update(
partial(task_handler.create, project_name=project_name, task_name=task_name)
)
Expand Down Expand Up @@ -141,3 +149,40 @@ def status():
console.print("[red bold]No active task.")
else:
console.print("[red bold]No active project.")


@task.command()
@click.argument("task_name")
@click.argument("new_name")
def rename(task_name, new_name):
"""
- Renames a task of the active project.
"""
state = data_handler.load_data(settings.state_filepath)
data = data_handler.load_data()
project_name = state.get(settings.CURRENT_PROJECT)
if project_name:
if not data.get(project_name):
console.print(f"[red bold]Project doesn't exist.")
state[settings.CURRENT_PROJECT] = ""
data_handler.save_data(state, settings.state_filepath)
return
if task_name not in data.get(project_name).get("tasks", []):
console.print(f"[bold red] {task_name} doesn't exists.")
return
if new_name in data.get(project_name).get("tasks", []):
console.print(f"Task {new_name} already exists. Choose a different name.")
return
data_handler.update(
partial(
task_handler.rename,
project_name=project_name,
task_name=task_name,
new_name=new_name,
)
)
state[settings.CURRENT_TASK] = new_name
data_handler.save_data(state, settings.state_filepath)
console.print(f"Renamed task: [green]{task_name}[/green] to {new_name}.")
else:
console.print("[red bold]No active project.")
7 changes: 7 additions & 0 deletions PyTM/core/project_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,10 @@ def remove(data, project_name):
if data.get(project_name):
del data[project_name]
return data


def rename(data, project_name, new_name):
if not new_name in data.keys():
if data.get(project_name):
data[new_name] = data.pop(project_name)
return data
10 changes: 10 additions & 0 deletions PyTM/core/task_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,13 @@ def remove(data, project_name, task_name):
if data.get(project_name)["tasks"].get(task_name):
del data.get(project_name)["tasks"][task_name]
return data


def rename(data, project_name, task_name, new_name):
if data.get(project_name):
if data.get(project_name).get("tasks"):
if not data.get(project_name).get("tasks").get(new_name):
data[project_name]["tasks"][new_name] = data[project_name]["tasks"].pop(
task_name
)
return data
22 changes: 17 additions & 5 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,17 @@ Screenshots
Installing PyTM
---------------

* First download and install the latest version of `Python <https://python.org/download/>`_ (Python 3.12+ is required).
* First download and install `pyenv <https://github.com/pyenv/pyenv#installation>`_. Use the command::

curl https://pyenv.run | bash

* Next, install Python 3.12 using the command::

pyenv install 3.12.0

Alternatively, you can skip pyenv installation and download python 3.12 or above from the official website and setup a virtualenv as well.


* Next, install PyTM from `PyPI <https://pypi.org/project/python-pytm/>`_ using :code:`pip`::

python -m pip install python-pytm
Expand All @@ -76,8 +86,9 @@ To see the available commands type::

Commands related to projects
============================

* Start a new/existing project: :code:`pytm project start PROJECT_NAME`
* Start a new project with a default name: :code:`pytm project start`
* Start a new project with the given name or, start an existing project: :code:`pytm project start PROJECT_NAME`
* Rename a project: :code:`pytm project rename OLD_PROJECT_NAME NEW_NAME`
* Remove a project: :code:`pytm project remove PROJECT_NAME`
* Check the status of a project: :code:`pytm project status PROJECT_NAME`
* Check the list of tasks and duration of a project: :code:`pytm project summary PROJECT_NAME`
Expand All @@ -87,8 +98,9 @@ Commands related to projects

Commands related to Task
========================

* Start a new or existing task in the current active project: :code:`pytm task start TASK_NAME`
* Start a new task with a default name in the current active project: :code:`pytm task start`
* Start a new task with the given name or existing task in the current active project: :code:`pytm task start TASK_NAME`
* Rename a task of the active project: :code:`pytm task rename OLD_TASK_NAME NEW_NAME`
* Remove a task: :code:`pytm task remove TASK_NAME`
* current task's status: :code:`pytm task status`
* Finish active task: :code:`pytm task finish`
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

setup(
name="python-pytm",
version="0.0.14",
version="0.0.15",
description="PyTM - an Open Source Python Time Management Tool for Mankind",
long_description=readme + "\n\n" + doclink + "\n\n" + history,
long_description_content_type="text/x-rst",
Expand Down

0 comments on commit 14e36db

Please sign in to comment.