Browse Source

symuid-list: added --limit param

Fabian Peter Hammerle 6 years ago
parent
commit
5d0b7c8873
1 changed files with 9 additions and 2 deletions
  1. 9 2
      symuid-list

+ 9 - 2
symuid-list

@@ -4,7 +4,7 @@
 import symuid
 
 
-def symuid_list(path, path_ignore_regex, filter_expression, sort_expression):
+def symuid_list(path, path_ignore_regex, filter_expression, sort_expression, limit):
     # use generators until sort is required
     attr_it = ({'path': track.path, 'play_count': track.get_play_count_sum()}
                for track in symuid.Track.walk(path, path_ignore_regex))
@@ -13,7 +13,9 @@ def symuid_list(path, path_ignore_regex, filter_expression, sort_expression):
     if sort_expression:
         attr_it = list(attr_it)
         attr_it.sort(key=lambda a: eval(sort_expression, a))
-    for attr in attr_it:
+    for i, attr in enumerate(attr_it):
+        if limit and i == limit:
+            break
         print(attr['path'])
 
 
@@ -48,6 +50,11 @@ def _init_argparser():
             "(play_count, len(path))",
         ),
     )
+    argparser.add_argument(
+        '--limit',
+        type=int,
+        help='(default: none)',
+    )
     return argparser