From ae92abad42be2a0fbdf3db4589954a7d32b0cd52 Mon Sep 17 00:00:00 2001 From: Morgan Weetman Date: Fri, 11 Nov 2022 14:45:44 +1100 Subject: [PATCH] Add new configuration options for custom separator --- did/base.py | 16 ++++++++++++++++ did/cli.py | 6 +++--- did/utils.py | 4 ++-- docs/config.rst | 6 +++++- 4 files changed, 26 insertions(+), 6 deletions(-) diff --git a/did/base.py b/did/base.py index f056621c..58437550 100644 --- a/did/base.py +++ b/did/base.py @@ -150,6 +150,22 @@ def width(self): except (NoOptionError, NoSectionError): return MAX_WIDTH + @property + def separator(self): + """ Separator character to use for the report """ + try: + return self.parser.get("general", "separator") + except (NoOptionError, NoSectionError): + return "~" + + @property + def separator_width(self): + """ Number of separator characters to use for the report """ + try: + return int(self.parser.get("general", "separator_width")) + except (NoOptionError, NoSectionError): + return 79 + def sections(self, kind=None): """ Return all sections (optionally of given kind only) """ result = [] diff --git a/did/cli.py b/did/cli.py index c31c3ade..469e6d20 100644 --- a/did/cli.py +++ b/did/cli.py @@ -210,7 +210,7 @@ def main(arguments=None): print(header) team_stats = UserStats(options=options) if options.merge: - utils.header("Total Report") + utils.header("Total Report", did.base.Config().separator_width, did.base.Config().separator) utils.item("Users: {0}".format(len(users)), options=options) # Check individual user stats @@ -218,7 +218,7 @@ def main(arguments=None): if options.merge: utils.item(user, 1, options=options) else: - utils.header(user) + utils.header(user, did.base.Config().separator_width, did.base.Config().separator) user_stats = UserStats(user=user, options=options) user_stats.check() team_stats.merge(user_stats) @@ -227,7 +227,7 @@ def main(arguments=None): # Display merged team report if options.merge or options.total: if options.total: - utils.header("Total Report") + utils.header("Total Report", did.base.Config().separator_width, did.base.Config().separator) team_stats.show() # Return all gathered stats objects diff --git a/did/utils.py b/did/utils.py index d96009cf..13dfa026 100644 --- a/did/utils.py +++ b/did/utils.py @@ -157,9 +157,9 @@ def load_components(*paths, **kwargs): return num_loaded -def header(text): +def header(text, separator_width=79, separator="~"): """ Show text as a header. """ - print("\n{0}\n {1}\n{0}".format(79 * "~", text)) + print("\n{0}\n {1}\n{0}".format(separator_width * separator, text)) def shorted(text, width=79): diff --git a/docs/config.rst b/docs/config.rst index c0d3a9b7..36404f0b 100644 --- a/docs/config.rst +++ b/docs/config.rst @@ -25,12 +25,16 @@ General Minimum config file should contain at least a ``general`` section with an email address which will be used for searching. Option ``width`` specifies the maximum width of the report, ``quarter`` -can be used to choose a different start month of the quarter:: +can be used to choose a different start month of the quarter. +The ``separator`` and ``separator_width`` options control the +character used, and width of the separator between users:: [general] email = Petr Šplíchal width = 79 quarter = 1 + separator = # + separator_width = 20 In order to load additional plugins from your custom locations provide paths to be searched in the ``plugins`` option::