aboutsummaryrefslogtreecommitdiff
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
--status
-rw-r--r--LICENSE9
-rw-r--r--etc/config3
-rw-r--r--setup.py22
-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
12 files changed, 206 insertions, 0 deletions
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..91d7289
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,9 @@
+Copyright (c) 2013, Yuriy Netesov
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
diff --git a/etc/config b/etc/config
new file mode 100644
index 0000000..15eb62e
--- /dev/null
+++ b/etc/config
@@ -0,0 +1,3 @@
+{
+ "dmenu_params": "-i -nb black -nf orange -sb black -p \"#\""
+} \ No newline at end of file
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..fe1a6c3
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,22 @@
+from setuptools import setup
+
+
+setup(
+ name='xboomx',
+ version='0.50',
+ packages=['xboomx'],
+ scripts=['xboomx/bin/xboomx_path.py',
+ 'xboomx/bin/xboomx_sort.py',
+ 'xboomx/bin/xboomx_update.py',
+ 'xboomx/bin/xboomx_urls.py',
+ 'xboomx/bin/web_xboomx',
+ 'xboomx/bin/xboomx'],
+ license='BSD',
+ long_description='wrapper for most common occurences in dmenu',
+ install_requires=[],
+ include_package_data=True,
+ package_data={'shared': ["etc/config"]},
+ author="Yuriy Netesov",
+ author_email="[email protected]",
+ url="https://bitbucket.org/dehun/xboomx/",
+)
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)