used black to reformat python scripts
This commit is contained in:
parent
2738f6cc94
commit
ea533a48ab
@ -15,5 +15,10 @@ class Dmenu(object):
|
|||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
"""Returns (exitCode, stdout)"""
|
"""Returns (exitCode, stdout)"""
|
||||||
p1 = subprocess.run(self._dmenu, input="\n".join(self._items), encoding="utf-8", stdout=subprocess.PIPE)
|
p1 = subprocess.run(
|
||||||
|
self._dmenu,
|
||||||
|
input="\n".join(self._items),
|
||||||
|
encoding="utf-8",
|
||||||
|
stdout=subprocess.PIPE,
|
||||||
|
)
|
||||||
return (p1.returncode, p1.stdout)
|
return (p1.returncode, p1.stdout)
|
||||||
|
@ -20,18 +20,40 @@ con = sqlite3.connect(os.path.dirname(sys.argv[0]) + "/database.sqlite")
|
|||||||
|
|
||||||
# ARGUMENTS PARSER
|
# ARGUMENTS PARSER
|
||||||
|
|
||||||
parser = argparse.ArgumentParser(description='Smart Dropdown Launcher for AwesomeWM')
|
parser = argparse.ArgumentParser(description="Smart Dropdown Launcher for AwesomeWM")
|
||||||
parser.add_argument('--create', dest='FLAG_CREATE', action='store_const', const=True, default=False, help='Force TABLE \
|
parser.add_argument(
|
||||||
CREATION')
|
"--create",
|
||||||
parser.add_argument('--build', dest='FLAG_BUILD', action='store_const', const=True, default=False, help='Force Build \
|
dest="FLAG_CREATE",
|
||||||
the Database')
|
action="store_const",
|
||||||
parser.add_argument('--truncate', dest='FLAG_TRUNCATE', action='store_const', const=True, default=False, help='Truncate\
|
const=True,
|
||||||
Database during build')
|
default=False,
|
||||||
|
help="Force TABLE \
|
||||||
|
CREATION",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--build",
|
||||||
|
dest="FLAG_BUILD",
|
||||||
|
action="store_const",
|
||||||
|
const=True,
|
||||||
|
default=False,
|
||||||
|
help="Force Build \
|
||||||
|
the Database",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--truncate",
|
||||||
|
dest="FLAG_TRUNCATE",
|
||||||
|
action="store_const",
|
||||||
|
const=True,
|
||||||
|
default=False,
|
||||||
|
help="Truncate\
|
||||||
|
Database during build",
|
||||||
|
)
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
# Helper functions
|
# Helper functions
|
||||||
|
|
||||||
|
|
||||||
def create_db():
|
def create_db():
|
||||||
command = "CREATE TABLE entries(`ID` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, `Name` TEXT, `json` TEXT, `hits` INTEGER NOT NULL DEFAULT 0, `disabled` INTEGER NOT NULL DEFAULT 0, `type` TEXT NOT NULL DEFAULT 'file', `file` TEXT);"
|
command = "CREATE TABLE entries(`ID` INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, `Name` TEXT, `json` TEXT, `hits` INTEGER NOT NULL DEFAULT 0, `disabled` INTEGER NOT NULL DEFAULT 0, `type` TEXT NOT NULL DEFAULT 'file', `file` TEXT);"
|
||||||
with con:
|
with con:
|
||||||
@ -49,7 +71,7 @@ def retrieve_db():
|
|||||||
ro = cur.fetchall()
|
ro = cur.fetchall()
|
||||||
for r in ro:
|
for r in ro:
|
||||||
r = dict(r)
|
r = dict(r)
|
||||||
r['json'] = json.loads(r['json'])
|
r["json"] = json.loads(r["json"])
|
||||||
rows.append(r)
|
rows.append(r)
|
||||||
return rows
|
return rows
|
||||||
|
|
||||||
@ -59,16 +81,19 @@ def build_db():
|
|||||||
for mod in loadModules:
|
for mod in loadModules:
|
||||||
entries.update(mod.build_db())
|
entries.update(mod.build_db())
|
||||||
for k, v in entries.items():
|
for k, v in entries.items():
|
||||||
with con:
|
if "Exec" in v["json"]:
|
||||||
con.cursor().execute("INSERT INTO entries(Name, json, file, type, disabled) VALUES(?, ?, ?, ?, ?)",
|
with con:
|
||||||
(k, json.dumps(v['json']), v['file'], v['type'], v['disabled']))
|
con.cursor().execute(
|
||||||
|
"INSERT INTO entries(Name, json, file, type, disabled) VALUES(?, ?, ?, ?, ?)",
|
||||||
|
(k, json.dumps(v["json"]), v["file"], v["type"], v["disabled"]),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def build_menu():
|
def build_menu():
|
||||||
entries = []
|
entries = []
|
||||||
db = retrieve_db()
|
db = retrieve_db()
|
||||||
for mod in loadModules:
|
for mod in loadModules:
|
||||||
entries += mod.build_menu([x for x in db if x['type'] == mod.db_type])
|
entries += mod.build_menu([x for x in db if x["type"] == mod.db_type])
|
||||||
|
|
||||||
# sort by hits
|
# sort by hits
|
||||||
return sorted(entries, key=lambda i: i[2], reverse=True)
|
return sorted(entries, key=lambda i: i[2], reverse=True)
|
||||||
@ -80,21 +105,21 @@ def run_program(data):
|
|||||||
cur.execute("UPDATE entries SET hits=? WHERE ID=?", (data[2] + 1, data[0]))
|
cur.execute("UPDATE entries SET hits=? WHERE ID=?", (data[2] + 1, data[0]))
|
||||||
cur.execute("SELECT type FROM entries WHERE ID=?", (data[0],))
|
cur.execute("SELECT type FROM entries WHERE ID=?", (data[0],))
|
||||||
con.commit()
|
con.commit()
|
||||||
typ = dict(cur.fetchone())['type']
|
typ = dict(cur.fetchone())["type"]
|
||||||
for mod in loadModules:
|
for mod in loadModules:
|
||||||
if mod.db_type == typ:
|
if mod.db_type == typ:
|
||||||
mod.call(data[1])
|
mod.call(data[1])
|
||||||
|
|
||||||
|
|
||||||
if (args.FLAG_CREATE):
|
if args.FLAG_CREATE:
|
||||||
with con:
|
with con:
|
||||||
con.cursor().execute("DROP TABLE IF EXISTS entries;")
|
con.cursor().execute("DROP TABLE IF EXISTS entries;")
|
||||||
create_db()
|
create_db()
|
||||||
# set BUILD flag so the database gets rebuilt too
|
# set BUILD flag so the database gets rebuilt too
|
||||||
args.FLAG_BUILD = True
|
args.FLAG_BUILD = True
|
||||||
|
|
||||||
if (args.FLAG_BUILD):
|
if args.FLAG_BUILD:
|
||||||
if(args.FLAG_TRUNCATE):
|
if args.FLAG_TRUNCATE:
|
||||||
with con:
|
with con:
|
||||||
con.cursor().execute("DELETE FROM entries")
|
con.cursor().execute("DELETE FROM entries")
|
||||||
con.cursor().execute("DELETE FROM sqlite_sequence WHERE name='entries'")
|
con.cursor().execute("DELETE FROM sqlite_sequence WHERE name='entries'")
|
||||||
@ -104,7 +129,7 @@ if (args.FLAG_BUILD):
|
|||||||
entries = build_menu()
|
entries = build_menu()
|
||||||
p1 = Dmenu([x[1] for x in entries]).run()
|
p1 = Dmenu([x[1] for x in entries]).run()
|
||||||
|
|
||||||
if (p1[0] != 0):
|
if p1[0] != 0:
|
||||||
# error on escape
|
# error on escape
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user