Skip to content

Commit 4cb92a8

Browse files
committed
Removed usage of log facility.
1 parent df36ce3 commit 4cb92a8

4 files changed

Lines changed: 3 additions & 67 deletions

File tree

scrolltext/config.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
"""
44
from pathlib import Path
55
import configparser
6-
import logging
76
import sys
87

98

@@ -14,9 +13,6 @@
1413
SCROLL_SPEEDS = [.25, .20, .18, .15, .125, .1, .09, .08, .075, .07, .0675]
1514

1615

17-
log = logging.getLogger(__name__)
18-
19-
2016
initial_config = {
2117
"main": {"action": "linescroller", "endless": "0"},
2218
"cursestext": {"box": "1"},
@@ -55,7 +51,6 @@ def init_config(write_config):
5551

5652
cfg, really_write = _read_config(config_path)
5753
if write_config and really_write:
58-
log.info("Writing a new config '%s' using defaults", config_path)
5954
_write_config(cfg, config_path)
6055
return cfg
6156

@@ -66,15 +61,11 @@ def _read_config(config_path):
6661
"""
6762
really_write = False
6863
cfg = configparser.ConfigParser(default_section="main")
69-
log.debug("try read config path: '%s'", config_path)
7064
read_config_files = cfg.read(config_path)
7165

7266
if not read_config_files:
7367
really_write = True
74-
log.info("No config file found")
7568
cfg.update(initial_config)
76-
else:
77-
log.debug("config read: '%s'", read_config_files)
7869
_validate(cfg)
7970
return cfg, really_write
8071

@@ -95,19 +86,15 @@ def _validate(cfg):
9586
raise NameError("Section '" + section + "' is missing in config")
9687
_validate_section_entries(cfg, section, entries)
9788

98-
log.debug(cfg["main"]["action"])
99-
10089
# NOTE: allow for several "scrolltext.text %d" sections
10190
# for index in range(2, 9):
10291
# scrolltext_section = "scrolltext.text " + str(index)
10392
# if not scrolltext_section in cfg:
10493
# cfg["main"]["max_index"] = str(index - 1)
105-
# log.debug("max scrolltext.text %d", cfg["main"]["max_index"])
10694
# break
10795
_fix_scrolltext_section(cfg, "scrolltext.text 1")
10896
if "cursestext" not in cfg:
10997
cfg["cursestext"] = {"box": "1"}
110-
log.debug("cursestext draw box: %s", cfg["cursestext"].getboolean("box"))
11198

11299

113100
def _validate_section_entries(cfg, section, entries):
@@ -124,4 +111,3 @@ def _fix_scrolltext_section(cfg, section_name):
124111
text_lines = cfg[section_name]["text"]
125112
text = "".join(text_lines.split("\n"))
126113
cfg[section_name]["text"] = text
127-
log.debug(text)

scrolltext/cursestext.py

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,12 @@
33
"""
44
from curses import wrapper, error
55
import curses
6-
import logging
76
from .utils import CharacterScroller, IS_WINDOWS, TermSize
87

98

109
QUIT_CHARACTERS = ["\x1B", "Q", "q"]
1110

1211

13-
log = logging.getLogger(__name__)
14-
15-
1612
def curses_scroller(win, cfg):
1713
"""
1814
Curses-main: render a text in a side-scrolling manner, using curses.
@@ -47,7 +43,6 @@ def do_textloop(win, cfg, term_size, scroller, min_scroll_line):
4743
This method loops over the scrolled text
4844
"""
4945
box = cfg["cursestext"].getboolean("box")
50-
term_too_small_printed = False
5146
for text in scroller:
5247
win_text = text
5348
# hack: When writing to the last line we prevent adding an immediate newline and thus
@@ -56,13 +51,7 @@ def do_textloop(win, cfg, term_size, scroller, min_scroll_line):
5651
win_text = text[:-1]
5752
if scroller.line >= min_scroll_line:
5853
_addstr_wrapper(win, scroller.line, (1 if box else 0), win_text)
59-
term_too_small_printed = False
6054
win.redrawwin()
61-
else:
62-
if not term_too_small_printed:
63-
log.debug("Terminal is too small cols: %d rows: %d",
64-
term_size.get_cols(), term_size.get_rows())
65-
term_too_small_printed = True
6655
character = get_char(win)
6756
if character == curses.KEY_EXIT:
6857
return
@@ -89,11 +78,8 @@ def get_char(win):
8978
:returns: curses.KEY_EXIT, if a quit character is entered, the current character, otherwise.
9079
:rtype: int
9180
"""
92-
log.debug("getch")
9381
character = None
9482
character = win.getch(0, 0)
95-
if character != -1:
96-
log.debug("got key (%d) type %s", character, type(character))
9783
if character != -1 and (chr(character) in QUIT_CHARACTERS):
9884
return curses.KEY_EXIT
9985
return character
@@ -104,7 +90,6 @@ def update_term_size(win, box, term_size):
10490
Updates TermSize object.
10591
"""
10692
winsize = win.getmaxyx()
107-
log.debug("win dimensions: (columns, rows) (%d, %d)", winsize[1], winsize[0])
10893
available_rows = winsize[0] - (2 if box else 1)
10994
available_columns = winsize[1] - (2 if box else 0)
11095
term_size.set_size(available_columns, available_rows)
@@ -125,19 +110,16 @@ def draw_items(win, box, min_scroll_line, scroller, term_size):
125110

126111

127112
def _addstr_wrapper(win, row, column, text):
128-
log.debug("addstr to line %d", row)
129113
try:
130114
win.addstr(row, column, text)
131115
except: # pylint: disable=W0702 (bare-except)
132-
log.exception("Error in addstr")
116+
pass
133117

134118

135119
def work(cfg):
136120
"""Main usese curses.wrapper. See curses doc for details.
137121
"""
138122
try: # noqa: C901 ignoring 'TryExcept 42' is too complex - fix later
139123
wrapper(curses_scroller, cfg)
140-
except error as ex:
141-
log.exception(ex)
142-
finally:
143-
log.debug("end")
124+
except error:
125+
pass

scrolltext/linescroller.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
A simple side scrolling text application.
33
"""
4-
import logging
54
import shutil
65
from time import sleep
76
from .utils import CLEAR, HOME, IS_WINDOWS, UP_ONE_ROW, CharacterScroller, TermSize
@@ -11,7 +10,6 @@
1110

1211

1312
last_term_rows = -1 # pylint: disable=C0103 (invalid-name)
14-
log = logging.getLogger(__name__)
1513

1614

1715
def linescroller(cfg):
@@ -70,8 +68,6 @@ def _check_input(getch):
7068
Use getchtimeout to get a character. If "Q" or "q" is given, then it raises SystemExit
7169
"""
7270
character = getch.getch(timeout=.1)
73-
if isinstance(character, int) == int:
74-
log.debug("Got key '%d'", character)
7571
if character is not None and character in ["\033", "\x1b", "", "\r", "", " ", "Q", "q"]:
7672
raise RuntimeError()
7773

scrolltext/utils.py

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
"""
22
Utilities for line-based text scrollers.
33
"""
4-
import logging
54
from os import getenv
65
from time import time
76
from scrolltext.config import get_speedsec_float, init_config
@@ -13,9 +12,6 @@
1312
UP_ONE_ROW = "\033[1A"
1413

1514

16-
log = logging.getLogger(__name__)
17-
18-
1915
def parse_int(var):
2016
"""
2117
Calls int on var, ignores TypeError and ValueError.
@@ -40,7 +36,6 @@ def init_utils(write_config):
4036
"""
4137
cfg = init_config(write_config)
4238
_override_from_env(cfg)
43-
_init_logging(cfg)
4439
return cfg
4540

4641

@@ -63,18 +58,9 @@ def get_linenum(scroll_line_str, min_row, max_row):
6358
line = max_row + line + 1
6459
line = max(line, min_row)
6560
line = min(line, max_row)
66-
log.debug("scroll_line_str: %s min: %d max: %d line:%d",
67-
scroll_line_str, min_row, max_row, line)
6861
return line
6962

7063

71-
def _init_logging(cfg):
72-
verbose = cfg["main"].getboolean("verbose")
73-
if verbose:
74-
# logging.basicConfig(filename="cursesscroller.log", filemode="w", level=logging.DEBUG)
75-
logging.basicConfig(filename="scrolltext.log", filemode="w", level=logging.DEBUG)
76-
77-
7864
def _override_from_env(cfg):
7965
_override_verbose(cfg) # x x x todo: recap (all of those ...)
8066
_override_scroll_box(cfg)
@@ -87,43 +73,37 @@ def _override_from_env(cfg):
8773
def _override_verbose(cfg):
8874
verbose = getenv("VERBOSE") == "1"
8975
if verbose:
90-
log.debug("Using env-var 'VERBOSE'")
9176
cfg["main"]["verbose"] = "1"
9277

9378

9479
def _override_scroll_box(cfg):
9580
scroll_direction = getenv("SCROLL_BOX") == "1"
9681
if scroll_direction:
97-
log.debug("Using env-var 'SCROLL_BOX'")
9882
cfg["cursestext"]["box"] = "1"
9983

10084

10185
def _override_scroll_direction(cfg):
10286
scroll_direction = getenv("SCROLL_DIRECTION") == "1"
10387
if scroll_direction:
104-
log.debug("Using env-var 'SCROLL_DIRECTION'")
10588
cfg["scrolltext.text 1"]["direction"] = "1"
10689

10790

10891
def _override_scroll_text(cfg):
10992
scroll_text = getenv("SCROLL_TEXT")
11093
if scroll_text:
111-
log.debug("Using env-var 'SCROLL_TEXT'")
11294
cfg["scrolltext.text 1"]["text"] = scroll_text
11395

11496

11597
def _override_scroll_line(cfg):
11698
scroll_line_str = getenv("SCROLL_LINE")
11799
if scroll_line_str:
118-
log.debug("Using env-var 'SCROLL_LINE_STR'")
119100
cfg["scrolltext.text 1"]["line"] = scroll_line_str
120101

121102

122103
def _override_scroll_speed(cfg):
123104
scroll_speed = getenv("SCROLL_SPEED")
124105
if scroll_speed:
125106
scroll_speed_index = parse_int(getenv("SCROLL_SPEED"))
126-
log.debug("Using env-var 'SCROLL_SPEED' with '%s'", scroll_speed)
127107
cfg["scrolltext.text 1"]["speed"] = str(scroll_speed_index)
128108

129109

@@ -154,17 +134,13 @@ def set_size(self, cols, rows):
154134
if self.term_rows != rows:
155135
self.term_rows = rows
156136
self.resized = True
157-
if self.resized:
158-
log.debug("TermSize columns: %d rows: %d", self.term_columns, self.term_rows)
159137

160138
def is_resized(self):
161139
"""
162140
Returns true, when the terminal window changed its size.
163141
"""
164142
resized = self.resized
165143
self.resized = False
166-
if resized:
167-
log.debug("TermSize resized")
168144
return resized
169145

170146
def get_cols(self):
@@ -225,12 +201,8 @@ def _resized(self, **argv):
225201
self.min_scroll_line, self.term_size.get_rows())
226202
if self.term_size.get_cols() != self.visible_text_length:
227203
self.visible_text_length = self.term_size.get_cols()
228-
log.debug("visibile_text_length: %d", self.visible_text_length)
229204
self.num_blanks = argv["blanks"] if "blanks" in argv else self.visible_text_length
230205
self._update_complete_text()
231-
log.debug("_resized line: %d columnns: %d rows: %d text-length %d",
232-
self.line, self.term_size.get_cols(),
233-
self.term_size.get_rows(), self.visible_text_length)
234206

235207
def _update_complete_text(self):
236208
blanks = self.num_blanks * " "

0 commit comments

Comments
 (0)