Commits

Anonymous committed 07522f9

added config

  • Participants
  • Parent commits e7b4876

Comments (0)

Files changed (6)

+{
+        "dmenu_params": "-i -nb black -nf orange -sb black -p \"#\""
+}

xboomx/bin/xboomx

 #!/usr/bin/python
 
 import os
+from xboomx.config import config
 
-DMENU_LAUNCHER = 'dmenu'
 
-os.system("bash -c 'dmenu_path | xboomx_sort.py | " + DMENU_LAUNCHER +  "| xboomx_update.py'")
+DMENU_LAUNCHER = 'dmenu ' + config.get("dmenu_params")
+
+os.system("bash -c 'dmenu_path | xboomx_sort.py | " + DMENU_LAUNCHER +  "| xboomx_update.py | xargs -I {} bash -c \'{}\''")

xboomx/bin/xboomx_sort.py

-import shelve
 import fileinput
-import os
+import xboomx.db
 
 
 def main():
-    # open db
-    db = shelve.open(os.getenv("HOME") + '/.xboomx/xboomx.db')
+    # open shelve
+    db = xboomx.db.open_shelve()
 
     # read lines and set weight according to db
     items = []

xboomx/bin/xboomx_update.py

-import shelve
 import fileinput
-import os
+import xboomx.db
 
 
 def main():
     # open db
-    db = shelve.open(os.getenv("HOME") + '/.xboomx/xboomx.db')
+    db = xboomx.db.open_shelve()
 
     # get item to update
     item = fileinput.input().next()
     # update item
     db[item] = db.get(item, 0) + 1
 
+    # print it
+    print item
+
     # clean up
     db.sync()
     db.close()
+import os
+import json
+import logging
+
+
+def load_config():
+    try:
+        with open(os.getenv("HOME") + "/.xboomx/config") as config_file:
+            return json.loads('\n'.join(config_file.readlines()))
+    except:
+        logging.error("Failed to load config file")
+        return {}
+
+
+config = load_config()
+import shelve
+import os
+
+
+def open_shelve():
+    # create dir if not exists
+    try:
+        os.makedirs(os.getenv("HOME") + '/.xboomx')
+    except:
+        pass
+
+    # open shelve
+    return shelve.open(os.getenv("HOME") + '/.xboomx/xboomx.db')