This commit is contained in:
13
file_list.py
13
file_list.py
@@ -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,12 +177,15 @@ 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()
|
||||||
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
|
ratio=0
|
||||||
best_match=""
|
best_match=""
|
||||||
for row in db:
|
for row in db:
|
||||||
@@ -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...')
|
||||||
|
|||||||
Reference in New Issue
Block a user