multiple strings in search
This commit is contained in:
14
file_list.py
14
file_list.py
@@ -32,7 +32,7 @@ def setup_options():
|
||||
help="Exclude folder name from the lists. This option may be issued several times")
|
||||
parser.add_argument("-f",action="store",dest="sqlfile",default=SQLFILE,
|
||||
help="SQL file name to use [%(default)s]")
|
||||
parser.add_argument("-s",type=str,dest="search",default=False,
|
||||
parser.add_argument("-s",type=str,action='append',dest="search",default=[],
|
||||
help="Search list based on path pattern")
|
||||
parser.add_argument("--match",type=str,dest="match",default=False,
|
||||
help="Search for closest match from basenames, can be helped with adding -s")
|
||||
@@ -170,10 +170,12 @@ def find_duplicates(sqlfile):
|
||||
return duphash
|
||||
|
||||
def searchdb(sqlfile,needle):
|
||||
needle=['%'+i+'%' for i in needle]
|
||||
like_query=' OR '.join(['file LIKE ?' for i in needle])
|
||||
conn=sqlite3.connect(sqlfile)
|
||||
conn.text_factory=str
|
||||
db=conn.cursor()
|
||||
db.execute("SELECT file FROM list WHERE file LIKE ? ORDER BY file",('%'+needle+'%',))
|
||||
db.execute("SELECT file FROM list WHERE "+like_query+" ORDER BY file",needle)
|
||||
for row in db:
|
||||
print(row[0])
|
||||
|
||||
@@ -182,8 +184,10 @@ def matchdb(sqlfile,needle,helper):
|
||||
conn=sqlite3.connect(sqlfile)
|
||||
conn.text_factory=str
|
||||
db=conn.cursor()
|
||||
if helper:
|
||||
db.execute("SELECT file FROM list WHERE file LIKE ?",('%'+needle+'%',))
|
||||
if len(helper)>0:
|
||||
helper=['%'+i+'%' for i in helper]
|
||||
like_query=' OR '.join(['file LIKE ?' for i in helper])
|
||||
db.execute("SELECT file FROM list WHERE "+like_query,helper)
|
||||
else:
|
||||
db.execute("SELECT file FROM list")
|
||||
ratio=0
|
||||
@@ -210,7 +214,7 @@ def main():
|
||||
|
||||
if not os.path.exists(options.sqlfile):
|
||||
createdb(options.sqlfile);
|
||||
if options.search and not options.match:
|
||||
if len(options.search)>0 and not options.match:
|
||||
searchdb(options.sqlfile,options.search)
|
||||
sys.exit(0)
|
||||
if options.match:
|
||||
|
||||
Reference in New Issue
Block a user