Browse Source

lint: logging lazy interpolation

boyska 7 years ago
parent
commit
8e36d293df

+ 1 - 1
larigira/audiogen_mostrecent.py

@@ -17,7 +17,7 @@ def recent_choose(paths, howmany, minepoch):
     found_files = {}
     for path in paths:
         if not os.path.exists(path):
-            logging.warn("Can't find requested path:,s" % path)
+            logging.warn("Can't find requested path: %s", path)
             continue
         if os.path.isfile(path):
             found_files[path] = get_mtime(path)

+ 1 - 1
larigira/audiogen_mpdrandom.py

@@ -16,7 +16,7 @@ def generate_by_artist(spec):
     c.connect(conf['MPD_HOST'], conf['MPD_PORT'])
 
     artists = c.list('artist')
-    log.debug("got %d artists" % len(artists))
+    log.debug("got %d artists", len(artists))
     if not artists:
         raise ValueError("no artists in your mpd database")
     for _ in range(spec['howmany']):

+ 1 - 1
larigira/audiogen_randomdir.py

@@ -23,7 +23,7 @@ def generate(spec):
     found_files = set()
     for path in spec['paths']:
         if not os.path.exists(path):
-            logging.warn("Can't find requested path: %s" % path)
+            logging.warn("Can't find requested path: %s", path)
             continue
         if os.path.isfile(path):
             found_files.add(path)

+ 1 - 1
larigira/audiogen_script.py

@@ -52,7 +52,7 @@ def generate(spec):
                          % (spec['name'], os.stat(scriptpath).st_uid,
                             os.getuid()))
     try:
-        log.info('Going to run {}'.format([scriptpath] + args))
+        log.info('Going to run %s', [scriptpath] + args)
         env = dict(
             HOME=os.environ['HOME'],
             PATH=os.environ['PATH'],

+ 16 - 15
larigira/event.py

@@ -106,7 +106,7 @@ class Monitor(ParentedLet):
             when = next(timegenerate(timespec, now=now))
         except:
             logging.exception("Could not generate "
-                              "an alarm from timespec {}".format(timespec))
+                              "an alarm from timespec %s", timespec)
         if when is None:
             # expired
             return None
@@ -131,16 +131,17 @@ class Monitor(ParentedLet):
             # but it is "tricky"; any small delay would cause the event to be
             # missed
             if delta is not None and delta <= 2*self.conf['EVENT_TICK_SECS']:
-                self.log.debug('Scheduling event {} ({}s) => {}'
-                               .format(alarm.get('nick', alarm.eid),
-                                       delta,
-                                       [a.get('nick', a.eid) for a in actions]
-                                       ))
+                self.log.debug('Scheduling event %s (%ds) => %s',
+                               alarm.get('nick', alarm.eid),
+                               delta if delta is not None else -1,
+                               [a.get('nick', a.eid) for a in actions]
+                               )
                 self.schedule(alarm, actions, delta)
             else:
-                self.log.debug('Skipping event {}, too far ({}s)'
-                               .format(alarm.get('nick', alarm.eid),
-                                       delta))
+                self.log.debug('Skipping event %s too far (%ds)',
+                               alarm.get('nick', alarm.eid),
+                               delta if delta is not None else -1,
+                               )
 
     def schedule(self, timespec, audiospecs, delta=None):
         '''
@@ -173,16 +174,16 @@ class Monitor(ParentedLet):
         if timespec.eid in self.running:
             del self.running[timespec.eid]
         else:
-            self.log.warn('Timespec {} completed but not in running '
-                          'registry; this is most likely a bug'.
-                          format(timespec.get('nick', timespec.eid)))
+            self.log.warn('Timespec %s completed but not in running '
+                          'registry; this is most likely a bug',
+                          timespec.get('nick', timespec.eid))
         uris = []
         for audiospec in audiospecs:
             try:
                 uris.extend(audiogenerate(audiospec))
             except:
-                self.log.error('audiogenerate for {} failed'
-                               .format(audiospec))
+                self.log.error('audiogenerate for %s failed',
+                               str(audiospec))
         self.send_to_parent('uris_enqueue',
                             dict(uris=uris,
                                  timespec=timespec,
@@ -198,4 +199,4 @@ class Monitor(ParentedLet):
             if kind in ('forcetick', 'timer'):
                 gevent.spawn(self.on_tick)
             else:
-                self.log.warning("Unknown message: %s" % str(value))
+                self.log.warning("Unknown message: %s", str(value))

+ 13 - 12
larigira/mpc.py

@@ -41,8 +41,8 @@ class MpcWatcher(ParentedLet):
                 status = self.client.idle()[0]
             except (mpd.ConnectionError, ConnectionRefusedError,
                     FileNotFoundError) as exc:
-                self.log.warning('Connection to MPD failed ({}: {})'.
-                                 format(exc.__class__.__name__, exc))
+                self.log.warning('Connection to MPD failed (%s: %s)',
+                                 exc.__class__.__name__, exc)
                 self.client = None
                 first_after_connection = True
                 gevent.sleep(5)
@@ -67,8 +67,8 @@ class Player:
             mpd_client.connect(self.conf['MPD_HOST'], self.conf['MPD_PORT'])
         except (mpd.ConnectionError, ConnectionRefusedError,
                 FileNotFoundError) as exc:
-            self.log.warning('Connection to MPD failed ({}: {})'.
-                             format(exc.__class__.__name__, exc))
+            self.log.warning('Connection to MPD failed (%s: %s)',
+                             exc.__class__.__name__, exc)
             raise gevent.GreenletExit()
         return mpd_client
 
@@ -116,22 +116,23 @@ class Player:
         assert 'uris' in songs
         spec = [aspec.get('nick', aspec.eid) for aspec in songs['audiospecs']]
         if not self.events_enabled:
-            self.log.debug('Ignoring <{}> (events disabled)'.format(
-                ','.join(spec)
-            ))
+            self.log.debug('Ignoring <%s> (events disabled)',
+                           ','.join(spec)
+                           )
             return
         mpd_client = self._get_mpd()
         for uri in reversed(songs['uris']):
             assert type(uri) is str
-            self.log.info('Adding {} to playlist (from <{}>:{}={})'.
-                          format(uri, songs['timespec'].get('nick', ''),
-                                 songs['aids'], spec))
+            self.log.info('Adding %s to playlist (from <%s>:%s=%s)',
+                          uri,
+                          songs['timespec'].get('nick', ''),
+                          songs['aids'], spec)
             insert_pos = 0 if len(mpd_client.playlistid()) == 0 else \
                 int(mpd_client.currentsong().get('pos', 0)) + 1
             try:
                 mpd_client.addid(uri, insert_pos)
             except mpd.CommandError:
-                self.log.exception("Cannot insert song {}".format(uri))
+                self.log.exception("Cannot insert song %s", uri)
             self.tmpcleaner.watch(uri.strip())
 
 
@@ -190,4 +191,4 @@ class Controller(gevent.Greenlet):
                 self.monitor.q.put(dict(kind='forcetick'))
                 gevent.Greenlet.spawn(self.player.check_playlist)
             else:
-                self.log.warning("Unknown message: %s" % str(value))
+                self.log.warning("Unknown message: %s", str(value))

+ 1 - 1
larigira/timeform_base.py

@@ -78,7 +78,7 @@ class FrequencyAlarmForm(Form):
             self.weekdays.data = list('1234567')
         self.interval.data = timespec['interval']
 
-    def validate_interval(form, field):
+    def validate_interval(self, field):
         try:
             int(field.data)
         except ValueError:

+ 2 - 2
larigira/unused.py

@@ -50,7 +50,7 @@ class UnusedCleaner:
         if 'TMPDIR' in self.conf and self.conf['TMPDIR'] \
            and commonpath([self.conf['TMPDIR'], fpath]) != \
            normpath(self.conf['TMPDIR']):
-            self.log.info('Not watching file {}: not in TMPDIR'.format(fpath))
+            self.log.info('Not watching file %s: not in TMPDIR', fpath)
             return
         if not os.path.exists(fpath):
             self.log.warning('a path that does not exist is being monitored')
@@ -63,7 +63,7 @@ class UnusedCleaner:
                              if song['file'].startswith('/')}
         for fpath in self.waiting_removal_files - files_in_playlist:
             # we can remove it!
-            self.log.debug('removing unused: {}'.format(fpath))
+            self.log.debug('removing unused: %s', fpath)
             self.waiting_removal_files.remove(fpath)
             if os.path.exists(fpath):
                 os.unlink(fpath)