aboutsummaryrefslogtreecommitdiff
path: root/xboomx
diff options
context:
space:
mode:
authorVictor Häggqvist <[email protected]>2014-09-02 11:27:50 +0200
committerVictor Häggqvist <[email protected]>2014-09-02 11:27:50 +0200
commitbcbd5bb12b3a1f89948d21a7a9bc0f056db73f38 (patch)
treef95b967cd8dec52fadba96c85cf03a635bb272f3 /xboomx
--status
Diffstat (limited to 'xboomx')
-rw-r--r--xboomx/__init__.py1
-rw-r--r--xboomx/bin/web_xboomx13
-rwxr-xr-xxboomx/bin/xboomx37
-rwxr-xr-xxboomx/bin/xboomx_path.py11
-rw-r--r--xboomx/bin/xboomx_sort.py36
-rw-r--r--xboomx/bin/xboomx_update.py31
-rw-r--r--xboomx/bin/xboomx_urls.py15
-rw-r--r--xboomx/config.py15
-rw-r--r--xboomx/db.py13
9 files changed, 172 insertions, 0 deletions
diff --git a/xboomx/__init__.py b/xboomx/__init__.py
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/xboomx/__init__.py
@@ -0,0 +1 @@
+
diff --git a/xboomx/bin/web_xboomx b/xboomx/bin/web_xboomx
new file mode 100644
index 0000000..67baba3
--- /dev/null
+++ b/xboomx/bin/web_xboomx
@@ -0,0 +1,13 @@
+#!/usr/bin/python
+
+import subprocess
+from xboomx.config import config
+
+
+DMENU_LAUNCHER = 'dmenu ' + config.get("dmenu_params", "")
+
+subprocess.call("""xboomx_urls.py | xboomx_sort.py urls | \
+ """ + DMENU_LAUNCHER + """| \
+ xboomx_update.py urls | \
+ xargs -I {} sh -c \'exec firefox {} &\'""",
+ shell=True)
diff --git a/xboomx/bin/xboomx b/xboomx/bin/xboomx
new file mode 100755
index 0000000..2b4d266
--- /dev/null
+++ b/xboomx/bin/xboomx
@@ -0,0 +1,37 @@
+#!/usr/bin/python
+import fileinput
+
+import subprocess
+from xboomx.config import config
+import xboomx.db
+import sys
+
+
+if len(sys.argv) > 1 and sys.argv[1] == "--stats":
+ db = xboomx.db.open_shelve('')
+
+ items = []
+
+ keys = db.keys()
+
+ for x in keys:
+ items.append([x, db.get(x, "")])
+
+ db.close()
+
+ # sort items
+ items.sort(key=lambda x: x[1], reverse=True)
+
+ # print items
+ print "Application\tLaunches"
+ for item in items:
+ if len(item[0]) < 8:
+ print item[0]+"\t\t"+str(item[1])
+ else:
+ print item[0]+"\t"+str(item[1])
+
+ exit(0)
+
+DMENU_LAUNCHER = 'dmenu ' + config.get("dmenu_params", "")
+
+subprocess.call("xboomx_path.py | xboomx_sort.py | " + DMENU_LAUNCHER + "| xboomx_update.py | xargs -I {} sh -c \'exec {} &\'", shell=True)
diff --git a/xboomx/bin/xboomx_path.py b/xboomx/bin/xboomx_path.py
new file mode 100755
index 0000000..67a1cb1
--- /dev/null
+++ b/xboomx/bin/xboomx_path.py
@@ -0,0 +1,11 @@
+#!/usr/bin/python
+
+import os
+
+pathes = os.environ['PATH'].split(':')
+
+
+for path in pathes:
+ if os.path.isdir(path):
+ for f in os.listdir(path):
+ print f
diff --git a/xboomx/bin/xboomx_sort.py b/xboomx/bin/xboomx_sort.py
new file mode 100644
index 0000000..a30c362
--- /dev/null
+++ b/xboomx/bin/xboomx_sort.py
@@ -0,0 +1,36 @@
+#!/usr/bin/python
+import fileinput
+import sys
+
+import xboomx.db
+
+
+def main():
+
+ # get db type
+ db_type = ''
+ if len(sys.argv) > 1:
+ db_type = sys.argv[1]
+
+ # open shelve
+ db = xboomx.db.open_shelve(db_type)
+
+ # read lines and set weight according to db
+ items = []
+
+ for input_item in fileinput.input([]):
+ input_item = input_item.strip('\n')
+ items.append((db.get(input_item, 0), input_item))
+
+ # sort items
+ items.sort(key=lambda x: x[0], reverse=True)
+
+ # print items
+ for item in items:
+ print item[1]
+
+ # clean up
+ db.close()
+
+
+main()
diff --git a/xboomx/bin/xboomx_update.py b/xboomx/bin/xboomx_update.py
new file mode 100644
index 0000000..892bc4c
--- /dev/null
+++ b/xboomx/bin/xboomx_update.py
@@ -0,0 +1,31 @@
+#!/usr/bin/python
+import sys
+import fileinput
+
+import xboomx.db
+
+
+def main():
+ # get db type
+ db_type = ''
+ if len(sys.argv) > 1:
+ db_type = sys.argv[1]
+ # open db
+ db = xboomx.db.open_shelve(db_type)
+
+ # get item to update
+ item = fileinput.input([]).next()
+ item = item.strip('\n')
+
+ # update item
+ db[item] = db.get(item, 0) + 1
+
+ # print it
+ print item
+
+ # clean up
+ db.sync()
+ db.close()
+
+
+main()
diff --git a/xboomx/bin/xboomx_urls.py b/xboomx/bin/xboomx_urls.py
new file mode 100644
index 0000000..211c98c
--- /dev/null
+++ b/xboomx/bin/xboomx_urls.py
@@ -0,0 +1,15 @@
+#!/usr/bin/python
+
+import xboomx.db
+DB_TYPE = 'urls'
+
+
+def main():
+ db = xboomx.db.open_shelve(DB_TYPE)
+ for url in db.keys():
+ print url
+
+ db.close()
+
+
+main()
diff --git a/xboomx/config.py b/xboomx/config.py
new file mode 100644
index 0000000..a98ef03
--- /dev/null
+++ b/xboomx/config.py
@@ -0,0 +1,15 @@
+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()
diff --git a/xboomx/db.py b/xboomx/db.py
new file mode 100644
index 0000000..fd099e3
--- /dev/null
+++ b/xboomx/db.py
@@ -0,0 +1,13 @@
+import shelve
+import os
+
+
+def open_shelve(db_type=''):
+ # create dir if not exists
+ try:
+ os.makedirs(os.getenv("HOME") + '/.xboomx')
+ except:
+ pass
+
+ # open shelve
+ return shelve.open(os.getenv("HOME") + '/.xboomx/xboomx%s.db' % db_type)