This commit is contained in:
q
2013-02-08 20:43:38 +02:00
parent cc59b4266e
commit 79a5fb29e5

View File

@@ -35,7 +35,7 @@ def setup_options():
parser.add_argument("-s",type=str,dest="search",default=False, parser.add_argument("-s",type=str,dest="search",default=False,
help="Search list based on path pattern") help="Search list based on path pattern")
parser.add_argument("--match",type=str,dest="match",default=False, 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='?') parser.add_argument('startpath', action="store",default='.', nargs='?')
options=parser.parse_args() options=parser.parse_args()
@@ -177,11 +177,14 @@ def searchdb(sqlfile,needle):
for row in db: for row in db:
print(row[0]) print(row[0])
def matchdb(sqlfile,needle): def matchdb(sqlfile,needle,helper):
import difflib as dl import difflib as dl
conn=sqlite3.connect(sqlfile) conn=sqlite3.connect(sqlfile)
conn.text_factory=str conn.text_factory=str
db=conn.cursor() db=conn.cursor()
if helper:
db.execute("SELECT file FROM list WHERE file LIKE ?",('%'+needle+'%',))
else:
db.execute("SELECT file FROM list") db.execute("SELECT file FROM list")
ratio=0 ratio=0
best_match="" best_match=""
@@ -207,11 +210,11 @@ def main():
if not os.path.exists(options.sqlfile): if not os.path.exists(options.sqlfile):
createdb(options.sqlfile); createdb(options.sqlfile);
if options.search: if options.search and not options.match:
searchdb(options.sqlfile,options.search) searchdb(options.sqlfile,options.search)
sys.exit(0) sys.exit(0)
if options.match: if options.match:
matchdb(options.sqlfile,options.match) matchdb(options.sqlfile,options.match,options.search)
sys.exit(0) sys.exit(0)
if options.delete: if options.delete:
print('Deleting entries...') print('Deleting entries...')