logger best practices
This commit is contained in:
parent
9dff6e88cf
commit
560d73a87c
@ -11,7 +11,7 @@ from urllib.request import urlopen
|
||||
import os
|
||||
import time
|
||||
|
||||
logs = logging.getLogger('inkycal_custom')
|
||||
logs = logging.getLogger(__name__)
|
||||
logs.setLevel(level=logging.INFO)
|
||||
|
||||
# Get the path to the Inkycal folder
|
||||
@ -26,14 +26,14 @@ image_folder = top_level + '/image_folder/'
|
||||
fonts = {}
|
||||
|
||||
for path, dirs, files in os.walk(fonts_location):
|
||||
for filename in files:
|
||||
if filename.endswith('.otf'):
|
||||
name = filename.split('.otf')[0]
|
||||
fonts[name] = os.path.join(path, filename)
|
||||
for _ in files:
|
||||
if _.endswith('.otf'):
|
||||
name = _.split('.otf')[0]
|
||||
fonts[name] = os.path.join(path, _)
|
||||
|
||||
if filename.endswith('.ttf'):
|
||||
name = filename.split('.ttf')[0]
|
||||
fonts[name] = os.path.join(path, filename)
|
||||
if _.endswith('.ttf'):
|
||||
name = _.split('.ttf')[0]
|
||||
fonts[name] = os.path.join(path, _)
|
||||
|
||||
available_fonts = [key for key, values in fonts.items()]
|
||||
|
||||
@ -206,6 +206,7 @@ def text_wrap(text, font=None, max_width=None):
|
||||
Uses a Font object for more accurate calculations.
|
||||
|
||||
Args:
|
||||
- text -> Text as a string
|
||||
- font: A PIL font object which is used to calculate the size.
|
||||
- max_width: int-> a width in pixels defining the maximum width before
|
||||
splitting the text into the next chunk.
|
||||
|
@ -32,8 +32,7 @@ import logging
|
||||
import sys
|
||||
import time
|
||||
|
||||
filename = os.path.basename(__file__).split('.py')[0]
|
||||
logger = logging.getLogger(filename)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class RaspberryPi:
|
||||
|
@ -71,8 +71,7 @@ else:
|
||||
# Show less logging for PIL module
|
||||
logging.getLogger("PIL").setLevel(logging.WARNING)
|
||||
|
||||
filename = os.path.basename(__file__).split('.py')[0]
|
||||
logger = logging.getLogger(filename)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
# TODO: autostart -> supervisor?
|
||||
|
@ -38,8 +38,7 @@ except ImportError:
|
||||
#############################################################################
|
||||
|
||||
# Get the name of this file, set up logging for this filename
|
||||
filename = os.path.basename(__file__).split('.py')[0]
|
||||
logger = logging.getLogger(filename)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
#############################################################################
|
||||
@ -159,7 +158,7 @@ class Simple(inkycal_module):
|
||||
# -----------------------------------------------------------------------#
|
||||
|
||||
# give an OK message
|
||||
print(f'{filename} loaded')
|
||||
print(f'{__name__} loaded')
|
||||
|
||||
#############################################################################
|
||||
# Validation of module specific parameters (optional) #
|
||||
@ -220,7 +219,7 @@ class Simple(inkycal_module):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print('running {0} in standalone mode'.format(filename))
|
||||
print('running {0} in standalone mode'.format(__name__))
|
||||
|
||||
################################################################################
|
||||
# Last steps
|
||||
|
@ -22,8 +22,7 @@ from icalendar import Calendar
|
||||
local timezone. Converting all-day events to local timezone is a problem!
|
||||
"""
|
||||
|
||||
filename = os.path.basename(__file__).split('.py')[0]
|
||||
logger = logging.getLogger(filename)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class iCalendar:
|
||||
@ -203,4 +202,4 @@ class iCalendar:
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {filename} in standalone mode')
|
||||
print(f'running {__name__} in standalone mode')
|
||||
|
@ -15,8 +15,7 @@ import requests
|
||||
|
||||
from PIL import Image
|
||||
|
||||
filename = os.path.basename(__file__).split('.py')[0]
|
||||
logger = logging.getLogger(filename)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Inkyimage:
|
||||
@ -30,7 +29,7 @@ class Inkyimage:
|
||||
self.image = image
|
||||
|
||||
# give an OK message
|
||||
logger.info(f'{filename} loaded')
|
||||
logger.info(f'{__name__} loaded')
|
||||
|
||||
def load(self, path):
|
||||
"""loads an image from a URL or filepath.
|
||||
@ -330,4 +329,4 @@ class Inkyimage:
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {filename} in standalone/debug mode')
|
||||
print(f'running {__name__} in standalone/debug mode')
|
||||
|
@ -11,8 +11,7 @@ from inkycal.custom import *
|
||||
from inkycal.modules.ical_parser import iCalendar
|
||||
from inkycal.modules.template import inkycal_module
|
||||
|
||||
filename = os.path.basename(__file__).split('.py')[0]
|
||||
logger = logging.getLogger(filename)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Agenda(inkycal_module):
|
||||
@ -81,7 +80,7 @@ class Agenda(inkycal_module):
|
||||
self.timezone = get_system_tz()
|
||||
|
||||
# give an OK message
|
||||
print(f'{filename} loaded')
|
||||
print(f'{__name__} loaded')
|
||||
|
||||
def generate_image(self):
|
||||
"""Generate image for this module"""
|
||||
@ -228,4 +227,4 @@ class Agenda(inkycal_module):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {filename} in standalone mode')
|
||||
print(f'running {__name__} in standalone mode')
|
||||
|
@ -10,8 +10,7 @@ from inkycal.custom import *
|
||||
import calendar as cal
|
||||
import arrow
|
||||
|
||||
filename = os.path.basename(__file__).split('.py')[0]
|
||||
logger = logging.getLogger(filename)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Calendar(inkycal_module):
|
||||
@ -86,7 +85,7 @@ class Calendar(inkycal_module):
|
||||
fonts['NotoSans-SemiCondensed'], size=self.fontsize)
|
||||
|
||||
# give an OK message
|
||||
print(f'{filename} loaded')
|
||||
print(f'{__name__} loaded')
|
||||
|
||||
def generate_image(self):
|
||||
"""Generate image for this module"""
|
||||
@ -341,4 +340,4 @@ class Calendar(inkycal_module):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {filename} in standalone mode')
|
||||
print(f'running {__name__} in standalone mode')
|
||||
|
@ -13,8 +13,7 @@ from random import shuffle
|
||||
|
||||
import feedparser
|
||||
|
||||
filename = os.path.basename(__file__).split('.py')[0]
|
||||
logger = logging.getLogger(filename)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Feeds(inkycal_module):
|
||||
@ -63,7 +62,7 @@ class Feeds(inkycal_module):
|
||||
self.shuffle_feeds = config["shuffle_feeds"]
|
||||
|
||||
# give an OK message
|
||||
print(f'{filename} loaded')
|
||||
print(f'{__name__} loaded')
|
||||
|
||||
def _validate(self):
|
||||
"""Validate module-specific parameters"""
|
||||
@ -155,4 +154,4 @@ class Feeds(inkycal_module):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {filename} in standalone/debug mode')
|
||||
print(f'running {__name__} in standalone/debug mode')
|
||||
|
@ -10,8 +10,7 @@ from inkycal.custom import *
|
||||
|
||||
from inkycal.modules.inky_image import Inkyimage as Images
|
||||
|
||||
filename = os.path.basename(__file__).split('.py')[0]
|
||||
logger = logging.getLogger(filename)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Inkyimage(inkycal_module):
|
||||
@ -66,7 +65,7 @@ class Inkyimage(inkycal_module):
|
||||
self.orientation = config['orientation']
|
||||
|
||||
# give an OK message
|
||||
print(f'{filename} loaded')
|
||||
print(f'{__name__} loaded')
|
||||
|
||||
def generate_image(self):
|
||||
"""Generate image for this module"""
|
||||
@ -105,4 +104,4 @@ class Inkyimage(inkycal_module):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {filename} in standalone/debug mode')
|
||||
print(f'running {__name__} in standalone/debug mode')
|
||||
|
@ -14,8 +14,7 @@ import requests
|
||||
# Show less logging for request module
|
||||
logging.getLogger("urllib3").setLevel(logging.WARNING)
|
||||
|
||||
filename = os.path.basename(__file__).split('.py')[0]
|
||||
logger = logging.getLogger(filename)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Jokes(inkycal_module):
|
||||
@ -33,7 +32,7 @@ class Jokes(inkycal_module):
|
||||
config = config['config']
|
||||
|
||||
# give an OK message
|
||||
print(f'{filename} loaded')
|
||||
print(f'{__name__} loaded')
|
||||
|
||||
def generate_image(self):
|
||||
"""Generate image for this module"""
|
||||
@ -101,4 +100,4 @@ class Jokes(inkycal_module):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {filename} in standalone/debug mode')
|
||||
print(f'running {__name__} in standalone/debug mode')
|
||||
|
@ -13,8 +13,7 @@ from inkycal.custom import *
|
||||
|
||||
from inkycal.modules.inky_image import Inkyimage as Images
|
||||
|
||||
filename = os.path.basename(__file__).split('.py')[0]
|
||||
logger = logging.getLogger(filename)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Inkyserver(inkycal_module):
|
||||
@ -73,7 +72,7 @@ class Inkyserver(inkycal_module):
|
||||
self.path_body = config['path_body']
|
||||
|
||||
# give an OK message
|
||||
print(f'{filename} loaded')
|
||||
print(f'{__name__} loaded')
|
||||
|
||||
def generate_image(self):
|
||||
"""Generate image for this module"""
|
||||
@ -122,7 +121,7 @@ class Inkyserver(inkycal_module):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {filename} in standalone/debug mode')
|
||||
print(f'running {__name__} in standalone/debug mode')
|
||||
|
||||
## 'https://inkycal.robertsirre.nl/panel/calendar/{model}?width={width}&height={height}'
|
||||
##path = path.replace('{model}', model).replace('{width}',str(display_width)).replace('{height}',str(display_height))
|
||||
|
@ -12,8 +12,7 @@ from inkycal.custom import *
|
||||
# PIL has a class named Image, use alias for Inkyimage -> Images
|
||||
from inkycal.modules.inky_image import Inkyimage as Images
|
||||
|
||||
filename = os.path.basename(__file__).split('.py')[0]
|
||||
logger = logging.getLogger(filename)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Slideshow(inkycal_module):
|
||||
@ -80,7 +79,7 @@ class Slideshow(inkycal_module):
|
||||
self._first_run = True
|
||||
|
||||
# give an OK message
|
||||
print(f'{filename} loaded')
|
||||
print(f'{__name__} loaded')
|
||||
|
||||
def generate_image(self):
|
||||
"""Generate image for this module"""
|
||||
@ -132,4 +131,4 @@ class Slideshow(inkycal_module):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {filename} in standalone/debug mode')
|
||||
print(f'running {__name__} in standalone/debug mode')
|
||||
|
@ -8,13 +8,13 @@ Copyright by aceisace
|
||||
from inkycal.modules.template import inkycal_module
|
||||
from inkycal.custom import *
|
||||
|
||||
import math, decimal
|
||||
import math
|
||||
import decimal
|
||||
import arrow
|
||||
|
||||
from pyowm.owm import OWM
|
||||
|
||||
filename = os.path.basename(__file__).split('.py')[0]
|
||||
logger = logging.getLogger(filename)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class Weather(inkycal_module):
|
||||
@ -102,7 +102,7 @@ class Weather(inkycal_module):
|
||||
fonts['weathericons-regular-webfont'], size=self.fontsize)
|
||||
|
||||
# give an OK message
|
||||
print(f"{filename} loaded")
|
||||
print(f"{__name__} loaded")
|
||||
|
||||
def generate_image(self):
|
||||
"""Generate image for this module"""
|
||||
@ -505,4 +505,4 @@ class Weather(inkycal_module):
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
print(f'running {filename} in standalone mode')
|
||||
print(f'running {__name__} in standalone mode')
|
||||
|
0
inkycal/tests/__init__.py
Normal file
0
inkycal/tests/__init__.py
Normal file
@ -80,7 +80,7 @@ class module_test(unittest.TestCase):
|
||||
module = Module(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
print('OK')
|
||||
if use_preview == True and environment == 'Raspberry':
|
||||
if use_preview and environment == 'Raspberry':
|
||||
preview(merge(im_black, im_colour))
|
||||
|
||||
|
||||
|
@ -181,7 +181,7 @@ class module_test(unittest.TestCase):
|
||||
module = Module(test)
|
||||
im_black, im_colour = module.generate_image()
|
||||
print('OK')
|
||||
if use_preview == True and environment == 'Raspberry':
|
||||
if use_preview and environment == 'Raspberry':
|
||||
preview(merge(im_black, im_colour))
|
||||
else:
|
||||
print('No key given, omitted testing')
|
||||
|
Loading…
Reference in New Issue
Block a user