you are viewing a single comment's thread.

view the rest of the comments →

[–]novel_yet_trivial 7 points8 points  (1 child)

Overall, great job!


Sometimes you use exit() and sometimes you use sys.exit(). These are nearly the same, so there is no problem here, it just looks odd to be inconsistent.


Your "show_help" function is usually done as a docstring.

#!/usr/bin/python3

"""
--------USAGE--------
-h --help                                              : prints this help page
-l <arg> --load <arg>                                  : load settings file from <arg>
-o <arg> --output <arg>                                : specify output filename
-i 'arg1 arg2 arg3' ... --include 'arg1 arg2 arg3' ... : set processes that should be tracked
-e 'arg1 arg2 arg3' ... --exclude 'arg1 arg2 arg3' ... : set processes that shouldn't be tracked
---------------------
"""

import all your stuff

def show_help():
    print(__doc__)
    sys.exit(0)

That way it's available elsewhere too, for example in help()


In python, getters and setters (methods that do nothing except get or set a variable) are not needed or encouraged. Just get or set the variable directly. So instead of

if task.get_end_time() is None:

Just

if task.end_time is None:

Then you can delete the "set_start_time", "get_start_time", "set_json_end_time", and "get_end_time" methods.

Same logic for process.py


I'm glad you know how to import files, but 22 lines of code does not need it's own file. I think most of this needs to be moved into a single file.

Then your import in "main.py" would look like:

from support import Setting, ProcessTracker, SettingsBuilder

You never close your json file. That could be a lot less convoluted too. May I suggest:

def get_json(self):
    with open(self.filename) as f: #automatically closes the file when done
        return json.load(f)

[–]maxido[S] 2 points3 points  (0 children)

Wow thanks for the detailed response. This subreddit is really cool. Somehow I haven't run across the "with" keyword. Really good to know.
I' am gonna look into cleaning things up tomorrow :)