Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ GPATH
GRTAGS
GTAGS
stats
.mypy_cache/
.vscode/
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't add these here. You can add your local gitignore under .git/info/exclude instead.

8 changes: 4 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ zero-based integer will be used.
Format of race history
----------------------

wpm will save scores in a CSV file in `~/.wpm.csv`. This file can be loaded
wpm will save scores in a CSV file in `~/.config/wpm/wpm.csv`. This file can be loaded
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather just use wpm.csv since this will (according to what I propose) be in different directories, dependent on what system and setup you have. Then add a short section where you describe how we decide where the file goes (simple: first time user and you have XDG_HOME, it goes there, otherwise your home directory).

directly into Excel. It uses the same format as TypeRacer, with the addition of
a few extra columns at the end. That means is should be possible to use
existing TypeRacer score history tools with this file with minor modifications.
Expand All @@ -164,7 +164,7 @@ tag str A user supplied tag for that score (e.g., keyboard)
========== ======== =======================================================

Should there be any problem saving or loading the score history, it will copy
the existing file into `~/.wpm.csv.backup` and create a new one.
the existing file into `~/.config/wpm/wpm.csv.backup` and create a new one.

Tagging races
-------------
Expand All @@ -185,10 +185,10 @@ grouped by each tag. It shows things like the average over time, along with
confidence and prediction intervals. An item like `n-10` means "the last 10
games".

The ~/.wpmrc file
The wpmrc file
-----------------

The first time you start wpm, it writes a `.wpmrc` file to your home directory.
The first time you start wpm, it writes a `wpmrc` file to `~/.config/wpm/wpmrc`.
It contains user settings that you can change. They are given in the table
below.

Expand Down
2 changes: 1 addition & 1 deletion wpm/commandline.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def parse_args():
argp.add_argument("--cpm", default=False, action="store_true",
help="Shows CPM instead of WPM in stats")

argp.add_argument("--stats-file", default="~/.wpm.csv", type=str,
argp.add_argument("--stats-file", default="~/.config/wpm/wpm.csv", type=str,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather get the default path here from get_config_directory

help="File to record score history to (CSV format)")

argp.add_argument("--id", "-i", default=None, type=int,
Expand Down
22 changes: 15 additions & 7 deletions wpm/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def int_tuple(s):
except ValueError:
raise ConfigError("Required format is (integer, integer): %s" % s)

def get_config_directory():
xdg_config_home = os.getenv("XDG_CONFIG_HOME")
if xdg_config_home == "":
xdg_config_home = os.path.join(os.getenv("HOME"), ".config")
return os.path.join(xdg_config_home, "wpm")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments below.


DEFAULTS = {
"curses": {
"escdelay": (str, 15, "Curses ESCDELAY"),
Expand Down Expand Up @@ -87,19 +93,21 @@ def __getattr__(self, name):
try:
return convert(value)
except ConfigError as e:
raise ConfigError("Error in .wpmrc section %r option %r: %s" %
raise ConfigError("Error in wpmrc section %r option %r: %s" %
(self.section, name, e))


class Config(object):
"""Contains the user configuration, backed by the .wpmrc file."""
"""Contains the user configuration, backed by the wpmrc file."""
# pylint: disable=too-many-public-methods

config = None

def __init__(self):
Config.config = configparser.ConfigParser()
self.filename = os.path.expanduser("~/.wpmrc")
config_directory = get_config_directory()
self.filename = os.path.join(config_directory, "wpmrc")
os.makedirs(config_directory, exist_ok=True)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't like creating this directory.

I'd rather want get_config_directory to (1) check if you already have ~/.wpmrc and just use that if people already have it there. If not, check that XDG_CONFIG_HOME is set and points to an existing directory, then return that if so.


if os.path.isfile(self.filename):
self.load()
Expand All @@ -113,19 +121,19 @@ def verify(self):
"""Verifies wpmrc values."""
level = self.wpm.confidence_level
if not (0 < level < 1):
raise ConfigError("The .wpmrc confidence level must be within [0, 1>")
raise ConfigError("The wpmrc confidence level must be within [0, 1>")

def load(self):
"""Loads ~/.wpmrc config settings."""
"""Loads wpmrc config settings."""
Config.config.read(self.filename)

def save(self):
"""Saves settings to ~/.wpmrc"""
"""Saves settings to wpmrc"""
with open(self.filename, "wt") as file_obj:
Config.config.write(file_obj)

def add_defaults(self):
"""Adds missing sections and options to your ~/.wpmrc file."""
"""Adds missing sections and options to your wpmrc file."""
for section, values in sorted(DEFAULTS.items()):
if not Config.config.has_section(section):
Config.config.add_section(section)
Expand Down
2 changes: 1 addition & 1 deletion wpm/error.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ class WpmError(RuntimeError):
pass

class ConfigError(WpmError):
"""Incorrect .wpmrc option."""
"""Incorrect wpmrc option."""
pass
3 changes: 2 additions & 1 deletion wpm/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import datetime
import math
import os
from .config import get_config_directory

class Timestamp(object):
"""Methods for dealing with timestamps."""
Expand Down Expand Up @@ -200,7 +201,7 @@ def load(filename=None):
"""Loads stats from a CSV file."""

if filename is None:
filename = os.path.expanduser("~/.wpm.csv")
filename = os.path.join(get_config_directory(), "wpm.csv")

games = collections.defaultdict(list)
current_tag = None
Expand Down