Skip to content

Commit

Permalink
Move stats classes into a separate module
Browse files Browse the repository at this point in the history
  • Loading branch information
psss committed Sep 10, 2015
1 parent 3efe777 commit d8af594
Show file tree
Hide file tree
Showing 23 changed files with 576 additions and 520 deletions.
375 changes: 223 additions & 152 deletions did/base.py

Large diffs are not rendered by default.

44 changes: 23 additions & 21 deletions did/cli.py
Expand Up @@ -16,8 +16,10 @@
import ConfigParser
from dateutil.relativedelta import relativedelta as delta

import did.base
import did.utils as utils
from did.base import UserStats
from did.stats import UserStats
from did.base import ConfigError, ReportError


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -58,7 +60,7 @@ def __init__(self, arguments=None):
"--format", default="text",
help="Output style, possible values: text (default) or wiki")
group.add_option(
"--width", default=utils.Config().width, type="int",
"--width", default=did.base.Config().width, type="int",
help="Maximum width of the report output (default: %default)")
group.add_option(
"--brief", action="store_true",
Expand Down Expand Up @@ -88,7 +90,7 @@ def parse(self, arguments=None):

# Enable debugging output
if opt.debug:
utils.logging.set(utils.LOG_DEBUG)
utils.Logging.set(utils.LOG_DEBUG)

# Enable --all if no particular stat or group selected
opt.all = not any([
Expand All @@ -98,15 +100,15 @@ def parse(self, arguments=None):

# Detect email addresses and split them on comma
if not opt.emails:
opt.emails = utils.Config().email
opt.emails = did.base.Config().email
opt.emails = utils.split(opt.emails, separator=re.compile(r"\s*,\s*"))

# Time period handling
if opt.since is None and opt.until is None:
opt.since, opt.until, period = self.time_period(arg)
else:
opt.since = utils.Date(opt.since or "1993-01-01")
opt.until = utils.Date(opt.until or "today")
opt.since = did.base.Date(opt.since or "1993-01-01")
opt.until = did.base.Date(opt.until or "today")
# Make the 'until' limit inclusive
opt.until.date += delta(days=1)
period = "given date range"
Expand All @@ -128,37 +130,37 @@ def time_period(arg):
""" Detect desired time period for the argument """
since, until, period = None, None, None
if "today" in arg:
since = utils.Date("today")
until = utils.Date("today")
since = did.base.Date("today")
until = did.base.Date("today")
until.date += delta(days=1)
period = "today"
elif "year" in arg:
if "last" in arg:
since, until = utils.Date.last_year()
since, until = did.base.Date.last_year()
period = "the last fiscal year"
else:
since, until = utils.Date.this_year()
since, until = did.base.Date.this_year()
period = "this fiscal year"
elif "quarter" in arg:
if "last" in arg:
since, until = utils.Date.last_quarter()
since, until = did.base.Date.last_quarter()
period = "the last quarter"
else:
since, until = utils.Date.this_quarter()
since, until = did.base.Date.this_quarter()
period = "this quarter"
elif "month" in arg:
if "last" in arg:
since, until = utils.Date.last_month()
since, until = did.base.Date.last_month()
period = "the last month"
else:
since, until = utils.Date.this_month()
since, until = did.base.Date.this_month()
period = "this month"
else:
if "last" in arg:
since, until = utils.Date.last_week()
since, until = did.base.Date.last_week()
period = "the last week"
else:
since, until = utils.Date.this_week()
since, until = did.base.Date.this_week()
period = "this week"
return since, until, period

Expand All @@ -184,9 +186,9 @@ def main(arguments=None):
gathered_stats = []

# Check for user email addresses (command line or config)
users = [utils.User(email=email) for email in options.emails]
users = [did.base.User(email=email) for email in options.emails]
if not users:
raise utils.ConfigError("No user email provided")
raise ConfigError("No user email provided")

# Prepare team stats object for data merging
team_stats = UserStats(options=options)
Expand Down Expand Up @@ -214,7 +216,7 @@ def main(arguments=None):
# Return all gathered stats objects
return gathered_stats, team_stats

except (utils.ConfigError, utils.ReportError) as error:
except (ConfigError, ReportError) as error:
utils.log.error(error)
sys.exit(1)

Expand All @@ -226,8 +228,8 @@ def main(arguments=None):
utils.log.error(error)
utils.log.error(
"No email provided on the command line or in the config file")
utils.info(
"Create at least a minimum config file {0}:".format(utils.CONFIG))
utils.info("Create at least a minimum config file {0}:".format(
did.base.CONFIG))
from getpass import getuser
utils.info(
'[general]\nemail = "My Name" <{0}@domain.com>'.format(getuser()))
Expand Down
5 changes: 3 additions & 2 deletions did/plugins/__init__.py
Expand Up @@ -26,7 +26,9 @@
import sys
import types

from did.utils import Config, ConfigError, log
from did.utils import log
from did.base import Config, ConfigError
from did.stats import StatsGroup, EmptyStatsGroup

# Self reference and file path to this module
PLUGINS = sys.modules[__name__]
Expand Down Expand Up @@ -67,7 +69,6 @@ def detect():
as well as the option used to enable those particular stats.
"""
# Detect classes inherited from StatsGroup and return them sorted
from did.base import StatsGroup, EmptyStatsGroup
stats = []
for plugin in load():
module = getattr(PLUGINS, plugin)
Expand Down
5 changes: 3 additions & 2 deletions did/plugins/bugzilla.py
Expand Up @@ -32,8 +32,9 @@
import bugzilla
import xmlrpclib

from did.base import Stats, StatsGroup
from did.utils import Config, log, pretty, ReportError
from did.base import Config, ReportError
from did.stats import Stats, StatsGroup
from did.utils import log, pretty


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion did/plugins/footer.py
Expand Up @@ -11,7 +11,7 @@
status = Status: Green | Yellow | Orange | Red
"""

from did.base import EmptyStatsGroup
from did.stats import EmptyStatsGroup


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
8 changes: 5 additions & 3 deletions did/plugins/gerrit.py
Expand Up @@ -10,12 +10,14 @@
prefix = GR
"""

from datetime import datetime
import json
import urllib
import urlparse
from did.base import Stats, StatsGroup
from did.utils import Config, ReportError, log, pretty, TODAY
from datetime import datetime

from did.utils import log, pretty
from did.stats import Stats, StatsGroup
from did.base import Config, ReportError, TODAY


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
6 changes: 4 additions & 2 deletions did/plugins/git.py
Expand Up @@ -18,8 +18,10 @@
import os
import re
import subprocess
from did.base import Stats, StatsGroup
from did.utils import Config, item, log, pretty, ReportError

from did.base import Config, ReportError
from did.utils import item, log, pretty
from did.stats import Stats, StatsGroup


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
2 changes: 1 addition & 1 deletion did/plugins/header.py
Expand Up @@ -10,7 +10,7 @@
joy = Joy of the week ;-)
"""

from did.base import EmptyStatsGroup
from did.stats import EmptyStatsGroup


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
5 changes: 3 additions & 2 deletions did/plugins/items.py
Expand Up @@ -12,8 +12,9 @@
item3 = Project Three
"""

from did.base import Stats, StatsGroup
from did.utils import Config, item
from did.utils import item
from did.base import Config
from did.stats import Stats, StatsGroup


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
9 changes: 5 additions & 4 deletions did/plugins/jira.py
Expand Up @@ -15,12 +15,13 @@
import json
import urllib
import urllib2
import urllib2_kerberos
import dateutil.parser
import cookielib
import dateutil.parser
import urllib2_kerberos

from did.base import Stats, StatsGroup
from did.utils import Config, log, pretty, listed, ReportError
from did.utils import log, pretty, listed
from did.base import Config, ReportError
from did.stats import Stats, StatsGroup

# Default identifier width
DEFAULT_WIDTH = 4
Expand Down
2 changes: 1 addition & 1 deletion did/plugins/nitrate.py
Expand Up @@ -10,7 +10,7 @@

from __future__ import absolute_import

from did.base import Stats, StatsGroup
from did.stats import Stats, StatsGroup
from did.utils import log

TEST_CASE_COPY_TAG = "TestCaseCopy"
Expand Down
5 changes: 3 additions & 2 deletions did/plugins/rt.py
Expand Up @@ -17,8 +17,9 @@
import urlparse
import kerberos

from did.base import Stats, StatsGroup
from did.utils import log, pretty, ReportError, Config
from did.utils import log, pretty
from did.base import ReportError, Config
from did.stats import Stats, StatsGroup


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
5 changes: 3 additions & 2 deletions did/plugins/trac.py
Expand Up @@ -13,8 +13,9 @@
import re
import xmlrpclib

from did.base import Stats, StatsGroup
from did.utils import Config, ReportError, log, pretty
from did.utils import log, pretty
from did.base import Config, ReportError
from did.stats import Stats, StatsGroup

INTERESTING_RESOLUTIONS = ["canceled"]
MAX_TICKETS = 1000000
Expand Down
11 changes: 9 additions & 2 deletions did/plugins/wiki.py
Expand Up @@ -10,8 +10,15 @@
"""

import xmlrpclib
from did.base import Stats, StatsGroup
from did.utils import Config, item

from did.utils import item
from did.base import Config
from did.stats import Stats, StatsGroup


# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Wiki Stats
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~rom did.utils import item

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Wiki Stats
Expand Down

0 comments on commit d8af594

Please sign in to comment.