wc_track Internals

Overview

wc_track is a wrapper around sauron and stl that provides an initial implementation of per-project tracking and operation. See wc-track Manual for more information about use.

In most cases, you will not need to use wc_track from another Python module, although some of the data in the projects dictionary may be useful in other scripts. In the future the configuration of projects may be distinct from wc_track, but at the moment you will need to edit wc_track.py before installing and using wc-track.

Dependencies

Internal

stl

Standard Library

Implementation

Variables and Data

username

Stores the current username. By default, uses os.getusername to get the username of the user that owns its process. Override if needed, and with caution.

personal_log

Stores the path of a “personal” projects log file. Defaults to: ~/.stl/personal-stats-<hostname>.log, where <hostname> is the output of python.socket.gethostname(). Override as needed.

work_log

Stores the path of a “work” projects log file. Defaults to: ~/.stl/work-stats-<hostname>.log, where <hostname> is the output of noindex:python:socket.gethostname(). Override as needed.

projects

A data structure (python dictionary) that stores configuration information for projects that you will use wc_track to collect data on regularly. for tracking.

Each project has a key in projects, which holds a dictionary. The keys of that dictionary map to the arguments to stl.generate_events()/stl. The projects the following keys:

projects.<project>.path

The path to the project’s top level directory. wc_track passes this value as directory to stl.generate_events().

projects.<project>.target

The name of the emacs daemon to send notifications about this project. wc_track passes this value as target to stl.generate_events().

projects.<project>.emacs

A Boolean value. If True, send a notification to emacs via sauron. wc_track passes this value as emacs to stl.generate_events().

projects.<project>.quiet

A Boolean value. If True, suppress all output on the console. wc_track passes this value as quiet to stl.generate_events().

projects.<project>.log

A filesystem path to the log. Typically personal_log or work_log.

projects.<project>.ext

The extension of the project files. wc_track passes this value as quiet to stl.generate_events().

set_quiet()
Parameters:
  • force (bool) – Pass True to override the value of projects.<project>.quiet.
  • project_quiet – A value, likely a bool, which set_quiet() will return if force is False.

A helper method that takes two arguments. If the first is true, the method will return True (and override the projects.<project>.quiet,) otherwise set_quiet() returns the second value.

main()

The core operation of the program. Includes the following operations:

  • Read input and user from the command line.
  • If users do not specify and project, iterate through all projects in projects and report all statistics if different from the cached values. (Unless passed forced on the command line.)
  • If users do specify a project, report only thhose projects, and only if they’ve not changed in the since (Unless passed forced on the command line.)

See wc-track Manual for more information.

Extension

In most cases, there are few possible modifications or extensions to wc_track, but it serves as a good example for the kinds of modification and interfaces that you could provide to the kinds of personal statistic monitoring and recording as part of STL and future related tools.