From 79a5fb29e56aa53f6e7daad8eb28f5db137638a8 Mon Sep 17 00:00:00 2001 From: q Date: Fri, 8 Feb 2013 20:43:38 +0200 Subject: [PATCH] --- file_list.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/file_list.py b/file_list.py index 5d47f08..4a9d77f 100755 --- a/file_list.py +++ b/file_list.py @@ -35,7 +35,7 @@ def setup_options(): parser.add_argument("-s",type=str,dest="search",default=False, help="Search list based on path pattern") parser.add_argument("--match",type=str,dest="match",default=False, - help="Search for closest match from basenames") + help="Search for closest match from basenames, can be helped with adding -s") parser.add_argument('startpath', action="store",default='.', nargs='?') options=parser.parse_args() @@ -177,12 +177,15 @@ def searchdb(sqlfile,needle): for row in db: print(row[0]) -def matchdb(sqlfile,needle): +def matchdb(sqlfile,needle,helper): import difflib as dl conn=sqlite3.connect(sqlfile) conn.text_factory=str db=conn.cursor() - db.execute("SELECT file FROM list") + if helper: + db.execute("SELECT file FROM list WHERE file LIKE ?",('%'+needle+'%',)) + else: + db.execute("SELECT file FROM list") ratio=0 best_match="" for row in db: @@ -207,11 +210,11 @@ def main(): if not os.path.exists(options.sqlfile): createdb(options.sqlfile); - if options.search: + if options.search and not options.match: searchdb(options.sqlfile,options.search) sys.exit(0) if options.match: - matchdb(options.sqlfile,options.match) + matchdb(options.sqlfile,options.match,options.search) sys.exit(0) if options.delete: print('Deleting entries...')