Ver código fonte

add select filters

Tobias Simetsreiter 2 anos atrás
pai
commit
a225c7a5ad
1 arquivos alterados com 23 adições e 3 exclusões
  1. 23 3
      multigource.py

+ 23 - 3
multigource.py

@@ -2,7 +2,10 @@
 
 from argparse import ArgumentParser,Namespace
 
-GIT_CMD = ["git", "log", "--all", '--pretty=format:user:%aN%n%ct', "--reverse", "--raw", "--encoding=UTF-8", "--no-renames"]
+GIT_CMD = ["git", "log",
+           "--all", '--pretty=format:user:%aN%n%ct',
+           "--reverse", "--raw", "--encoding=UTF-8",
+           "--no-renames", "--no-show-signature"]
 SCHEMA=[
 '''
 CREATE TABLE IF NOT EXISTS user (
@@ -51,7 +54,6 @@ SELECT time,user.name as user,action,repo.path as repo, file.path as file FROM c
 LEFT JOIN user ON user.id = change.user_id
 LEFT JOIN repo ON repo.id = change.repo_id
 LEFT JOIN file ON file.id = change.file_id
-ORDER BY time ASC
 '''
 
 def main():
@@ -75,6 +77,9 @@ def parser():
     p_join.add_argument('-p','--prefix')
     p_select = sub.add_parser('select')
     p_select.add_argument('output')
+    p_select.add_argument('--repo-like', default=None, type=str)
+    p_select.add_argument('--file-like', default=None, type=str)
+    p_select.add_argument('--user-like', default=None, type=str)
     p_select.set_defaults(func=select)
     return p
 
@@ -183,7 +188,22 @@ def select(args: Namespace):
     import sqlite3
     import os
     with sqlite3.connect(args.output) as db:
-        for i in db.execute(STMT_SELECT):
+        STMT = STMT_SELECT
+        ARGS = []
+        WHERE_VERB = "WHERE"
+        if args.user_like:
+            STMT += " "+WHERE_VERB+" user.name LIKE ? "
+            ARGS.append(args.user_like)
+            WHERE_VERB = "AND"
+        if args.repo_like:
+            STMT += " "+WHERE_VERB+" repo.path LIKE ? "
+            ARGS.append(args.repo_like)
+            WHERE_VERB = "AND"
+        if args.file_like:
+            STMT += " "+WHERE_VERB+" file.path LIKE ? "
+            ARGS.append(args.file_like)
+            WHERE_VERB = "AND"
+        for i in db.execute(STMT + " ORDER BY time ASC", ARGS):
             # print(i)
             path = os.path.join(i[3],i[4])
             print('|'.join((str(i[0]),i[1],i[2],path)))