used black to reformat python scripts

This commit is contained in:
Tobias Manske 2018-06-10 21:59:13 +02:00
parent 2738f6cc94
commit ea533a48ab
No known key found for this signature in database
GPG Key ID: 978D99F12D4E041F
2 changed files with 48 additions and 18 deletions

View File

@ -15,5 +15,10 @@ class Dmenu(object):
def run(self):
"""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)

View File

@ -20,18 +20,40 @@ con = sqlite3.connect(os.path.dirname(sys.argv[0]) + "/database.sqlite")
# ARGUMENTS PARSER
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 \
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')
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 \
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()
# Helper functions
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);"
with con:
@ -49,7 +71,7 @@ def retrieve_db():
ro = cur.fetchall()
for r in ro:
r = dict(r)
r['json'] = json.loads(r['json'])
r["json"] = json.loads(r["json"])
rows.append(r)
return rows
@ -59,16 +81,19 @@ def build_db():
for mod in loadModules:
entries.update(mod.build_db())
for k, v in entries.items():
with con:
con.cursor().execute("INSERT INTO entries(Name, json, file, type, disabled) VALUES(?, ?, ?, ?, ?)",
(k, json.dumps(v['json']), v['file'], v['type'], v['disabled']))
if "Exec" in v["json"]:
with con:
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():
entries = []
db = retrieve_db()
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
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("SELECT type FROM entries WHERE ID=?", (data[0],))
con.commit()
typ = dict(cur.fetchone())['type']
typ = dict(cur.fetchone())["type"]
for mod in loadModules:
if mod.db_type == typ:
mod.call(data[1])
if (args.FLAG_CREATE):
if args.FLAG_CREATE:
with con:
con.cursor().execute("DROP TABLE IF EXISTS entries;")
create_db()
# set BUILD flag so the database gets rebuilt too
args.FLAG_BUILD = True
if (args.FLAG_BUILD):
if(args.FLAG_TRUNCATE):
if args.FLAG_BUILD:
if args.FLAG_TRUNCATE:
with con:
con.cursor().execute("DELETE FROM entries")
con.cursor().execute("DELETE FROM sqlite_sequence WHERE name='entries'")
@ -104,7 +129,7 @@ if (args.FLAG_BUILD):
entries = build_menu()
p1 = Dmenu([x[1] for x in entries]).run()
if (p1[0] != 0):
if p1[0] != 0:
# error on escape
exit(1)