Browse Source

fix submodule import & linter warnings

Fabian Peter Hammerle 1 month ago
parent
commit
d6894be38c

+ 1 - 0
.gitignore

@@ -1 +1,2 @@
+dist/
 tags

+ 0 - 0
symuid/import_library/__init__.py


+ 4 - 9
symuid/import_library/cmus_cache.py

@@ -34,13 +34,13 @@ def symuid_import_cmus(library_id, cache_path):
                         register_dt=datetime_utc_now(),
                         count=cmus_track.play_count,
                     ),
-                    tag_set_cb=lambda tr, tag:
-                    print('{!r}: set tag {!r}'.format(tr.path, tag)),
+                    tag_set_cb=lambda track, tag:
+                    print('{!r}: set tag {!r}'.format(track.path, tag)),
                 )
 
 
-def _init_argparser():
-    argparser = argparse.ArgumentParser(description=None)
+def _main():
+    argparser = argparse.ArgumentParser(description="Import play counts from cmus' cache")
     argparser.add_argument('library_id')
     argparser.add_argument(
         'cache_path',
@@ -48,10 +48,5 @@ def _init_argparser():
         default=os.path.expanduser('~/.config/cmus/cache'),
         help='(default: %(default)r)',
     )
-    return argparser
-
-
-def _main():
-    argparser = _init_argparser()
     args = argparser.parse_args()
     symuid_import_cmus(**vars(args))

+ 4 - 9
symuid/import_library/itunes_xml.py

@@ -25,7 +25,7 @@ def import_itunes_xml_library(xml_library_path, path_regex_sub):
                 symuid_track.register_play_count(
                     symuid.PlayCount(
                         player='itunes',
-                        library_id=lib.id,
+                        library_id=lib.library_id,
                         register_dt=itunes_track.last_play_dt,
                         count=itunes_track.play_count,
                     ),
@@ -34,8 +34,8 @@ def import_itunes_xml_library(xml_library_path, path_regex_sub):
                 )
 
 
-def _init_argparser():
-    argparser = argparse.ArgumentParser(description=None)
+def _main():
+    argparser = argparse.ArgumentParser(description='Import play counts from iTunes XML Library')
     argparser.add_argument('xml_library_path')
     argparser.add_argument(
         '--path-regex-sub',
@@ -43,12 +43,7 @@ def _init_argparser():
         action='append',
         metavar=('regex', 'replacement'),
         default=[],
-        help='(default: %(default)r)',
+        help='(default: no substitution)',
     )
-    return argparser
-
-
-def _main():
-    argparser = _init_argparser()
     args = argparser.parse_args()
     import_itunes_xml_library(**vars(args))

+ 0 - 0
symuid/library/__init__.py


+ 2 - 2
symuid/library/cmus.py

@@ -1,5 +1,3 @@
-# -*- coding: utf-8 -*-
-
 import re
 import sys
 
@@ -49,6 +47,8 @@ class Track:
 
 class Cache:
 
+    # pylint: disable=too-few-public-methods
+
     FILE_PREFIX = b'CTC'
     VERSION_LENGTH = 1
     SUPPORTED_VERSIONS = [b'\x0c', b'\x0d']

+ 10 - 13
symuid/library/itunes.py

@@ -1,10 +1,9 @@
-# -*- coding: utf-8 -*-
-
-import dateutil.parser
 import os
 import urllib.parse
 import xml.etree.ElementTree
 
+import dateutil.parser
+
 
 class XmlDict:
 
@@ -24,14 +23,13 @@ class XmlDict:
     def _parse_value_node(value_node):
         if value_node.tag == 'string':
             return value_node.text
-        elif value_node.tag == 'integer':
+        if value_node.tag == 'integer':
             return int(value_node.text)
-        elif value_node.tag == 'date':
+        if value_node.tag == 'date':
             return dateutil.parser.parse(value_node.text)
-        elif value_node.tag == 'dict':
+        if value_node.tag == 'dict':
             return XmlDict(value_node)
-        else:
-            raise ValueError(value_node.tag)
+        raise ValueError(value_node.tag)
 
     def __getitem__(self, key):
         value_node = self._get_value_node(key)
@@ -51,7 +49,7 @@ class XmlDict:
             yield (key, value)
 
     def values(self):
-        for key, value in self.items():
+        for _, value in self.items():
             yield value
 
 
@@ -70,7 +68,7 @@ class Track:
         self._last_play_dt = self._dict.get('Play Date UTC', None)
 
     @property
-    def id(self):
+    def track_id(self):
         return self._id
 
     @property
@@ -88,8 +86,7 @@ class Track:
             return os.path.sep + urllib.parse.unquote(
                 self.location_url[len(self.LOCAL_LOCATION_URL_PREFIX):],
             )
-        else:
-            raise ValueError(self.location_url)
+        raise ValueError(self.location_url)
 
     @property
     def play_count(self):
@@ -110,7 +107,7 @@ class XmlLibrary:
         assert len(self._id) > 4
 
     @property
-    def id(self):
+    def library_id(self):
         return self._id
 
     @property