Skip to content

Commit 5eb9db3

Browse files
clamytoepybites
authored andcommitted
Moved database to a centralized location in the user's home directory… (#50)
* Moved database to a centralized location in the user's home directory. Renamed database. Removed all f-strings and used .format() instead. Upgraded to version 0.1.0. * Modified to utilize namespace properly. * Modified README so that it uses pip to install the package.
1 parent 6c00ce5 commit 5eb9db3

File tree

6 files changed

+88
-33
lines changed

6 files changed

+88
-33
lines changed

23/clamytoe/README.md

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# pyTrack
2-
> Simple project/task time tracker for Python 3.6.0+.
2+
3+
> Simple project/task time tracker for Python 3.
34
45
[![GitHub issues][issues-image]][issues-url]
56
[![GitHub forks][fork-image]][fork-url]
@@ -20,8 +21,35 @@ cd Projects
2021
git clone https://github.com/clamytoe/pyTrack.git
2122
python3.6 -m venv venv
2223
source ./venv/bin/activate
23-
pip install -r requirements.txt
24-
python setup.py install
24+
pip install .
25+
```
26+
27+
These are all of the packages that get installed:
28+
29+
```bash
30+
pip freeze
31+
click==6.7
32+
dateparser==0.6.0
33+
humanize==0.5.1
34+
maya==0.3.2
35+
peewee==2.10.1
36+
pendulum==1.2.4
37+
python-dateutil==2.6.0
38+
pyTrack==0.1.2
39+
pytz==2017.2
40+
pytzdata==2017.2
41+
regex==2017.6.23
42+
ruamel.yaml==0.15.15
43+
six==1.10.0
44+
tzlocal==1.4
45+
```
46+
47+
## Uninstall
48+
49+
Uninstalling the package is very simple.
50+
51+
```bash
52+
pip uninstall pyTrack
2553
```
2654

2755
## Usage example
@@ -45,6 +73,7 @@ Commands:
4573
```
4674
4775
### List all projects
76+
4877
To list all of the projects that you are currently tracking:
4978
5079
```bash
@@ -58,6 +87,7 @@ pytrack
5887
The project marked with an ``*`` is the currently selected project. This means that the **start** and **stop** commands will apply to that project.
5988
6089
### Add a new project
90+
6191
To add a new project use the **add** command followed by the name of your project. If longer than one word, enclose it in quotes.
6292
6393
```bash
@@ -69,6 +99,7 @@ Selected: [3] Replace the motor on the A/C unit
6999
The project is added and selected as the default project.
70100
71101
### Remove a project
102+
72103
To remove a project use the **remove** command followed by the project id.
73104
74105
> NOTE: To get the project id, just run **pytrack** by itself.
@@ -83,6 +114,7 @@ Removed [3] Replace the motor on the A/C unit
83114
You are asked to confirm your action and a confirmation message is displayed.
84115
85116
### Select a project
117+
86118
To switch the default project, use the **select** command.
87119
88120
```bash
@@ -91,6 +123,7 @@ Selected: [1] Put together a README.md file
91123
```
92124
93125
### Start tracking the currently selected project
126+
94127
If you are ready to work on a project that you want to track, simply issue the **start** command to start tracking it.
95128
96129
```bash
@@ -107,6 +140,7 @@ pytrack
107140
```
108141
109142
### Stop tracking the currently ACTIVE project
143+
110144
When you are finished or are read to take a break simply run the **stop** command.
111145
112146
```bash
@@ -127,6 +161,7 @@ The default project will remain selected until you add a new project or you chan
127161
> NOTE: Feel free to take as many breaks as needed, you can always start tracking once again at any time.
128162
129163
### Reset the database
164+
130165
If you have completed all of your projects and you want to start with a clean slate so that your new projects don't start at the last created project id, simply **reset** the database.
131166
132167
```bash
@@ -139,18 +174,28 @@ All records have been removed.
139174
> WARNING: This is unrecoverable! Make sure that you truly want to delete all logs!
140175
141176
## TODO
177+
142178
* I plan on adding an option to output the logs into a csv file.
143179
144180
## Development setup
145181
146182
If you would like to install this in order to play around with the code and make modifications yourself, simply change the last command in the installation instructions above to the following:
147183
148184
```bash
149-
python setup.py develop
185+
pip install -e .
150186
```
151187
152188
## Release History
153189
190+
* 0.1.2
191+
* CHANGE: Modified to use pip to install the package.
192+
* 0.1.1
193+
* CHANGE: Modified imports to utilize namespaces properly.
194+
* 0.1.0
195+
* CHANGE: Moved the database file into the home directory of the user because when installed, the database was getting created from wherever the command was being issued.
196+
* CHANGE: Renamed the database file.
197+
* 0.0.6
198+
* CHANGE: Removed all f-strings so that the code could be used in older versions of Python.
154199
* 0.0.5
155200
* FIX: Fixed bug when the currently selected project is removed, no other is selected as the default.
156201
* 0.0.4

23/clamytoe/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
#!/usr/bin/env python3.6
1+
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
from sys import argv
44

55
import click
66
from peewee import OperationalError
77

8-
from pytrack.models import db, Log, Project
9-
from pytrack.pytrack import get_projects, add_project, select_project, remove_project
10-
from pytrack.pytrack import start_tracking, stop_tracking, reset_db
8+
from pytrack import db, Log, Project
9+
from pytrack import get_projects, add_project, select_project, remove_project
10+
from pytrack import start_tracking, stop_tracking, reset_db
1111

1212

1313
def main():

23/clamytoe/pytrack/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
# -*- coding: utf-8 -*-
22
from .models import db, Log, Project
33
from .pytrack import get_projects, add_project, select_project, remove_project
4-
from .pytrack import start_tracking, stop_tracking, reset_db
4+
from .pytrack import start_tracking, stop_tracking, reset_db

23/clamytoe/pytrack/models.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
# -*- coding: utf-8 -*-
2+
from os import mkdir, path
3+
24
from peewee import BooleanField, CharField, DateTimeField, ForeignKeyField, PrimaryKeyField
35
from peewee import Model, OperationalError, SqliteDatabase
46

5-
DATABASE = 'pyTrack_db.sqlite'
7+
DB_NAME = 'pyTrack.db'
8+
HOME = path.expanduser('~')
9+
DB_FOLDER = path.join(HOME, '.pytrack')
10+
DATABASE = path.join(DB_FOLDER, DB_NAME)
11+
12+
if not path.exists(DB_FOLDER):
13+
mkdir(DB_FOLDER)
14+
615
db = SqliteDatabase(DATABASE)
716

817

@@ -21,7 +30,6 @@ class Project(BaseModel):
2130
status = BooleanField(default=0)
2231
duration = CharField(default='0:00:00')
2332

24-
2533
class Meta:
2634
db_table = 'projects'
2735

@@ -38,6 +46,7 @@ class Log(BaseModel):
3846
class Meta:
3947
db_table = 'logs'
4048

49+
4150
if __name__ == '__main__':
4251
try:
4352
Project.create_table()

23/clamytoe/pytrack/pytrack.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#!/usr/bin/env python3.6
1+
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
from maya import get_localzone, MayaInterval, now, parse
44

@@ -15,9 +15,9 @@ def get_projects(display=False):
1515
projects.append(project)
1616
if display:
1717
if project.selected:
18-
print(f'*[{project.id}] {project.duration} {STATE[project.status]}: {project.name}')
18+
print('*[{}] {} {}: {}'.format(project.id, project.duration, STATE[project.status], project.name))
1919
else:
20-
print(f' [{project.id}] {project.duration} {STATE[project.status]}: {project.name}')
20+
print(' [{}] {} {}: {}'.format(project.id, project.duration, STATE[project.status], project.name))
2121
else:
2222
print('You are not currently tracking any projects.')
2323
return projects
@@ -32,9 +32,9 @@ def get_selected(display=True):
3232
selected = project
3333
if display:
3434
if selected:
35-
print(f'Selected: {selected.name}')
35+
print('Selected: {}'.format(selected.name))
3636
else:
37-
print(f'Selected: {selected}')
37+
print('Selected: {}'.format(selected))
3838

3939
return selected
4040

@@ -74,7 +74,7 @@ def update_project(project):
7474
project.duration = duration
7575
project.status = 0
7676
project.save()
77-
print(f'Deactivating: {project.name} with total time of {project.duration}')
77+
print('Deactivating: {} with total time of {}'.format(project.name, project.duration))
7878

7979

8080
def add_project(name):
@@ -83,12 +83,12 @@ def add_project(name):
8383
active = get_active()
8484

8585
if active:
86-
print(f'There is an active project: [{active.id}] {active.name}')
86+
print('There is an active project: [{}] {}'.format(active.id, active.name))
8787
print('Please close that out before adding another project.')
8888
else:
8989
project = Project.create(name=name)
9090
project.save()
91-
print(f'Added Project: [{project.id}] {project.name}')
91+
print('Added Project: [{}] {}'.format(project.id, project.name))
9292
select_project(project.id)
9393

9494

@@ -98,8 +98,8 @@ def select_project(id):
9898
active = get_active()
9999

100100
if active:
101-
print(f'Cannot make project selection while there is an active project!')
102-
print(f'Currently tracking: {active.name}')
101+
print('Cannot make project selection while there is an active project!')
102+
print('Currently tracking: {}'.format(active.name))
103103
else:
104104
projects = get_projects()
105105

@@ -114,13 +114,13 @@ def select_project(id):
114114
if project.id == id:
115115
project.selected = True
116116
project.save()
117-
print(f'Selected: [{project.id}] {project.name}')
117+
print('Selected: [{}] {}'.format(project.id, project.name))
118118
else:
119119
# unselect all others
120120
project.selected = False
121121
project.save()
122122
else:
123-
print(f'[{id}] is not a valid entry. \nChoose from the following:\n')
123+
print('[{}] is not a valid entry. \nChoose from the following:\n'.format(id))
124124
_ = get_projects(display=True)
125125

126126

@@ -139,17 +139,17 @@ def remove_project(id):
139139
select = proj.id
140140

141141
if project:
142-
print(f'About to remove [{project.id}] {project.name}')
142+
print('About to remove [{}] {}'.format(project.id, project.name))
143143
answer = input('Are you sure (y/n): ')
144144
if 'y' in answer.lower():
145145
project.delete_instance()
146-
print(f'Removed [{project.id}] {project.name}')
146+
print('Removed [{}] {}'.format(project.id, project.name))
147147
if selected and select:
148148
select_project(select)
149149
else:
150150
print('Aborted')
151151
else:
152-
print(f'Project [{id}] does not exists!')
152+
print('Project [{}] does not exists!'.format(id))
153153

154154

155155
def reset_db():
@@ -172,14 +172,14 @@ def start_tracking():
172172
active = get_active()
173173

174174
if active:
175-
print(f'Already tracking {active.name}!')
175+
print('Already tracking {}!'.format(active.name))
176176
else:
177177
project = get_selected(display=False)
178178
log = Log.create(project=project, start_time=now().datetime())
179179
log.save()
180180
project.status = 1
181181
project.save()
182-
print(f'Activating: {project.name}')
182+
print('Activating: {}'.format(project.name))
183183

184184

185185
def stop_tracking():
@@ -198,4 +198,4 @@ def stop_tracking():
198198
# update the project's status and duration time
199199
update_project(active)
200200
else:
201-
print(f'There are currently no active projects...')
201+
print('There are currently no active projects...')

23/clamytoe/setup.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,22 @@
1-
#!/usr/bin/env python3.6
1+
#!/usr/bin/env python
22
# -*- coding: utf-8 -*-
33
from setuptools import setup
44

55

66
setup(
77
name='pyTrack',
8-
version='0.0.5',
8+
version='0.1.2',
99
author='Martin Uribe',
1010
author_email='[email protected]',
1111
url='https://github.com/clamytoe/pyTrack',
12-
description='Simple project/task time tracker for Python 3.6.0+',
12+
description='Simple project/task time tracker for Python 3',
1313
long_description='Helps you keep track of how much time you spend on your projects and tasks. A sqlite database '
1414
'is used to track your time logs, and it is kept simply by only implementing as few commands as '
1515
'needed to get a full featured application. You can add/remove multiple projects, start/stop '
1616
'tracking any of them, or completely reset the database to start with a clean slate',
1717
license='MIT',
18-
keywords='3.6 project tracker peewee click maya',
18+
packages=['pytrack'],
19+
keywords='project tracker peewee click maya',
1920
py_modules=[
2021
'main',
2122
'pytrack.models',

0 commit comments

Comments
 (0)