Skip to content

Commit 14e36db

Browse files
authored
Merge pull request #258 from wasi0013/v0.0.15
V0.0.15
2 parents cb6bc62 + 8d1bda4 commit 14e36db

9 files changed

Lines changed: 144 additions & 11 deletions

File tree

HISTORY.rst

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,4 +95,18 @@ History
9595
* copy logo instead of moving it permanently when configuring invoice.
9696
* fixed f strings quote issue.
9797
* made init command hidden.
98-
* improved doc strings and help texts.
98+
* improved doc strings and help texts.
99+
100+
0.0.15 (2023-11-08)
101+
-------------------
102+
103+
* added new command rename for renaming existing projects.
104+
* added new command rename for renaming existing tasks.
105+
* updated show command to show active task and project when available.
106+
* Simplified project start command.
107+
* New projects can be started without project name.
108+
* Project started without a name will now have a default name which can be renamed later.
109+
* Simplified task start command.
110+
* New tasks can be started without task name.
111+
* Task started without a name will have a default name which can be renamed later at ease.
112+
* Bug fix

PyTM/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
__author__ = "Wasi"
22
__email__ = "wasi0013@gmail.com"
3-
__version__ = "0.0.14"
3+
__version__ = "0.0.15"

PyTM/cli.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ def show():
104104
- shows list of projects and status
105105
"""
106106
data = data_handler.load_data()
107+
state = data_handler.load_data(settings.state_filepath)
107108
table = Table()
108109
table.add_column("Project Name", style="blue bold")
109110
table.add_column("Created at")
@@ -114,6 +115,13 @@ def show():
114115
f'{datetime.datetime.fromisoformat(value["created_at"]).strftime("%Y, %B, %d, %H:%M:%S %p")}',
115116
value["status"],
116117
)
118+
message = ""
119+
if state[settings.CURRENT_PROJECT]:
120+
message += f"Active Project: [bold blue]{state[settings.CURRENT_PROJECT]}[/bold blue]\n"
121+
if state[settings.CURRENT_TASK]:
122+
message += f"Active Task: [bold green]{state[settings.CURRENT_TASK]}"
123+
if message:
124+
console.print(message)
117125
console.print(table)
118126

119127

PyTM/commands/project.py

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,23 @@ def pause():
112112

113113

114114
@project.command()
115-
@click.argument("project_name")
115+
@click.argument("project_name", required=False)
116116
def start(project_name):
117117
"""
118118
- starts an existing project or creates a new project.
119119
"""
120120
data = data_handler.load_data()
121+
122+
if project_name is None:
123+
num = len(data.keys())
124+
while project_name is None or data.get(project_name):
125+
num += 1
126+
project_name = f"UNNAMED_{num}"
127+
121128
data_handler.update(partial(project_handler.create, project_name=project_name))
122129
state = data_handler.load_data(settings.state_filepath)
123130
state[settings.CURRENT_PROJECT] = project_name
131+
state[settings.CURRENT_TASK] = ""
124132
data_handler.save_data(state, settings.state_filepath)
125133
console.print(f"[bold blue]{project_name}[/bold blue] started.")
126134
if project_name not in data.keys():
@@ -183,3 +191,32 @@ def json(project_name):
183191
console.print_json(
184192
data=project_handler.summary(data_handler.load_data(), project_name)
185193
)
194+
195+
196+
@project.command()
197+
@click.argument("project_name")
198+
@click.argument("new_name")
199+
def rename(project_name, new_name):
200+
"""
201+
- Renames an existing project.
202+
"""
203+
data = data_handler.load_data()
204+
state = data_handler.load_data(settings.state_filepath)
205+
206+
if not data.get(project_name):
207+
console.print(
208+
f"[bold red] {project_name} doesn't exists. Make sure the spelling is correct."
209+
)
210+
return
211+
if data.get(new_name):
212+
console.print(
213+
f"[bold red] {new_name} already exists. Choose a different project name."
214+
)
215+
return
216+
data_handler.update(
217+
partial(project_handler.rename, project_name=project_name, new_name=new_name)
218+
)
219+
console.print(f"The project: {project_name} is renamed to {new_name}.")
220+
if state[settings.CURRENT_PROJECT] == project_name:
221+
state[settings.CURRENT_PROJECT] = new_name
222+
data_handler.save_data(state, settings.state_filepath)

PyTM/commands/task.py

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,22 @@ def pause():
8888

8989

9090
@task.command()
91-
@click.argument("task_name")
91+
@click.argument("task_name", required=False)
9292
def start(task_name):
9393
"""
9494
- starts a new/existing task in current project.
9595
"""
96+
data = data_handler.load_data()
9697
state = data_handler.load_data(settings.state_filepath)
9798
project_name = state.get(settings.CURRENT_PROJECT)
98-
if project_name:
99+
if project_name and data.get(project_name):
100+
if task_name is None:
101+
num = len(data.get(project_name).get("tasks", {}).keys())
102+
while task_name is None or data.get(project_name).get("tasks", {}).get(
103+
task_name, ""
104+
):
105+
num += 1
106+
task_name = f"UNTITLED_{num}"
99107
data_handler.update(
100108
partial(task_handler.create, project_name=project_name, task_name=task_name)
101109
)
@@ -141,3 +149,40 @@ def status():
141149
console.print("[red bold]No active task.")
142150
else:
143151
console.print("[red bold]No active project.")
152+
153+
154+
@task.command()
155+
@click.argument("task_name")
156+
@click.argument("new_name")
157+
def rename(task_name, new_name):
158+
"""
159+
- Renames a task of the active project.
160+
"""
161+
state = data_handler.load_data(settings.state_filepath)
162+
data = data_handler.load_data()
163+
project_name = state.get(settings.CURRENT_PROJECT)
164+
if project_name:
165+
if not data.get(project_name):
166+
console.print(f"[red bold]Project doesn't exist.")
167+
state[settings.CURRENT_PROJECT] = ""
168+
data_handler.save_data(state, settings.state_filepath)
169+
return
170+
if task_name not in data.get(project_name).get("tasks", []):
171+
console.print(f"[bold red] {task_name} doesn't exists.")
172+
return
173+
if new_name in data.get(project_name).get("tasks", []):
174+
console.print(f"Task {new_name} already exists. Choose a different name.")
175+
return
176+
data_handler.update(
177+
partial(
178+
task_handler.rename,
179+
project_name=project_name,
180+
task_name=task_name,
181+
new_name=new_name,
182+
)
183+
)
184+
state[settings.CURRENT_TASK] = new_name
185+
data_handler.save_data(state, settings.state_filepath)
186+
console.print(f"Renamed task: [green]{task_name}[/green] to {new_name}.")
187+
else:
188+
console.print("[red bold]No active project.")

PyTM/core/project_handler.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,10 @@ def remove(data, project_name):
5252
if data.get(project_name):
5353
del data[project_name]
5454
return data
55+
56+
57+
def rename(data, project_name, new_name):
58+
if not new_name in data.keys():
59+
if data.get(project_name):
60+
data[new_name] = data.pop(project_name)
61+
return data

PyTM/core/task_handler.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,13 @@ def remove(data, project_name, task_name):
7676
if data.get(project_name)["tasks"].get(task_name):
7777
del data.get(project_name)["tasks"][task_name]
7878
return data
79+
80+
81+
def rename(data, project_name, task_name, new_name):
82+
if data.get(project_name):
83+
if data.get(project_name).get("tasks"):
84+
if not data.get(project_name).get("tasks").get(new_name):
85+
data[project_name]["tasks"][new_name] = data[project_name]["tasks"].pop(
86+
task_name
87+
)
88+
return data

README.rst

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,17 @@ Screenshots
5656
Installing PyTM
5757
---------------
5858

59-
* First download and install the latest version of `Python <https://python.org/download/>`_ (Python 3.12+ is required).
59+
* First download and install `pyenv <https://github.com/pyenv/pyenv#installation>`_. Use the command::
60+
61+
curl https://pyenv.run | bash
62+
63+
* Next, install Python 3.12 using the command::
64+
65+
pyenv install 3.12.0
66+
67+
Alternatively, you can skip pyenv installation and download python 3.12 or above from the official website and setup a virtualenv as well.
68+
69+
6070
* Next, install PyTM from `PyPI <https://pypi.org/project/python-pytm/>`_ using :code:`pip`::
6171

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

7787
Commands related to projects
7888
============================
79-
80-
* Start a new/existing project: :code:`pytm project start PROJECT_NAME`
89+
* Start a new project with a default name: :code:`pytm project start`
90+
* Start a new project with the given name or, start an existing project: :code:`pytm project start PROJECT_NAME`
91+
* Rename a project: :code:`pytm project rename OLD_PROJECT_NAME NEW_NAME`
8192
* Remove a project: :code:`pytm project remove PROJECT_NAME`
8293
* Check the status of a project: :code:`pytm project status PROJECT_NAME`
8394
* Check the list of tasks and duration of a project: :code:`pytm project summary PROJECT_NAME`
@@ -87,8 +98,9 @@ Commands related to projects
8798

8899
Commands related to Task
89100
========================
90-
91-
* Start a new or existing task in the current active project: :code:`pytm task start TASK_NAME`
101+
* Start a new task with a default name in the current active project: :code:`pytm task start`
102+
* Start a new task with the given name or existing task in the current active project: :code:`pytm task start TASK_NAME`
103+
* Rename a task of the active project: :code:`pytm task rename OLD_TASK_NAME NEW_NAME`
92104
* Remove a task: :code:`pytm task remove TASK_NAME`
93105
* current task's status: :code:`pytm task status`
94106
* Finish active task: :code:`pytm task finish`

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323

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

0 commit comments

Comments
 (0)