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,
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...')